Linux INIT script for bukkit

Discussion in 'Bukkit Help' started by ShivalWolf, Jan 18, 2011.

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

    ShivalWolf

    Hi All
    1st I hope this is the right thread to post this.

    I just wanted to share my LINUX(debian based) init script that I use for bukkit/minecraft. This script was based off previous ones I use for CSS and other games. This init script runs the game server as a specified user on the system and inside a screen session. The screen session allows you to load up the server console via the dedicated user and lets you interact with it without having to kill the server or running it in a terminal all the time.

    This script requires bash, wget, sudo, screen as well as a dedicated user to run the server as.
    There are a number of variables that can be adjusted in the script to match almost any system and install path. All these variables are commented for easy adjustment.

    The init script contains several commands "start|stop|restart|clear|update"
    The 1st 3 should be obvious to their function
    "Clear" will clear the pid files and is sometimes required if the server is killed badly where the pid files are not removed
    "Update" This command uses the web addresses specified in the init script config to 1st download the md5 file for the current bukkit version and checks it against the previous downloaded md5 file. If they are differnt it assumes and update and downloads the new server .jar file. It will then verify this file against the md5 it downloaded, stop the server, copy the new .jar file and then restart the server.


    The .zip archive attached contains 3 script files.
    DOWNLOAD: http://mc-1.snapgaming.net/mcinit.zip

    mc-1-server.init
    This is the main .init file all the config is in this script, This file should be placed somewhere outside the game directory and owned/executable via root. I put all my init scripts into /var/games/launchers Before using the init script make sure you adjust the key variables for server location user and any other path options to match your setup.

    mc-1.sh
    This is the launcher script. It is a simple script that has init.d skeleton base so it can be placed in /etc/init.d (or equivalent). This script needs to be altered to the user you want to run the server as and the path to the mc-1-server.init file needs to match where you placed the file.
    This file in /etc/init.d needs to be owend and executable by root
    I also place a copy of this script in the mc users home directory as launcher.sh owned and executed by the mc user so that you can ssh in as that user and just run ./launcher.sh (command)

    server_nogui.sh
    This is the generic starter script and needs to be placed in the same path as the craftbukkit.jar file. Its very standard and separate from the init file to allow for easy adjustment.


    1 last change needs to be made to the sudoers file in order to give permission to use sudo to launch the script as the user.

    Code:
    /etc/sudoers:
    mc-1 ALL=(mc-1) NOPASSWD: /var/games/launchers/mc-1-server.init
    
    Just remember to adjust the username and the path to the init file to match your setup.

    REMEMBER if you want this to automatically startup you will also have to run the update-rc.d to insert the appropriate symlinks into rc0-6.d. The Runlevels can be adjusted in the mc-1.sh script

    TO DO:
    This list relies on me learning how to write a plugin.

    • Modify the stop code in the init script to trigger a proper save-all and 'stop' instead of the kill -1 used by the script. Currently a save is not automatically triggered prior to the termination of the server so it is possible for data to be lost.
    • Add a version command to the init script to just echo the current build number
    • Add a status command to the init script to get the current state of the server and maybe a player list/count.
    If you encounter any problems or have any questions please let me know and I will attempt to answer them.
    If you want to help me write a plugin that allows for me using a UDP message to a localhost port that the bukkit server listens to to trigger a kick all players then save-all then stop that would be good to. Any recommendations on how else to send the required commands would also be helpful.
     
  2. Offline

    TnT Retired Staff

    Nice. I will add this post as a feature on the Advance part of my Ubuntu setup guide.
     
  3. Offline

    AbsolutePolak

    is it just me or is there no attacked .zip?
     
  4. Offline

    TnT Retired Staff

    Not just you.
     
  5. Offline

    ShivalWolf

    Ok that's just weird It was attached to the file But I am behind a very dodgy proxy so it may have been stripped out. I will upload it to my server and post the link.
    --- merged: Jan 19, 2011 12:16 AM ---
    Download link is now in the initial post.
     
  6. Offline

    AbsolutePolak

    one last question
    mc-1 ALL=(mc-1) NOPASSWD: /var/games/launchers/mc-1-server.init
    what parts do we change to our username? im guessing the the mc-1 parts?
     
  7. Offline

    ShivalWolf

    Yes its the mc-1 part

    mc = minecraft
    1 = server 1.

    It was my standard naming convention.
    so just change mc-1 to whatever user whenever it occurs or match your own naming convention.
     
  8. Offline

    halvors

    The init script does not stop the server... What should i do? May we have some updates?
    --- merged: Jan 24, 2011 1:16 AM ---
    The init script does not stop the server... What should i do? May we have some updates?
     
  9. Offline

    ShivalWolf

    yeah sorry theres a bug in the stop
    change kill -1 to kill -9
    --- merged: Jan 24, 2011 2:24 AM ---
    As for updates I still cant find a good way to send a save and proper stop Plugins apparently cant do it and I can't seem to get the java app to respond to messages sent to its stdin PTS it seems to close the listener and only respond in the actual terminal.

    Also can't find a way to grab the current build but I have it saving the build timestamp which is at least a little better then nothing.
    --- merged: Jan 26, 2011 12:40 AM ---
    The zip attached in the main post has been updated.
    It uses the send command to screen method

    http://forums.bukkit.org/threads/li...-interaction-from-outside-autosave-stop.2187/

    To send a save-all and stop to the MC process instead of forcefully killing MC. However it will fall back to a kill if the stop fails.



    It seems to work at least for me on Debian and does a nice clean save.
     
  10. Offline

    Robby Stolle

    so I must be broken. How do I get the init script to launch
    I get unknown job
     
  11. Offline

    Robby Stolle

    zero@zero-Aspire-R1600:~$ ./home/zero/Desktop/mc.init
    bash: ./home/zero/Desktop/mc.init: No such file or directory
    zero@zero-Aspire-R1600:~$ sudo ./home/zero/Desktop/mc.init
    [sudo] password for zero:
    sudo: ./home/zero/Desktop/mc.init: command not found
    zero@zero-Aspire-R1600:~$ start ./home/zero/Desktop/mc.init
    start: Unknown job: ./home/zero/Desktop/mc.init
    zero@zero-Aspire-R1600:~$ start /home/zero/Desktop/mc.init
    start: Unknown job: /home/zero/Desktop/mc.init
    zero@zero-Aspire-R1600:~$ cd D
    Desktop/ Documents/ Downloads/
    zero@zero-Aspire-R1600:~$ cd Desktop/
    zero@zero-Aspire-R1600:~/Desktop$ start mc.init
    start: Unknown job: mc.init
    zero@zero-Aspire-R1600:~/Desktop$ mc.init
    mc.init: command not found
    zero@zero-Aspire-R1600:~/Desktop$ start ./mc.init
    start: Unknown job: ./mc.init
    zero@zero-Aspire-R1600:~/Desktop$ version mc.init
    version: command not found
    zero@zero-Aspire-R1600:~/Desktop$
     
Thread Status:
Not open for further replies.

Share This Page