Namespaces

Variants

Share

Share
Views
Actions

Tutorials/Ubuntu startup script

From Minecraft Wiki
Jump to: navigation, search
Warning
Since this is a wiki and anyone may modify any page at any time, it is suggested that you do not actually use this script but instead simply use it as a guideline for writing your own.

This is a simple startup-script for the upstart mechanism used by ubuntu-servers. It won't give you a console, which I don't consider a problem since there's an ingame console anyway. It also doesn't update Minecraft, I believe there's a built-in updater coming on the way.

[edit] Prerequisites

  • add a user for minecraft so that it doesn't run as root
sudo adduser --system --no-create-home --home /srv/minecraft-server minecraft
  • hand your server-installation over to our new user, I have mine in /srv/minecraft-server
sudo chown -R minecraft /srv/minecraft-server
  • install the upstart script by opening /etc/init/minecraft-server.conf (NOT /etc/init.d but /etc/init (without the .d)
sudo nano /etc/init/minecraft-server.conf

and pasting the following into it. Don't forget to change the directory after "chdir" to your installation

# description "start and stop the minecraft-server"

start on runlevel [2345]
stop on runlevel [^2345]

console log
chdir YOUR_INSTALLATION_DIRECTORY
setuid minecraft
setgid minecraft

respawn
respawn limit 20 5

exec /usr/bin/java -Xms1536M -Xmx2048M -jar minecraft_server.jar nogui

Above Explained (Note, this script isn't usable.):

# description "start and stop the minecraft-server" <-- Adds a tip to what this script does.

start on runlevel [2345] <-- Tells Ubuntu when to start the server. Runlevels 2, 3, 4, and 5 are the "normal operation".
stop on runlevel [^2345] <-- Tells Ubuntu when to stop the server. The ^ means NOT.

console log <-- Logs the actions taken
chdir YOUR_INSTALLATION_DIRECTORY <-- Changes the active directory to the installation dir.
setuid minecraft <-- Sets the UserID to "minecraft" (acts like Minecraft user)
setgid minecraft <-- Sets the GroupID to "minecraft" (acts like Minecraft group)

respawn <-- Allows the program to "respawn" (restart) when it dies unexpectedly.
respawn limit 20 5 <-- Allows the program to "respawn" 20 times in 5 seconds.

exec /usr/bin/java -Xms1536M -Xmx2048M -jar minecraft_server.jar nogui <-- Below...
'exec' > Executes command
'/usr/bin/java' > Invokes Java.
'-Xms1536M' > Sets minimum allocated memory limit.
'-Xmx2048M' > Sets MAXIMUM allowable memory limit.
'-jar minecraft-server.jar' > Tells Java to run the jarfile minecraft_server.jar
'nogui' > Tells minecraft-server.jar to run without a GUI. (Graphical screen).

Since Ubuntu 13.10 having both --stop "stop" and --start causes a errors, remove the --stop "stop" and use ps -ef to get PID and use kill PID to close it if you require it shut down to change settings.

[edit] Usage

  • to start the server
sudo start minecraft-server
  • to stop the server
sudo stop minecraft-server

[edit] Troubles?

You can check the server log by using:

tail /var/log/upstart/minecraft-server.log

If that doesn't help, just contact me: User:Cel1ne