Solved Linux Crontab Question - How to access console

Discussion in 'Bukkit Help' started by LHammonds, Mar 10, 2012.

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

    LHammonds

    Greetings,

    Short-and-to-the-point:
    Question: How do I issue the "stop" command to a CraftBukkit console that was started from Crontab?

    Longer-drawn-out-info:
    I have Ubuntu Server 10.04 LTS (64-bit) running CraftBukkit 1.1-R4, Build 1938 and Java JRE 6, Update 31 (x64).

    I have a Bash script created called "startcb.sh" which starts CraftBukkit. When run manually, I obviously have access to the console to type "stop" to shut it down cleanly in order to perform maintenance and reboot.

    I found that I need to cycle the server at least once a day in order to maintain smooth performance. To help automate this, I found and started to use the AutoShutdown plugin which cleanly stops the CraftBukkit server at pre-defined times. However, the automated shutdown also implies that I need an auto-start system and that is why Crontab seemed like the best solution. The problem is that if I need to stop CraftBukkit at a time different from AutoShutdown, I don't know how to do it cleanly. Killing the process ID of the server would most-likely cause corruption problems (not a clean stop)

    As it stands right now, I cannot use Crontab to automatically start the server if I cannot control stopping it when necessary (CPU spike, power loss, reboot for reported lag, installing new plugin, etc.)

    Anyone know how to manually and cleanly stop the CraftBukkit server once started via Crontab?

    Thanks,
    LHammonds
     
  2. Offline

    zipron

    Best way to do is to put it in a screen, so you can always access your console even if it's started with a crontab. (however, you should look up the commands itself, I don't know them: man screen)

    Don't want to do that? ps aux will give a list of all processes running, search the ID of your bukkit proces, it's
    Code:
    bukkit    5204 14.8 42.0 1739640 864320 pts/3  Sl+  Mar09 240:48 java -Xmx1024M -Xms1024M -jar craftbukkit.jar
    for me, so 5204 is the proces ID, then kill it: kill 5204

    hope that helped =)
    zip
     
  3. Offline

    LHammonds

    Screen seems like the perfect solution. Thanks for mentioning it.

    I know how to kill a process ID but if used on a bukkit server, wouldn't that risk corrupting the world/region somehow?

    PS - Anyone looking to learn the basics on how to use the screen command (rather than looking at the man page and scratching your head), take a look here.

    I particularly liked one suggestion to add a colored status bar to the bottom of a screen session by editing / creating the following file:

    vi ~/.screenrc

    Then add the following bit of text:
    Code:
    startup_message off
    shell -bash
    caption always “%{Gb}%3n %t %=[%l | %H | %c]”
    
    The caption line gives a nice colored status bar that shows which screen window is currently visible along with some other useful information like hostname, time, and load average.

    My "startcb.sh" script looks like this (which starts CraftBukkit in detached mode)

    Code:
    #!/bin/sh
    CBDIR="/opt/craftbukkit"
    CD ${CBDIR}
    screen -d -m java -d64 -Xincgc -Xmx2048M -jar ${CBDIR}/craftbukkit.jar nogui
    
     
  4. Offline

    LHammonds

    Starting a Bukkit server using the "screen" command via crontab seems to present a problem for me and I have not found out a way to resolve it yet.

    When the server is shutdown, rebooted and then crontab starts the Bukkit server up using the screen utility, it doesn't appear to actually complete the load. When trying to connect via the Minecraft client, it cannot find the server and appears offline. When I connect to the server, I run the "screen -r" command to access the detached console. It is initially black (assuming it is acting like a screen saver mode), I press any key and the console is immediately shown. I can then connect via the Minecraft client without having to do anything else other than the initial re-attachment of the detached session that crontab started.

    Re-attaching to the console did not simply start the console because it already had the Bukkit server started and all plugins were loaded.

    I don't know what re-attaching to the session does that allows it to start working again but it certainly does not work as an automated recovery process after the server reboots.

    Oh, I might also add that if I detach from the screen session by pressing CTRL+A and the "d", the Bukkit server is still running and Minecraft clients can still attach....until the next reboot.

    Anyone else run into this problem and know how to fix it?

    LHammonds
     
  5. Offline

    LHammonds

    Resolved. There were about 9 patches I applied to Ubuntu using the "aptitude safe-upgrade" and one of the patches was to crontab. The Minecraft server started just fine in a screen session after the upgrade and reboot without changing anything else.

    In case anyone is interested, here is exactly what my scripts look like:


    crontab file:
    Code:
    0 3,15 * * * /opt/craftbukkit/startcb.sh
    57 2,14 * * * reboot
    /opt/craftbukkit/startcb.sh
    Code:
    #!/bin/sh
    
    CBDIR="/opt/craftbukkit"
    cd ${CBDIR}
    
    ## Backup Minecraft
    ${CBDIR}/backupcb.sh
    
    ## Startup Minecraft
    screen -d -m java -d64 -Xincgc -Xmx2048M -jar ${CBDIR}/craftbukkit.jar nogui
    
    /opt/craftbukkit/backupcb.sh
    Code:
    #!/bin/bash
    ## Requires: 7-Zip (aptitude install p7zip-full)
    TEMPDIR="/tmp"
    CBDIR="/opt/craftbukkit"
    SHAREDIR="/srv/samba/share"
    ARCHIVEFILE="`date +%Y-%m-%d-%H-%M`_craftbukkit-backup.tar.7z"
    tar -cpf - ${CBDIR} | 7za a -si -mx=9 -w${TEMPDIR} ${TEMPDIR}/${ARCHIVEFILE} 1>/dev/null 2>&1
    mv ${TEMPDIR}/${ARCHIVEFILE} ${SHAREDIR}/.
    
    NOTE: The backup creates a TAR file to preserve group/ownership and is then compressed using 7-Zip with maximum compression enabled. It then copies it to a Samba share so I can copy them from my Windows PCs.

    LHammonds
     
Thread Status:
Not open for further replies.

Share This Page