Start a process on linux startup
I need to start a process when our linux/unix boxes (These boxes are used as build agents) are starting (ie: after a reboot). We use the following distros:
- debian 6
- ubuntu 12.something
- CentOS 6
- Suse 12.something 🙂
Can you please let me know what should I make in order for this to happen?
The easiest way would be to put your command in /etc/rc.d/rc.local. The rc.local script is run after all the other System V init script are done.
In general the same process should work for all those distro’s but you might have to tweak them to suit their specific implementation.
Have a look at “run levels”, determine at which level you want to start your scripts (usually 3 for a server and 3 & 5 for a graphical client) and then follow this:
In a nutshell, you create your startup script (best copy and modify an existing one – for the sake of example call it “myScript”) and place it in /etc/init.d. Then in /etc/init.d/rcX.d (where X is your run level) place links to the script you put in /etc/init.d. The links should be named SxxmyScript and KxxmyScript. The “S” links get followed on startup – i.e. when the system enters that runlevel, and the “K” links get executed when the system exits that runlevel.
More recent distributions use services which are a more elegant twist on the above, but the above should work.
Also, for completeness look at /etc/inittab. This isnt available on all distributions (i.e. ubuntu) but should be present on SuSE. This is a proper old throwback but is still very much used these days in older environments.