Skip to content

Instantly share code, notes, and snippets.

@hacst
Created January 15, 2012 08:27
Show Gist options
  • Save hacst/1615062 to your computer and use it in GitHub Desktop.
Save hacst/1615062 to your computer and use it in GitHub Desktop.
Automatic update and restart shell scripts for rotc servers
Automatic updates and restarts for an rotc server
=================================================
1) Create an rotc user on your server (home: /home/rotc/)
2) Checkout rotc using git to /home/rotc/rotc/
3) Place these two scripts into the /home/rotc/rotc/ folder (and adjust them)
4) Adjust runme.sh:
* Make the -srv variable point to your server configuration.
* If you don't intend to run the script as root remove the sudo's inside.
If you run as root make sure the runme.sh script isn't editable by anyone else).
5) Call runme.sh inside a screen session
6) Edit the contab for the rotc user (contrab -u rotc -e) and add the update script. For example for an update check every 10 minutes:
*/10 * * * * /home/rotc/rotc/up
7) Done
If your server reboots you will have to call runme.sh to bring the server up again (an init script might be a good idea but I was too lazy to write one ;-) ).
#!/bin/sh
while [ 1 ]
do
while [ -f .updateinprogress ]
do
echo "Update in progress, waiting..."
sleep 5
done
echo "Restarting in 4 seconds, CTRL-C to abort"
sleep 4
sudo -H -u rotc ./rotc.bin -dedicated -srv game/server/dbclan.de.srv
#sudo -H -u rotc ./rotcd.bin -dedicated -src game/server/dbclan.de.srv
#mv /home/rotc/.rotc-ethernet/p.3-dev/console.log /home/rotc/logs/`date +"%F-%X"`-console.log
done
#!/bin/sh
cd /home/rotc/rotc/
here=$(git for-each-ref --format="%(objectname)" refs/remotes/origin/master)
there=$(git ls-remote origin refs/heads/master | cut -f1)
len=${#there}
if [ "$len" -ne 40 ]
then
echo Remote host did not return proper rev id: $there
exit 1
fi
if [ "$here" != "$there" ]
then
echo Update needed, local version $here, remote $there
touch .updateinprogress
killall rotc.bin
sleep 1
git reset HEAD --hard
git pull
chmod +x rotc.bin
rm .updateinprogress
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment