Start a service manager process automatically on startup

Hello,

I am in the process of learning Linux OS.

How do I run the below lines of code automatically as root on server startup.

cd /opt/program_folder/ServiceManager/bin
nohup ./servce_manager DEV &

Currently, as soon as the server is up and running I log in as root (as this program needs to be run as root) and run the above lines of code.

How do I set up this code in rc.d to run automatically?
When the server goes down I do not worry as it does not need to be shutdown gracefully. The only way right now is to kill the process, if there is a need to shutdown the service_manager.

Please help me out.

Thanks,
Ram.

There are lots of ways to do it.

One option might be to put a line in root's crontab, which you edit via crontab -e :

@reboot cd /opt/program_folder/ServiceManager/bin ; nohup ./servce_manager DEV &
1 Like

Tested the entry in crontab and worked like a charm. Thank You very much.

I have another question. I have a script (ksh script) that starts an application listener.
It is owned by a user scott (command for example: start_listener.ksh -a start ).
This also needs to start at the server start up as scott.

Could you kindly guide me?

Thanks,
Ram.

Login to scott and add it to his crontab. You may need to add him to the cron group like usermod -a -G cron scott before crontab -e will work.

You may want to nohup command & that one as well.

1 Like

I finally figured the answer to my question. Used the same technique of crontab suggested by you. I did as below:

su - scott -c 'start_listener.ksh -a start'

I put the above code in a strt_lsnr.sh
executed the script using your technique using an entry in crontab.

Thanks You very much for guiding me.

Thanks,
Ram.

Hi Corona wont just running the below command as root add the cron job to that user specified ?

crontab -u scot -e

Why need to log into the user ? Just curious because it worked for me many times before.

Thanks,

You don't need root access, just scot access, to set up scot's crontab by logging in as scot.

It also makes it harder to mess up anything else by accident, since you'll have access to only scot's crontab etc.