How to start a script file on boot?
On latest Ubuntu, you should do it like this, create /etc/init/bukkit.conf
(whatever .conf),
description "Some java server"
author "Moi <[email protected]>"
start on runlevel [2345] # change start / stop level if needed
stop on runlevel [016]
pre-start script
echo "script is abort to start"
end script
exec /path/to/script param1 param2
post-start script
echo "script is started" # if you needed any post-start hack
end script
More information here.
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.