Skip to content

Instantly share code, notes, and snippets.

@Soulflare3
Created August 19, 2015 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soulflare3/eb7f1c9c8ea6f6467ec2 to your computer and use it in GitHub Desktop.
Save Soulflare3/eb7f1c9c8ea6f6467ec2 to your computer and use it in GitHub Desktop.
hmh_bot management scripts | These are all the scripts I use to run hmh_bot for http://twitch.tv/handmade_hero

update.sh - is the main "startup" script. It simply tells the bot to run a backup, check for updates via git, and then start

backup.sh - does what it says on the tin. It backs up all .db and .cfg files (the only important files, the rest can be re-obtained via git). I also have this line in crontab for it: @daily /home/backup.sh >/home/logs/hmhbackup.log 2>/home/logs/hmhbackuperror.log so backup.sh runs whenever the bot gets updated, as well as once a day. I have not yet set a limit on how many backups to retain.

willie.sh - This is a heavily modified script that I've had for a few years, and it's sort of "evolved" as requirements appeared. I never really added "graceful" stopping. As of now it makes sure python has permission to read and write to the db (perms overkill, I was lazy) and then starts 2 copies of willie, first making sure their previous copies are no longer running.

startwillie.sh startwilliequake.sh

  • Two nearly identical files, simply to launch willie as a non-root user, using separate config files.
#! /bin/bash
echo Backing up HMH_bot
today=$(date +%Y-%m-%d);
time=$(date +%k%M);
backupfolder="/home/backups/hmhbot/$today/$time"
set -f
backupfolder=$(printf '%s' $backupfolder)
set +f
# http://stackoverflow.com/a/13661348
mkdir -p $backupfolder
chmod 777 $backupfolder
cd /home/ChronalRobot/
cp -v *.cfg -b -t $backupfolder
cp -v *.db -b -t $backupfolder
sudo -H -u noroot willie -c /home/ChronalRobot/handmade.cfg
sudo -H -u noroot willie -c /home/ChronalRobot/handmadequakenet.cfg
#! /bin/sh
bash /home/backup.sh
cd /home/ChronalRobot && git pull
sh /home/willie.sh start
#! /bin/sh
#test -f willie || exit 0
file=/home/ChronalRobot/handmade.db
case "$1" in
start)
echo "Stopping running copies of Willie, if applicable"
screen -R willie -X quit
screen -R hmhquakenet -X quit
echo "pkilling willie (in case something went wrong)"
pkill -x willie
echo "Setting permissions"
sudo chmod 777 /home/ChronalRobot/handmade.db
echo "Starting Willie"
screen -dmS willie sh /home/scripts/startwillie.sh
echo "Willie Twitch started"
screen -dmS hmhquakenet sh /home/scripts/startwilliequake.sh
echo "Willie Quakenet started"
echo "Done"
exit 1
;;
stop)
echo "Stopping running copies of Willie, if applicable"
screen -R willie -X quit
screen -R hmhquakenet -X quit
echo "pkilling willie (in case something went wrong)"
pkill -x willie
exit 1
;;
*)
echo "Usage: willie.sh start|stop"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment