Talk:Tutorials/Server startup script

Is the server updater working for anyone? I remember trying it a couple of times and it not working. Nosrepa 08:20, 19 May 2011 (UTC) ~

Confirmed, it doesn't work "as is".

I made the following tweaks : mc_update { if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null then echo "$SERVICE is running! Will not start update." else MC_SERVER_URL=http://www.minecraft.net/download/minecraft_server.jar as_user "cd $MCPATH && wget -q -O $MCPATH/minecraft_server.jar.update $MC_SERVER_URL --no-check-certificate" if [ -f $MCPATH/minecraft_server.jar.update ] then if `diff $MCPATH/$SERVICE $MCPATH/minecraft_server.jar.update >/dev/null` then echo "You are already running the latest version of $SERVICE." else as_user "cp $MCPATH/minecraft_server.jar.update $MCPATH/$SERVICE" echo "Minecraft successfully updated." fi   else echo "Minecraft update could not be downloaded." fi   as_user "rm $MCPATH/minecraft_server.jar.update" fi } Modifications : SeigneurAo 13:09, 6 September 2011 (UTC)
 * deletion of the "v=" attribute in the URL, which is basically useless
 * addition of the -no-check-certificate switch for wget, since some servers (mine, for instance) don't handle Amazon's SSL certificate
 * removal of minecraft_server.jar.update afterwards, whatever the update did

Anyone have any experience setting this script up? I'm having trouble getting it to work on a Linode running Ubuntu 10.4.

The problem seems to be sending a command to screen. Even if I create the screen first, then detach it, I can't send a command to it. The only way to start the server is to attach to the screen and run the command from there, then detach to get back to my main session.

I can still send commands to the screen after the server is running, though. It's really odd. Any input on this would be great, and I can provide any additional info as well.

Thanks

You're encountering this bug: http://savannah.gnu.org/bugs/?25813 If you compile a version of screen from head it should work. Riff Zifnab 21:16, 28 May 2011 (UTC)

Works fine for me. Only problem is that it only takes 6 backups total per day and then stops working. --Barely 22:33, 26 April 2011 (UTC)

Untested, but it appears the reason why it only allows 6 backups is becasue of for i in 1 2 3 4 5 6 When the code sees the "world_YYYYMMDD-#"backup with the same date and a trailing 6, it continues through the for loop. Since the for loop only goes up to 6, the for loop is over at that point, so nothing is done.

A better (not the best) way to do this is to figure out how many backups you plan on running in a day ( every 30 minutes would be 24 per day). Replace the above text with... for i in $(seq 24) There are two occurrences in the script. Again, this is untested, so backup your script! --Ischwarz3 20:17, 27 April 2011 (UTC)

---

Thanks for the reply. I looked into the script myself without checking here, and figured I would take about 50 backups per day. I actually changed that line to this:

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

It works fine now. It doesn't stop at 6 backups a day like before, and I'm in the 20s already so it seems to work. It doesn't backup the jar though, but I could care less about the .jar. I could live with taking just one a day, in my opinion the jar backup isn't needed.

I'm sure there's a better way to do that :P However I don't really know too much about bash, let alone unix coding. Also, backups every 30 minutes would be 48 backups, not 24. ;)

I'm going to setup a cronjob to tar all of the backups for the day into one file. This will make archiving easier, because each backup is ~20 MBs. The only problem is deleting the old, untarred backups. I'd probably run the script at midnight. (well, 2 minutes after. Backups are on the hour, every hour now.)

Thanks!

--Barely 02:51, 28 April 2011 (UTC)

---

I've been working on my modified backup script. It uses rsync and an efficient method rotation. I will explain how it works if you are interested.

mc_backup { echo "Backing up minecraft world" date=`date "+%Y-%m-%dT%H:%M:%S"` as_user "rsync -aP --link-dest=$BACKUPPATH/current $MCPATH $BACKUPPATH/back-$date" as_user "rm -f $BACKUPPATH/current" as_user "ln -s $BACKUPPATH/back-$date $BACKUPPATH/current" echo "Backup complete"

#backup rotation toKeep=200 everyN=4 toDelete=$(($toKeep/10)) if (( `ls -1 $BACKUPPATH | wc -l` > $toKeep)); then let count=0 for folder in `ls $BACKUPPATH` ; do     let count=$count+1 if (( $count < $((toDelete*everyN)) )) ; then let modulus=$count%$everyN if [ $modulus -eq 2 ] ; then rm -r $BACKUPPATH/$folder echo $folder fi     fi    done fi }

--Chrisbay90 10:38, 4 July 2011 (UTC)

Graceful shutdown
Has anyone tested this script in an external shutdown situation, where gracefully stopping the minecraft server is crucial?

In my testing, the script appears to run on e.g. 'shutdown -h now', but by the time that happens, the screen and java processes have already been killed. Using Debian 6 so installed it with 'insserv minecraft' which seems to be the preferred method now, as opposed to update-rc.d. In /etc/rc0.d for example, there's a K01minecraft symlink, which comes before K02sendsigs, so all seems right?

Really nifty script works perfectly for me. One thing that bothers me is that when I try to send commands to the screen session the same way this script does I get a permission denied. I've turned on correct settings in .screenrc. addacl www-data multiuser on I can -r into the session as the www-data user but sending commands seems to be another story. Googling on the subject gives some results on people asking the same question as me. So I was thinking maybe someone from the source of the script might be interfacing with minecraft from the webserver. --Husse 08:59, 20 June 2011 (UTC)