Ubuntu: How to make a script in init.d run later


A package installed /etc/init.d/ccpd which is a script run at start up. I would like this script to be run as very last of all my start up scripts, how can I achieve this?


When your computer starts up, it doesn't run the init.d scripts directly. Instead, depending on what's called the "runlevel", it runs the scripts in /etc/rcN.d (where N is the runlevel). You can determine the current runlevel with the runlevel command; mine returns 2 in normal operation. That means that when the computer started up, it ran the scripts in /etc/rc2.d. The contents of rc2.d are just symlinks to scripts in /etc/init.d, named according to whether they should be started or stopped, and the order they should be run.

Use the runlevel command to find out what runlevel your computer is at (probably 2), then look in /etc/rc2.d for a link named SNNccpd, which will be a symlink to /etc/init.d/ccpd, and rename it to S99zzzccpd - or whatever it takes to get it to sort after the other entries - that will cause it to run last.

There's more information about init.d scripts and runlevels at https://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts


Rather than putting it as a service which always keeps running, what you can do remove it as a service from /etc/init.d

and make a script and put it in /root/bin or /usr/local/bin

Inside that script,

#!/bin/bash sleep 300  #call your service and run it in background  /usr/bin/ccpd &  

the startup will continue and your stuff will run after 5 minutes

Now the last step is to make your script run on startup, either add your script to /etc/fstab or to profile

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »