So, I've been running a server for my kids at minecraftpe.secret.be for a few weeks now and I thought I'd share some of my experiences... Server is running on Amazon AWS and is costing round $40 a month. First things first, I wanted pocketmine to run as a service. So I created a service controller in /etc/init.d/minecraftpe Code: #!/bin/sh . /etc/rc.d/init.d/functions DAEMON="/minecraftDirectory/pe/" SCRIPT="./start.sh" LOG_FILE="/minecraftDirectory/pe/daemon.log" USER="minecraft" LOCK_FILE="/minecraftDirectory/pe/minecraftPE.Locked" do_start() { if [ ! -f "$LOCK_FILE" ] ; then echo -n $"Starting $SERVER: " runuser -l "$USER" -c "$DAEMON$SCRIPT >> $LOG_FILE &" && echo_success || echo_failure RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCK_FILE else echo "$SERVER is locked." RETVAL=1 fi } do_stop() { echo -n $"Stopping $SERVER: " #pid=`ps -aefw | grep "$DAEMON$Script" | grep -v " grep " | awk '{print $2}'` pid=`ps -u minecraft | grep "php" | grep -v " grep " | awk '{print $1}'` kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE } case "$1" in start) do_start ;; stop) do_stop ;; restart) do_stop do_start ;; *) echo "Usage: $0 {start|stop|restart}" RETVAL=1 esac exit $RETVAL This gives me the ability to start the server from a console by typing service minecraftpe start My setup is a bit extreme - in that I've got a load of plugins installed Plugins (14): PurePerms v1.0.8, VoteReward v2.1, WorldGM v3, BanItem v2.1, SignPortal v1.1.2, EssentialsPE v1.0.2, Whois v2.0.3, CommandSigns v2, Pundler v1.3, ChatCensor v1.4, ServerMail v0.0.2, iProtector v3.0, PocketGuard v2.1.1, SimpleAuth v1.6.0 Some of which are nowhere near actually being setup (lol) and this seems to cause quite a lot of stability problems. So I restart the server every 4 hours using a cron task - configured using crontab -e 0 */6 * * * /bin/sh /minecraftDirectory/rebootServer.sh Code: #!/bin/bash echo "Server reboot at $(date)" >> /minecraftDirectory/srvChk.log /minecraftDirectory/rcon/./mcrcon -P 19132 -H 127.0.0.1 -p MYPASSWORD "broadcast Server scheduled reboot in 10 seconds" sleep 7 /minecraftDirectory/rcon/./mcrcon -P 19132 -H 127.0.0.1 -p MYPASSWORD "broadcast Server scheduled reboot in 3 seconds"i sleep 3 /minecraftDirectory/rcon/./mcrcon -P 19132 -H 127.0.0.1 -p MYPASSWORD "broadcast Server scheduled reboot in NOW" /etc/init.d/minecraftpe stop echo "Stopped at $(date)" >> /minecraftDirectory/srvChk.log sleep 10 rm -r -f /minecraftDirectory/pe/minecraftPE.Locked echo "log removed at $(date)" >> /minecraftDirectory/srvChk.log /etc/init.d/minecraftpe start echo "Restart complete at $(date)" >> /minecraftDirectory/srvChk.log I also use git to keep an hourly backup of every single change to the server and its worlds - mostly as an anti-griefer step. I can literally roll the server back to any point in time. 0 * * * * cd /minecraftDirectory/ && sh autoCommit.sh Code: #!/bin/sh echo Begin Autocommit >> /minecraftDirectory/autocommit.log date >> /minecraftDirectory/autocommit.log git add --a >> /minecraftDirectory/autocommit.log git commit -m 'autocommit!' >> /minecraftDirectory/autocommit.log git push origin master --force >> /minecraftDirectory/autocommit.log echo DONE >> /minecraftDirectory/autocommit.log Finally, I also check for CrashDump files every minute and if I detect one I restart the server and delete the CrashDump. * * * * * cd /minecraftDirectory/ && sh checkServer.sh Code: #!/bin/bash if ls /minecraftDirectory/pe/Crash* 1> /dev/null 2>&1; then now="$(date)" echo "Current date and time %s\n" "$now" >> srvChk.log echo "crash log files found" >> srvChk.log /etc/init.d/minecraftpe stop >> srvChk.log rm -f /minecraftDirectory/pe/minecraftPE.Locked >> srvChk.log /etc/init.d/minecraftpe start >> srvChk.log rm -f /minecraftDirectory/pe/Crash* >> srvChk.log echo "restart server" >> srvChk.log fi Hope this post is useful to somebody.... D
So the server should work without SSH? I'm asking because I want my server working but my PC is very noisy and it's in my sleeping room. When I close SSH connection server closes up and I can't connect.
It needs to run as a service. If you just ./start.sh then it's running in your session and being killed when your session ends
I'm new to Linux so I'm wondering how to do the restart every four hours. Where would I put that script. I'm using Ubuntu.
Actually you just need to run `./start.sh -l` rather than `./start.sh` when you start the server. @iJoshuaHD has made an AutoServerRestarter (ASR) for auto restarting. He has also made a script for Ubuntu with screens installed, where the Stopping other threads bug is alleviated.
I just don't like how ASR broadcasts messages every minute and you can't restart it longer than an hour.
I'm pretty sure that crontab -e will work on Ubuntu although I've not tested this. you'll need to ensure that the cron service is running too. Try a quick google search for crontab Ubuntu and I'm sure you'll get better answers than I have
If it helps, I'm now sharing these scripts via https://bitbucket.org/davecozens/pocketminescripts feel free to steal/clone/read/etc
Easiest way is to copy the url of the scripts and then wget them onto your linux server. There's inline instructions in the original post at the top. I'll try and do an end to end tutorial later...
ill add an option to disable broadcast messages soon. and regarding cant restart longer than an hour, its a security feature because its not advised to run your server longer than that unless you know what you are doing. if you know what you are doing, just edit the config file generated by ASR and edit there by yourself.
I just edited ASR by deleting the broadcast messages every minute and only made it broadcast 30 seconds, 10 seconds, and so on.
you can use 'screen' if you run PM on ssh, and wide your screen, then exit your ssh. your server isnt turn off again if you exit your ssh