Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement
警吿

因為這是Wiki的一個條目,可以在任何時間內被任何人編輯,因此建議你不要完全使用這個腳本,而是將其當作編寫腳本的指導手冊看待。

這是一個簡單的 Ubuntu 伺服器啟動腳本,它沒有控制台,因為這不是問題。因為遊戲內已經有一個控制台。該腳本不會更新 Minecraft,但在晚些時候會加入這個功能。

先決條件

  • set up a user and group for minecraft so that it doesn't run as root
sudo adduser --system --no-create-home --home /srv/minecraft-server minecraft
sudo addgroup --system minecraft
sudo adduser minecraft minecraft # this adds user "minecraft" the group "minecraft"
  • hand your server-installation over to our new user, I have mine in /srv/minecraft-server
sudo chown -R minecraft.minecraft /srv/minecraft-server
  • create and edit the start/stop script creating a new file under /etc/init/minecraft-server (NOT /etc/init.d but /etc/init (without the .d) )
sudo nano /etc/init/minecraft-server

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).
  • Now install the start/stop to the default runlevels by running
sudo initctl reload-configuration

If you get an error saying the file does not exsist, try moving the minecraft-server file to /etc/init.d/ Also if after running sudo start minecraft-server says that they is no job for it, try running "sudo /etc/init.d/minecraft-server start"

Usage

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

Troubles?

You can check the server log by using:

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

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

Advertisement