Ubuntu – init.d script not running on startup

bootscriptUbuntu

I am hosting some Counter-Strike game servers on my dedicated server using screen. I have this script that I run when I want to start/stop the servers:

#! /bin/sh
# /etc/init.d/css-server
#

case "$1" in
  start)
    echo "Starting Nullus Imprimis war server..."
    screen -A -m -d -S css-war-server /home/css-servers/war-server/css/srcds_run -game cstrike +map de_dust2 +maxplayers 16 -autoupdate -port 2555 -tick 100 
    echo "Nullus Imprimis war server started"
    echo "Starting Nullus Imprimis pub server #1..."
    screen -A -m -d -S css-pub-server-1 /home/css-servers/pub-server-1/css/srcds_run -game cstrike +map de_dust2 +maxplayers 32 -autoupdate -port 2666 -tickrate 100
    echo "Nullus Imprimis pub server #1 started"
    ;;
  stop)
    echo "Stopping Nullus Imprimis war server..."
    screen -S css-war-server -X quit
    echo "Nullus Imprimis war server stopped"
    echo "Stopping Nullus Imprimis pub server #1..."
    screen -S css-pub-server-1 -X quit
    echo "Nullus Imprimis pub server #1 stopped"
    ;;
  *)
    echo "Usage: /etc/init.d/css-servers {start|stop}"
    exit 1
    ;;
esac

exit 0

I put this script (called css-servers) in /etc/init.d/ and to my knowledge that means it gets run when the system boots up. However when I check active screens using screen -ls there are none running.

How can I make these run on startup under Ubuntu Server?

Best Answer

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