Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # site settings
- BaseDir="/home/$USER/Server/Core"
- LogDir="$BaseDir/logs"
- AuthBin="$BaseDir/bin/authserver"
- AuthParm="--config $BaseDir/conf/authserver.conf"
- BNetBin="$BaseDir/bin/bnetserver"
- BNetparm="--config $BaseDir/conf/bnetserver.conf"
- WorldBin="$BaseDir/bin/worldserver"
- WorldParm="--config $BaseDir/conf/worldserver.conf"
- CheckBin="`which mysqlcheck`"
- SQLUser="trinity"
- SQLPass="trinity"
- SQL_DBs="auth characters"
- start_world () {
- PID=`pgrep -u $USER worldserver`
- if [ ! -n "$PID" ]; then
- "$WorldBin" "$WorldParm"
- RC=$?
- fi
- }
- norm_exit () {
- echo "Normal server exit"
- exit
- }
- err_exit () {
- # should actually do something useful here
- echo "`date '+%D %H:%M:%S'` Server error...restarting..." >> "$LogDir/crash.log"
- }
- invalid_exit () {
- echo "`date '+%D %H:%M:%S'` Invalid exit code ($RC)...restarting..." >> "$LogDir/invalid_exits.log"
- }
- maint_exit () {
- echo "`date '+%D %H:%M:%S'` --==Begin Weekly Maintenance==--" >> "$LogDir/maintenance.log"
- echo "`date '+%D %H:%M:%S'` Optimizing database(s)" >> "$LogDir/maintenance.log"
- "$CheckBin" -u$SQLUser -p$SQLPass -o --databases $SQL_DBs >> "$LogDir/maintenance.log"
- echo "`date '+%D %H:%M:%S'` Stopping authserver" >> "$LogDir/maintenance.log"
- PID=`pgrep -u $USER authserver`
- if [ -n "$PID" ]; then
- kill -INT `pgrep -u $USER authserver`
- sleep 4
- PID=`pgrep -u $USER authserver`
- if [ -n "$PID" ]; then
- kill -KILL `pgrep -u $USER authserver`
- sleep 1
- fi
- fi
- echo "`date '+%D %H:%M:%S'` Stopping bnetserver" >> "$LogDir/maintenance.log"
- PID=`pgrep -u $USER bnetserver`
- if [ -n "$PID" ]; then
- kill -INT `pgrep -u $USER bnetserver`
- sleep 4
- PID=`pgrep -u $USER bnetserver`
- if [ -n "$PID" ]; then
- kill -KILL `pgrep -u $USER bnetserver`
- sleep 1
- fi
- fi
- echo "`date '+%D %H:%M:%S'` Rotating log files" >> "$LogDir/maintenance.log"
- logrotate -s "$LogDir/rotate.status" "$BaseDir/conf/logrotate.conf"
- echo "`date '+%D %H:%M:%S'` Re-launching authserver" >> "$LogDir/maintenance.log"
- PID=`pgrep -f AuthServer`
- if [ ! -n "$PID" ]; then
- screen -a -d -m -t AuthServer "$AuthBin" "$AuthParm"
- fi
- echo "`date '+%D %H:%M:%S'` Re-launching bnetserver" >> "$LogDir/maintenance.log"
- PID=`pgrep -f BNetServer`
- if [ ! -n "$PID" ]; then
- screen -a -d -m -t BNetServer "$BNetBin" "$BNetParm"
- fi
- echo "`date '+%D %H:%M:%S'` --==End Weekly Maintenance==--" >> "$LogDir/maintenance.log"
- echo >> "$LogDir/maintenance.log"
- }
- while true
- do
- start_world
- case "$RC" in
- 0)
- norm_exit
- ;;
- 1)
- err_exit
- ;;
- 3)
- maint_exit
- ;;
- *)
- invalid_exit
- ;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement