Startup – How to Start a Script File on Boot

servicesstartup

I am running a little minecraft server.

I want Lubuntu to execute the following script when the server boots up. NOT on login, and NOT on restart (unless it's starting up of course).

The script is currently located in:

/home/mc/server/craftbukkit.sh

I can manually launch the script by just going into the dir and typing ./craftbukkit.sh. But I want to fire off the script when the machine boots.

Best Answer

I run a minecraft server from a debian terminal, and this is probably the wrong way to do it, but it works. First, sudo apt-get install screen, then save the following script as /etc/init.d/minecraft:

#!/bin/bash
case "$1" in
  start)
    screen -S minecraft /home/mc/server/craftbukkit.sh
    echo "Server started on screen minecraft"
    ;;
  stop)
    screen -X -S minecraft kill
    echo "Server shutting down"
    ;;
  *)
    echo "Usage: /etc/init.d/minecraft {start|stop}"
    exit 1
    ;;
esac

exit 0

Now, run the following commands as root:

update-rc.d -f minecraft defaults

This will make the minecraft server run in the background when the system boots. To view the console, run screen -x minecraft in a terminal. To quit the console, press Ctrl+A and then D.

Related Question