init.d script not running on startup

Just having the script present in /etc/init.d is not sufficient to have it run at startup.

To add it to your startup, you have to tell Ubuntu about it:

sudo update-rc.d css-servers defaults

It should then start on next boot, if the script is properly formatted, executable bit set, etc. Packages that you install from apt-get/Software Center run this command or its equivalent for you automatically, which is why you don't usually have to worry about it.

If you want to start it immediately, you can call it directly:

sudo service css-servers start

You have the first part done. /etc/init.d is where initialization scripts are run from. However, they are not run automatically.

They are run in order as specified by symbolic links the /etc/rc*.d directories. Each run level has its own directory. Scripts with link names starting with K are run with the stop pararmeter, and those with names starting with S are run with the start parameter. By convention the file names start with K or S followed by a two digit number used for sequencing, and ending with the name of the script in /etc/init.d.

The links can be created manually, but are generally created with a script. The generic script update-rc.d is available on Ubuntu. The command man update-rc.d will give you documentation on who to use it. In your case try:

sudo update-rc.d css-servers defaults

To start it using the init script try:

sudo /etc/init.d/css-servers start

I generally start and stop the server this way to ensure the script is working as desired. Then I run update-rc.d to add it to the /etc/rc.d runlevel directories.


Additionally, for those who are stuck: the shebang is necessary for init.d scripts.

 #!/bin/sh