[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

    I can write a "minecraft console" option in very easily. As you'll see, this is just Java running inside Screen. You can connect to the console now with screen -dr and disconnect with Ctrl+a then d. I'll add this in when I get some free time.

    Writing something to push commands to the server is very easy. Getting the output of those commands back to the terminal I'll have to look into, I'm not sure that's even possible.

    Do you still think a "minecraft cmd" would be useful if you couldn't get output back to the terminal? If you wanted to see the output of whatever you just ran, you'd have to tail the log file, or connect to "minecraft console".
     
  2. Offline

    mmorton89

    awesome script, I am using it on my server right now. thanks!

    edit - maybe add a option to automatically restart craftbukkit if the server happens to crash?
     
  3. Offline

    lorenzorota

    Thanks, i already added a line to the bash script:
    Code:
    mc_console() {
    screen -dr
    exit 1;
    }  
    then
    Code:
      console)
     mc_console
    ;;
    and changed the notification to:
    Code:
    * Usage: minecraft {start|stop|restart|backup|update|status|info|console}
    I just did this for temporary use and because i like shortcuts.
     
  4. Offline

    Super Jamie

    I did similar, I just included the usual "is it running?" check, and the Screen session name, incase you are running multiple Screens. I added the option for a different Screen session name to the rest of the script and a couple of other things while I was there. GitHub has been updated.

    Code:
    ## Connect to the active Screen session, disconnect with Ctrl+a then d
     
    mc_console() {
      if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
      then
        as_user "screen -S $SCRNAME -dr"
      else
        failure && echo " * $SERVERNAME was not running!"
        exit 1;
      fi
    }
     
  5. Offline

    ukballer1012

    I've been looking for a script like this for a long time and this is exactly what I want :D. Anyways, it wont work for me. I think I followed the instructions correctly but this is displayed when I try to start the server:
    Code:
    [root@V-2559 home]# minecraft start
    /etc/init.d/minecraft: line 18: CraftBukkit: command not found
    /etc/init.d/minecraft: line 49: collection: command not found
    sed: option requires an argument -- e
    Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
     
      -n, --quiet, --silent
                    suppress automatic printing of pattern space
      -e script, --expression=script
                    add the script to the commands to be executed
      -f script-file, --file=script-file
                    add the contents of script-file to the commands to be executed
      -i[SUFFIX], --in-place[=SUFFIX]
                    edit files in place (makes backup if extension supplied)
      -c, --copy
                    use copy instead of rename when shuffling files in -i mode
                    (avoids change of input file ownership)
      -l N, --line-length=N
                    specify the desired line-wrap length for the `l' command
      --posix
                    disable all GNU extensions.
      -r, --regexp-extended
                    use extended regular expressions in the script.
      -s, --separate
                    consider files as separate rather than as a single continuous
                    long stream.
      -u, --unbuffered
                    load minimal amounts of data from the input files and flush
                    the output buffers more often
          --help    display this help and exit
          --version  output version information and exit
     
    If no -e, --expression, -f, or --file option is given, then the first
    non-option argument is taken as the sed script to interpret.  All
    remaining arguments are names of input files; if no input files are
    specified, then the standard input is read.
     
    E-mail bug reports to: [email protected] .
    Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
    /etc/init.d/minecraft: line 56: s/.*level-name=//: No such file or directory
    /etc/init.d/minecraft: line 63: -jar: command not found
    /etc/init.d/minecraft: line 69: -XX:MaxPermSize=128M: command not found
    /etc/init.d/minecraft: line 70: -XX:+UseParallelOldGC: command not found
    /etc/init.d/minecraft: line 100: syntax error near unexpected token `('
    /etc/init.d/minecraft: line 100: `    failure && echo " * $SERVERNAME was already running! (pid $PID)"'
    I would include specific details but I have no clue what to say :p

    Edit:
    Here is the minecraft file http://pastie.org/4350047
     
  6. Offline

    Super Jamie

    Look at the line numbers you're getting errors on, then compare those with the actual line numbers on github. Your text editor seems to have got some weird line-wrapping going on.
     
  7. Offline

    ukballer1012

    Do you have any recommended methods for using a ram disk while still using this script?
     
  8. Offline

    Super Jamie

    Sorry I don't. I've considered it, but my current server doesn't have enough RAM for me to play around with ramdisk.

    I also don't like the idea of having to sync my ramdisk changes manually (or even partially-automated like with a cron job every minute) in the event of power outage. If I did setup a ramdisk, I'd want the on-disk copy to be a proper filesystem-level or block-level mirror of the ramdisk, like with LVM mirroring or mdadm software RAID or something.

    Honestly for the bother/time/risk of creating and administering such as setup, I'd just buy a 60G SSD and put my world on that, much easier and more reliable. You can get good ones for $100. It's true that eventually you will wear-level the SSD and it won't work anymore, however you'd need to write 8Gb a day for 10 years to wear-level a modern SSD.

    I do know Ahtenus' initscript includes commands for running with a ramdisk, that may be more suited to your needs? You can find it at https://github.com/Ahtenus/minecraft-init
     
  9. Offline

    ukballer1012

    Code:
    alternatives --install /usr/bin/java java /usr/java/jre1.6.0_31/bin/java 16001
    alternatives --config java
    After I ran these as root it doesn't recognize java as a command.
     
  10. Offline

    Super Jamie

    Do you actually have Java 6 R31 installed? If not, you'll need to modify the command to suit your system. You can find where your Java binary is with rpm -ql <java package name> | egrep "bin/java$"

    Under Sun's Java 7, you don't need to do the alternatives setup at all. If you're using Sun Java 7, just remove /usr/bin/java and reinstall the rpm.
     
  11. Offline

    Super Jamie

    I thought about this a bit more.

    Like I said, I don't like the idea of using RAM directly as a filesystem or block device. However, being able to keep the map in memory would be beneficial, especially for writes. The kernel's capability to keep files cached can do exactly this, however the set limits for how much memory can be used by cache are quite low.

    By default, up to 20% of unmapped memory can be cached writes before the kernel starts blocking writes. To cache a lot of writes, this is a low value. The kernel also allows 10% of unmapped memory, or writes up to 30 seconds old, to sit in a cache before being written out. I think these are also too generous.

    I set the following in/etc/sysctl.conf

    # decrease likeliness to swap
    vm.swappiness = 0
    # make sure there's 10Mb free at all times, default is too high
    vm.min_free_kbytes = 10240
    # if a write has sat in cache for 7.5 seconds, write it to disk
    vm.dirty_expire_centisecs = 750
    # regions are ~8M, so when we have 2 regions (16Mb) of dirty pages, write them out
    vm.dirty_background_bytes = 16384
    # don't block writes until 90% of system memory is full
    vm.dirty_ratio = 90

    The idea beind these being: The kernel checks for cached writes every 5 seconds. If a write has sat for 7.5 seconds, or is over 16Mb in size (a Minecraft map region is ~8Mb max), then write them out to disk. This should start cached writes sooner rather than later, preventing cache from filling with dirty pages. I also want to use up to 90% of unmapped system memory for cached writes before the kernel starts blocking writes, which would affect application performance.

    This should keep the *required parts* of the map in system memory, and fully use that memory to perform reads and writes as much as possible. The first read of a map region will be slow as it always has to come from disk, subsequent access to that part of the map should be fast, as the file is in cache.

    I've got 5Gb of RAM, a 2Gb map, and have set Java to occupy 2Gb of HugePages. The system itself uses just under 1Gb, which leaves a little over 2Gb to hold cached files. This seems like it would give the benefits of a ramdisk (except for the slowness of the initial read) without any of the drawbacks I was concerned with in my previous post. This also seems like it would use memory more efficiently, as I'm not using any memory for the parts of the map which nobody is visiting.

    I'll see how it goes.
     
  12. Offline

    lorenzorota

    hello, for some reason i get this error when i run "mc info" or "mc status":

    Code:
    /etc/init.d/minecraft: line 331: -: syntax error: operand expected (error token is "-")
     
  13. Offline

    Super Jamie

    Hmm, I'm not able to reproduce, I tried with and without HugePages. Are you using the latest version of the script from GitHub? Try that first. What OS are you running? Are you able to put the output of cat /proc/meminfo on pastebin?
     
  14. Offline

    lorenzorota

    http://pastebin.com/ute5SL47
     
  15. Offline

    Super Jamie

    Thanks for that. What distro are you using?

    When I know that I'll run it up in a VM and test how it reports HugePages, I've only tested that part on CentOS and Fedora.

    If you need a workaround for now, you can comment out all the HugePages-related stuff (add a # to the start of lines 327-333 and lines 341-345).
     
  16. Offline

    Spliffie

    Hi Guys,

    This has been my home page for the last few days, and id like to say i have a Craftbukkit server working nicley.

    only problems i'm having is the backups.
    output as follows after running mc backup or minecraft backup:


    mc backup
    * CraftBukkit is running. Commencing save...
    * Notifying users of save...
    * Setting server read-only...
    * Saving map named "iGSA MineCraft Server" to disk...
    * Map saved. [ OK ]
    * Backing up CraftBukkit map named "iGSA MineCraft Server"...
    * Syncing /home/bukkit/craftbukkit/iGSA MineCraft Server to /home/bukkit/backup s/iGSA MineCraft Server
    rsync: link_stat "/home/bukkit/craftbukkit/iGSA" failed: No such file or directo ry (2)
    rsync error: some files/attrs were not transferred (see previous errors) (code 2 3) at main.c(1039) [sender=3.0.6]
    * Creating compressed backup...
    tar: Cowardly refusing to create an empty archive
    Try `tar --help' or `tar --usage' for more information.
    * Backed up map. [ OK ]
    * Backing up the CraftBukkit server executable...
    * Backed up executable. [ OK ]
    * CraftBukkit is running. Re-enabling saves...
    Regards,
    Wesley
     
  17. Offline

    Super Jamie

    Evidently I was not handling spaces in the worldname correctly. This should be resolved, please fetch the latest version from github. Thanks for pointing this out.
     
  18. Offline

    Spliffie

    Sorry man could i ask you for a link to the script?
     
  19. Offline

    Super Jamie

  20. Offline

    lorenzorota

    Linux version 2.6.32-042stab059.7 (root@rh6-build-x64) (gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) ) #1 SMP Tue Jul 24 19:12:01 MSK 2012


    ps: sorry for late response :S i was busy with school
     
  21. Offline

    Super Jamie

    It's cool. That syntax error should be fixed now, please fetch the latest version from github and test?
     
  22. Offline

    Spliffie

    Hi and thank you, seems to be kind of working now, take a look below.
    first pic is the files in the backup dir and the other is the out put of the back up.

    mcbkups.PNG mcbkup_process.PNG
     
  23. Offline

    InsaneMosquito

    I have an issue when issuing the 'minecraft stop' command. It never seems to be able to stop the server:

    If I run 'ps -aef | grep minecraft', it still shows my screen session is running the server.
     
  24. Offline

    Super Jamie

    Sorry, I didn't test this properly. I've made more changes and confirmed everything actually does work with spaces. Please fetch again from github, apologies for the bother.

    I've found this occasionally too, Bukkit not being 100% stable, but it doesn't happen constantly.

    Try running the server without the initscript, just run with "java [your usual options] craftbukkit.jar". Then see if a normal quit works when you type "save-all" and "stop" in the server console. If either of these actions take longer than 10 seconds, you'll need to increase the sleep 10 values in mc_stop() and mc_saveoff().

    Also if anyone's following, I'm now supporting Ubuntu Server 12.04 as well as CentOS 5 and 6.

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

    InsaneMosquito

    It happens constantly for me. I extended the sleep values to be 120. I'd expect two minutes to be more than enough time since a normal stop takes only a few seconds.
     
  26. Offline

    Super Jamie

    Hi all,

    I am still maintaining this. I get bug reports every now and then which have all been fixed, and have extended it to be able to run multiple instances of the same server.

    Feel free to check it out if you are running a CraftBukkit or vanilla server on Linux.
     
  27. Offline

    lorenzorota

    Super Jamie, I created a new case statement for the initscript which I thought would be pretty useful for people who are not so familiar with the MC console or just prefer not using it.

    So I added this function:
    Code:
    ## Broadcasts a message something
     
    mc_say() {
        s_string="${@:1}"
      if [[ -z "$s_string" ]]
      then
        echo " * You need to enter your message. Usage; \"minecraft say message\""
      elif server_running
      then
        echo " * Broadcasting \"$s_string\""
        as_user "screen -p 0 -S $SCRNAME -X eval 'stuff \"say $s_string\"\015'"
      else
        failure && echo " * $SERVERNAME was not running!"
        exit 1
      fi
    }
    Created this case statement:
    Code:
      say)
    mc_say ${@:2}
    ;;
    And well... I also edited the usage display list:
    Code:
     echo " * Usage: minecraft {start|stop|restart|backup|update|status|info|console|say}"
    My version may be rather a bit clumsy, but I just wrote it as a small script which would allow me to easily create crontab jobs with adjustable messages such as:
    Code:
    0 0 25 2 * /etc/init.d/minecraft say Today is Lorenzo's Birthday, Let's party and eat some cake WOO!
    or even displaying the time every 10 minutes:
    Code:
    */10 * * * * /etc/init.d/minecraft say The time right now is: $(date +"%r")
     
  28. Offline

    Super Jamie

    That's excellent, thank you so much! I've created a new Issue on GitHub, I'll add this feature in next time I'm working on it.
     
  29. Offline

    FShiwani

    I seem to be having an issue. Whenever I use any command, it says
    [ERROR] Settings file /etc/sysconfig/minecraft does not exist. Can't run!
    Tried running from both root and minecraft user(mine is called minecraft not bukkit)
     
  30. Offline

    advtech

    I have been some issues regarding the script saying that my server.properties doesn't exist when it's setting right in the root folder.
     
Thread Status:
Not open for further replies.

Share This Page