Showing posts with label Service. Show all posts
Showing posts with label Service. Show all posts

Thursday, April 30, 2026

How to run a command on boot or startup in Ubuntu.


https://linuxvox.com/blog/automatically-run-a-program-on-startup-under-linux-ubuntu/

We start by creating a .sh file in /usr/bin/mycommand.sh
 
Enter the following text in it.

#!/bin/sh
sudo ip  route add 10.30.24.0/24 via  192.168.0.1 dev eth0 onlink

Creating a new service:
sudo nano /etc/systemd/system/mycommand.service # create new service file

Enter the following text in it.

[Unit]
Description=Add route command
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/bash /usr/bin/mycommand.sh
User=root #running as root user
Restart=never # do not restart the service if it fails

[Install]
WantedBy=multi-user.target

Starting the service:
sudo systemctl daemon-reload # reload the system daemon
sudo systemctl start mycommand.service # to start without rebooting for testing
sudo systemctl status mycommand.service # to verify status of service.
sudo systemctl enable mycommand.service # enable the service to run at startup


Removing a systemdservice
Sudo systemctl stop mycommand.service # stop the service
Sudo systemctl disable mycommand.service # disable the service
Sudo rm /ect/systemd/system/mycommand.service

 

 

Tuesday, June 15, 2021

Adding recovery task in SCOM for service start

 This is for the SQL management pack. But can be applied to any management pack which discovers the service name and monitors it.

Open the settings of the monitor and click add command recovery for your health state.

Full Path to file:

%windir%\system32\net.exe

Parameters:

start $Target/Property[Type="MicrosoftSQLServer2016Discovery7040!Microsoft.SQLServer.2016.Agent"]/ServiceName$

Working Directory:

%windir%\system32