I recently had the need to run some code with each server restart. update-rc.d provides a great and easy way execute your own code on server startup (in my case, Ubuntu 12.04).
As root, create your script:
Make the script executable:
Add your script to
update-rc.d on the new script:
So, what is the
If defaults is used then update-rc.d will make links to start the service in runlevels 2345 and to stop the service in runlevels 016.
Here’s a great article describing runlevels in exhausting detail:
And what is a runlevel? You might assume that this refers to different levels that the system goes through during a boot up. Instead, think of the runlevel as the point at which the system is entered. Runlevel 1 is the most basic configuration (simple single user access using an text interface), while runlevel 5 is the most advanced (multi-user, networking, and a GUI front end). Runlevels 0 and 6 are used for halting and rebooting the system.