You are not logged in.

#1 2010-10-22 13:55:33

maxexcloo
Member
Registered: 2009-10-14
Posts: 177

Minecraft Server Daemon

Hey everyone,
Is it possible to make a daemon for the Minecraft server?
I am currently running the server using nohup and backgrounding and have found it to be a bit of a hack in terms of system integration and ease of use.
To start the server you have to be logged in to a terminal and then have to execute a command simular to this:

java -Xms1024M -Xmx1024M -jar minecraft_mod.jar nogui

If anyone can help out, it would be awesome. Thanks!

Offline

#2 2010-10-22 16:03:07

sctincman
Member
From: CO (USA)
Registered: 2009-04-08
Posts: 85

Re: Minecraft Server Daemon

Perhaps just create your own daemon/init script in /etc/rc.d? Put the necessary commands in the start/stop cases. Wicd's script seems like it might be simple enough to use as a starting point

Offline

#3 2010-10-22 22:31:08

maxexcloo
Member
Registered: 2009-10-14
Posts: 177

Re: Minecraft Server Daemon

Thanks man, the script is nice and simple smile
What's the best way to run that Java command as a user from the daemon script?

Offline

#4 2010-10-22 22:40:42

maxexcloo
Member
Registered: 2009-10-14
Posts: 177

Re: Minecraft Server Daemon

I just made this for Dropbox (another daemon I needed tongue

#!/bin/bash

name=Dropbox
user=main
sname=dropboxd
process=dropbox
command=dropboxd

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
    start)
        stat_busy "Starting $name Daemon"
        su -c "$command &" $user &> /dev/null
        add_daemon $sname
        stat_done
        ;;
    stop)
        stat_busy "Stopping $name Daemon"
        pkill -f $process &> /dev/null
        rm_daemon $sname
        stat_done
        ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        echo "usage: $0 {start|stop|restart}"
esac
exit 0

EDIT: Fixed a problem tongue

Last edited by maxexcloo (2010-10-22 22:45:21)

Offline

#5 2010-10-22 23:48:14

maxexcloo
Member
Registered: 2009-10-14
Posts: 177

Re: Minecraft Server Daemon

This is the script I want to execute when the daemon is started:

#!/bin/bash
# Starts Minecraft Server, performs backups and creates maps.

# Set Interval
interval="7200"

while true
do
    # Root Directory
    cd ~

    # Time Variables
    backup=~/Backups/$(date +"%Y-%m-%d-%H:%M").zip
    map=~/Maps/$(date +"%Y-%m-%d-%H:%M").png

    # Start Minecraft
    if pidof java >/dev/null;
    then
        echo -e "\033[1m>>> Server Status:\033[0m"
        echo Server is online!
    else
        cd ~/Server
        (nohup java -Xms1024M -Xmx1024M -jar minecraft_mod.jar nogui 2> /dev/null > /dev/null &)2> /dev/null > /dev/null
        echo -e "\033[1m>>> Server Status:\033[0m"
        echo Server was started!
    fi
    echo

    # Backup Server
    echo -e "\033[1m>>> Backup Started...\033[0m"
    cd ~/Server
    zip -r $backup . >/dev/null
    rm -rf ~/Dropbox/Minecraft/Current.zip
    cp $backup ~/Dropbox/Minecraft/Current.zip
    echo Done!
    echo

    # Map Server
    echo -e "\033[1m>>> Creating Map...\033[0m"
    ~/Scripts/C10T -w ~/Server/world/ -o $map >/dev/null
    rm -rf ~/Dropbox/Minecraft/Maps/$(date +"%Y-%m-%d").png
    cp $map ~/Dropbox/Minecraft/Maps/$(date +"%Y-%m-%d").png
    rm -rf ~/Dropbox/Minecraft/Maps/Current.png
    cp $map ~/Dropbox/Minecraft/Maps/Current.png
    echo Done!
    echo

    # Wait Interval
    echo -e "\033[1m>>> Waiting...\033[0m"
    sleep $interval
    echo Done!
    echo
done

And this is what I want to do when it's stopped:

#!/bin/bash
killall java
killall Start.sh
rm -rf nohup.out

Right now I start it by logging in an issuing this command:

nohup Scripts/Start.sh & 2> /dev/null > /dev/null

Offline

#6 2010-10-22 23:55:35

Shmexalicious
Member
Registered: 2010-07-31
Posts: 2

Re: Minecraft Server Daemon

Perhaps you would want to not use dropbox at all, and use scp or rsync, depending on your needs.

Offline

#7 2010-10-24 00:25:40

sctincman
Member
From: CO (USA)
Registered: 2009-04-08
Posts: 85

Re: Minecraft Server Daemon

looks that might work, have the start case call your start.sh script, and stop kill the processes. I wonder if the server has a better way to stop itself though

Also, I don't think you'd nohup, as the initscript should background it for you

Offline

Board footer

Powered by FluxBB