You are not logged in.
Pages: 1
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
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
Thanks man, the script is nice and simple
What's the best way to run that Java command as a user from the daemon script?
Offline
I just made this for Dropbox (another daemon I needed
#!/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
Last edited by maxexcloo (2010-10-22 22:45:21)
Offline
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
Perhaps you would want to not use dropbox at all, and use scp or rsync, depending on your needs.
Offline
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
Pages: 1