[ADMIN] CraftBukkit Initscript for CentOS/Fedora/Ubuntu

Discussion in 'Bukkit Tools' started by Super Jamie, Feb 19, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Super Jamie

    This is an initscript to run a Minecraft or CraftBukkit server on CentOS, Fedora, and Ubuntu.

    If anyone has any edits/suggestions/requests, please post here and I'll see what I can do.

    • Start, stop, restart CraftBukkit as a system service
    • Automatic (via cron) and manual logfile rotation
    • Automatic (via cron) and manual backups
    • Backup compression and rotation (keeps 7 days worth of backups)
    • Check latest Recommended Build and update to it if required
    • Information display including Java path, current memory usage, current TCP connections
    • Able to run multiple separate instances of the server at once
    Supported Distributions
    • CentOS 6, CentOS 5, Fedora 14 (probably works on Fedora Core 6 and later, untested)
    • Ubuntu Server 12.04 LTS
    Other distros which use SysV Init or Upstart (Debian, Mint) will probably work.
    Distros using systemd (Fedora 15+, Arch Linux, Debian 8, etc) will not work.

    Get the script, view Requirements, Installation, Backups, Multiple Instances, and Usage
    Released under GNU GPL v3 - http://www.gnu.org/licenses/

    Thanks to these people whose work I have used in the making of this
  2. Offline


    This is amazing work, will be using this. Thanks much
  3. Offline


    I get the following error when running backup. Any suggestions?

    [[email protected] etc]$ mc backup
    * CraftBukkit is running. Commencing save...
    * Notifying users of save...
    * Setting server read-only...
    " to disk...p named "world
    * Map saved. [ OK ]
    "...acking up CraftBukkit map named "world
    to /home/bukkit/backups/worldukkit/world
    rsync: link_stat "/home/bukkit/craftbukkit/world\#015" failed: No such file or directory (2)
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
    * Creating compressed backup...
    * Backed up map. [ OK ]
    * Backing up the CraftBukkit server executable...
    tar: world\r: Cannot stat: No such file or directory
    tar: Exiting with failure status due to previous errors
    * Backed up executable. [ OK ]
    * CraftBukkit is running. Re-enabling saves...
    [[email protected] etc]$

    EDIT: Nevermind... Im a dummy. Forgot to give the bukkit user access to the script. Now Rsync works, but im still getting an error from tar. Can you help?
  4. Offline

    Super Jamie

    DOS/Windows and Unix/Linux use different ASCII characters for their line endings. Unix and Linux use hex 0x0A which is called Line Feed (LF), DOS and Windows use hex 0x0D which is called Carriage Return (CR) followed by a Line Feed. This is why you sometimes open downloaded text files in Notepad and they appear as all one line, they come from a Linux webserver and have no CR in them.

    I think the script is interpreting the world name in your server.properties file as "world Carriage Return" which breaks the tar command.

    You can convert your DOS text files to Unix format with the dos2unix program. Here are some handy commands to run:
    this just converts the server.properties file
    dos2unix server.properties
    this one finds all your .txt and .yml files and converts them
    find /home/bukkit/craftbukkit/ -regex ".*txt*\|.*yml*"

    Give these a go and see if the tar script works?

    To prevent this happening, you can do few things:
    - edit text files on Windows, upload them, run them through dos2unix before using them
    - use a Linux text editor in shell, for example nano (simple, Ctrl+O saves, Ctrl+X quits) or vi (more complex)
    - use a Windows text editor which supports Unix line endings, I would suggest EditPadLite
  5. Offline


    Goodness gracious. I feel like even more of a dummy. I knew about the CR thing... I had forgotten that I edited with notepad though like two months ago. Thank you. Everything works now.

    Ok. another problem. I get this error when running the log rotate.
    [[email protected] ~]$ mc logrotate
    /etc/init.d/minecraft: line 262: [: lck: integer expression expected
    [[email protected] ~]$

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  6. Offline

    Super Jamie

    All good about the CRLF, I made the same mistake myself :) I have noticed that logrotate isn't working on my server either, though it does on my test server. I'll be looking into this soon.
  7. Offline


    ok thanks
  8. Offline

    Super Jamie

    Silly me, I was trying to rotate the lockfile too. Evidently I didn't test log rotation when the server was actually running. I've updated the first post, this should work now. Thanks for the debug info!
  9. Offline


    Your Welcome, and thanks for the quick fix!

    Just some more feedback/debug. after running mc restart and then mc info i get this output:
    [[email protected] craftbukkit]$ mc info
    * CraftBukkit (pid pts/0) is running...
    ERROR: Process ID list syntax error.
    ********* simple selection ********* ********* selection by list *********
    -A all processes -C by command name
    -N negate selection -G by real group ID (supports names)
    -a all w/ tty except session leaders -U by real user ID (supports names)
    -d all except session leaders -g by session OR by effective group name
    -e all processes -p by process ID
    T all processes on this terminal -s processes in the sessions given
    a all w/ tty, including other users -t by tty
    g OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
    r only running processes U processes for specified users
    x processes w/o controlling ttys t by tty
    *********** output format ********** *********** long options ***********
    -o,o user-defined -f full --Group --User --pid --cols --ppid
    -j,j job control s signal --group --user --sid --rows --info
    -O,O preloaded -o v virtual memory --cumulative --format --deselect
    -l,l long u user-oriented --sort --tty --forest --version
    -F extra full X registers --heading --no-heading --context
    ********* misc options *********
    -V,V show version L list format codes f ASCII art forest
    -m,m,-L,-T,H threads S children in sum -y change -l format
    -M,Z security data c true command name -c scheduling class
    -w,w wide output n numeric WCHAN,UID -H process hierarchy
    - Java Path : /usr/java/latest/jre/bin/java
    - Start Command : java -Xms2650M -Xmx2650M -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:UseSSE=2 -XX:+AggressiveOpts -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XXarallelGCThreads=4 -jar craftbukkit.jar nogui
    - Server Path : /home/bukkit/craftbukkit
    - World Name : world
    - Process ID : pts/0
    - Memory Usage : kb
    - Active Connections :
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0* LISTEN
    tcp 0 555 174.21.**.**:63849 ESTABLISHED (PS I EDITED THE IPs OUT)
    tcp 0 403 123.211.**.**:53992 ESTABLISHED
    tcp 0 107 12.54.**.**:53302 ESTABLISHED
    tcp 0 246 90.190.**.**:55571 ESTABLISHED
    tcp 0 77 192.168.**.**:1262 ESTABLISHED
    tcp 0 529 69.146.**.**:52538 ESTABLISHED
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  10. Offline

    Super Jamie

    What OS and shell are you running on?

    I updated the script in the first post just now. I changed the way I detected the PID of the running process, it may have fixed this.
  11. Offline


    Is there anyway to get access to the console? It looks like the the script starts a screen session, but when I try to attach to it I get this error message:
    [[email protected] ~]$ screen -r minecraft
    Cannot open your terminal '/dev/pts/1' - please check.
    Is there anyway to fix this?
    EDIT: Never mind i got it.
  12. Offline

    Super Jamie

    For other people I'll explain anyway :) This happens when you ssh in as root (or another user) then su to the bukkit user. You can fix the above by giving others access to your virtual terminal with chmod 777 /dev/pts/1 before the su command.

    From your hostname, I'm assuming this works on Debian too? Handy to know!
  13. Offline


    No I'm using Debian, I had it installed before I put CentOs on my machine. During the install it made my hostname debian, and wouldn't let me change it.
  14. Offline

    Super Jamie

    You can change hostname permanently with HOSTNAME= in /etc/sysconfig/network, and for the current boot with hostname newname as root.
  15. Offline


    Hi before I integrate this to my live server, I wanted to go through setup in a virtualbox environment. I have CentOS 6 installed and setup. Could you elaborate on how to do the step for setting java as an alternative? I'm running the built in Java that comes with CentOS 6 and the below command does not seem to work.

  16. Offline

    Super Jamie

    You're almost there, now do alternatives --config java and select the Sun Java binary instead of the OpenJDK Java binary. You can confirm the JVM you've chosen with java -version. I've updated the first post to reflect this.
  17. Offline


    # alternatives --config java
    There are 2 programs which provide 'java'.
      Selection    Command
      1          /usr/lib/jvm/jre-1.5.0-gcj/bin/java
    *+ 2          /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
    Enter to keep the current selection[+], or type selection number: 1
    # alternatives --config java
    There are 2 programs which provide 'java'.
      Selection    Command
    + 1          /usr/lib/jvm/jre-1.5.0-gcj/bin/java
    *  2          /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
    Enter to keep the current selection[+], or type selection number:
    # java -version
    java version "1.5.0"
    gij (GNU libgcj) version 4.4.4 20100726 (Red Hat 4.4.4-13)
    Copyright (C) 2007 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    It says it is java 1.5.0. Should I update that to Java 1.6 or even 1.7? If so, could you walk me through doing that?
  18. Offline

    Super Jamie

    Yeah you should have Java 1.6. Grab the RPM download from http://www.java.com/en/ (use the 64-bit version if you have a 64-bit OS) which will download a bin file. Make this file executable with chmod +x jre-<version>.bin and run it as the root user. Then run the two alternatives commands in the first post to add the new binary to alternatives, and to select it. Confirm again with java -version and you should be good to go!
  19. Offline


    Ok so I installed this and when i do mine craft start it just says FAILED in the terminal..
  20. Offline

    Super Jamie

    Change to your craftbukkit directory and try starting Java manually, that should give you more of an idea why it's failing. You'd use something like

    java -Xms4096M -Xmx4096M -Djava.net.preferIPv4Stack=true -XX:MaxPermSize=256M -XX:UseSSE=2 -XX:-DisableExplicitGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=2 -jar craftbukkit.jar nogui

    Minor script update: Log rotation wasn't working on one of my servers, but was on the other. I think I've fixed it now.

    I've also moved the script to github.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  21. Offline


    Here's the console on 2 tries. Once with your code and once with the code supplied by Bukkit on the Wiki.

    Last login: Fri Mar 30 19:50:14 on ttys001
    Lyndons-MacBook:~ lyndondueck$ ssh [email protected]
    [email protected]'s password: 
    Last login: Fri Mar 30 22:38:31 2012 from
    [email protected] [~]# cd /home/bukkit/craftbukkit
    [email protected] [/home/bukkit/craftbukkit]# java -Xms4096M -Xmx4096M -Djava.net.preferIPv4Stack=true -XX:MaxPermSize=256M -XX:UseSSE=2 -XX:-DisableExplicitGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=2 -jar craftbukkit.jar nogui
    182 recipes
    27 achievements
    java.io.IOException: Cannot run program "sh": java.io.IOException: error=12, Cannot allocate memory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
    at java.lang.Runtime.exec(Runtime.java:610)
    at java.lang.Runtime.exec(Runtime.java:483)
    at jline.UnixTerminal.exec(UnixTerminal.java:297)
    at jline.UnixTerminal.exec(UnixTerminal.java:282)
    at jline.UnixTerminal.stty(UnixTerminal.java:273)
    at jline.UnixTerminal.initializeTerminal(UnixTerminal.java:77)
    at jline.Terminal.setupTerminal(Terminal.java:75)
    at jline.Terminal.getTerminal(Terminal.java:26)
    at jline.ConsoleReader.<init>(ConsoleReader.java:191)
    at jline.ConsoleReader.<init>(ConsoleReader.java:186)
    at net.minecraft.server.MinecraftServer.<init>(MinecraftServer.java:94)
    at net.minecraft.server.MinecraftServer.main(MinecraftServer.java:611)
    at org.bukkit.craftbukkit.Main.main(Main.java:134)
    Caused by: java.io.IOException: java.io.IOException: error=12, Cannot allocate memory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
    at java.lang.ProcessImpl.start(ProcessImpl.java:81)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
    ... 13 more
    01:44:34 [INFO] Starting minecraft server version 1.2.4
    01:44:34 [INFO] Loading properties
    01:44:34 [INFO] Starting Minecraft server on *:25565
    01:44:34 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.4-R1.0-b2126jnks (MC: 1.2.4) (Implementing API version 1.2.4-R1.0)
    01:44:34 [INFO] Preparing level "world"
    01:44:34 [INFO] Default game type: 0
    01:44:35 [INFO] Preparing start region for level 0 (Seed: -7151966787964701982)
    01:44:35 [INFO] Preparing start region for level 1 (Seed: -7151966787964701982)
    01:44:35 [INFO] Preparing start region for level 2 (Seed: -7151966787964701982)
    01:44:36 [INFO] Server permissions file permissions.yml is empty, ignoring it
    01:44:36 [INFO] Done (1.109s)! For help, type "help" or "?"
    01:44:36 [INFO] Unknown command. Type "help" for help.
    01:45:45 [INFO] CONSOLE: Stopping the server..
    01:45:45 [INFO] Stopping server
    01:45:45 [INFO] Saving chunks
    t.jar noguir [/home/bukkit/craftbukkit]# java -Xms1024M -Xmx1024M -jar craftbukki 
    182 recipes
    27 achievements
    01:46:17 [INFO] Starting minecraft server version 1.2.4
    01:46:17 [INFO] Loading properties
    01:46:17 [INFO] Starting Minecraft server on *:25565
    01:46:17 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.4-R1.0-b2126jnks (MC: 1.2.4) (Implementing API version 1.2.4-R1.0)
    01:46:17 [INFO] Preparing level "world"
    01:46:17 [INFO] Default game type: 0
    01:46:17 [INFO] Preparing start region for level 0 (Seed: -7151966787964701982)
    01:46:17 [INFO] Preparing start region for level 1 (Seed: -7151966787964701982)
    01:46:18 [INFO] Preparing start region for level 2 (Seed: -7151966787964701982)
    01:46:18 [INFO] Preparing spawn area: 61%
    01:46:18 [INFO] Server permissions file permissions.yml is empty, ignoring it
    01:46:18 [INFO] Done (1.150s)! For help, type "help" or "?"
    It seems like the second time works, but I never tried it in the MC client. I'll do that now.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  22. Offline

    Super Jamie

    So allocating 4Gb of memory with-Xms4096M -Xmx4096M results in the error "error=12, Cannot allocate memory" but allocating 1Gb of memory with -Xms1024M -Xmx1024M works fine. There's your problem!
  23. Offline


    Ok so how do I change this in the script to allocate only 1GB of memory?

    Edit: I found the startup command and changed it to 1024M but I still get a failed error. I'm going to restart the server and see if that will solve the problem.

    Yeah I can't get it to work but doing the manual command seems to work java -Xms1024M -Xmx1024M -jar craftbukkit.jar nogui

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  24. Offline

    Super Jamie

    What Java version do you have (java -version)? How many CPU cores do you have? What SSE level does your processor support (cat /proc/cpuinfo | grep sse)? If you have heaps of plugins, maybe 256Mb PermSize isn't enough, try taking that part out. You could also just use the working commandline as the invocation line in the script.
  25. Offline


    Yeah I tried replacing the invocation with the working command line but it still returns the FAILEd error.

    java version "1.6.0_22"
    OpenJDK Runtime Environment (IcedTea6 1.10.6) (rhel-
    OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
    I've got 4 CPU cores
    Right now I'm just trying to run the server vanilla and take it from there. Also the perm size is 128 currently.

    Ok I talked to my host and they informed me that the user (bukkit) didn't have the proper permissions to start the script so I changed the username to root (since I was logging in with root anyways) and started it and now it's good to go. I will stay in touch with my host because they were going to try and help me get it working with the bukkit user.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  26. Offline

    Super Jamie

    Use actual Sun Java from java.com, not OpenJDK from the RHEL Server channel, you should use Sun Java to run anything Minecraft. You also might want to upgrade, 1.6.22 is old, the current is 1.6.31. I haven't tested at all on EL5 so maybe it doesn't work?

    Tested ok on CentOS 5.8 with Sun Java 1.6.31. Try some of the other things I suggested.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
  27. Offline


    I have it running as root and it seems to be running ok. My host says the added security risk is minimal-hardly noticeable so I'll leave it like this for now.
  28. Offline


    Ok the server keeps crashing using this script. I don't know if it's due to the performance issues in 1.2.5 or what. We also had an attack threat on the server tho no data has been lost it just keeps going offline. I've already banned a few users who made the server really laggy when they logged in so I assumed they were hackers.

    Any ideas? It usually happens overnight while I'm sleeping and I have to restart the master server when i wake up.
  29. Offline

    Super Jamie

    This just runs the server in a Screen session, there's no more/less security than running it manually. This is why you don't run things as the root user.

    Crashes could be many things - plugins, Minecraft bugs, Bukkit bugs, CentOS bugs, the actual system you're running all this on - check your logs for error messages and put them into Google. Lag could also be any of these things. Troubleshooting your server security and instability is a bit beyond the scope of my script, sorry.
  30. Offline


    is there gonna be an update that you can also do like
    "minecraft console"
    or perhaps "minecraft cmd"

    There is a line that shows the following:

    INVOCATION="java -Xms3075M -Xmx3075M -Djava.net.preferIPv4Stack=true -XX:MaxPermSize=128M -XX:UseSSE=2 -XX:-DisableExplicitGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=$CPU_COUNT -XX:+UseLargePages -jar $SERVICE nogui"
    You should change the "Xms3075M -Xmx3075M" to a number that your computer, or vps is capable of using.
    For example: "Xms500M -Xmx500M", but this is a small amount of ram capacity for your server and it might crash even quicker. So you might need to allocate a little more memory: "Xms1024M - Xmx1024M"

    First mine couldn't start because it wanted to use up more ram than i had, so when i decreased the size it worked.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 24, 2016
Thread Status:
Not open for further replies.

Share This Page