Skip to content

Instantly share code, notes, and snippets.

@A-xis
Last active November 26, 2015 03:25
Show Gist options
  • Save A-xis/f7af9fea81af664b6926 to your computer and use it in GitHub Desktop.
Save A-xis/f7af9fea81af664b6926 to your computer and use it in GitHub Desktop.
Init script for mixmaster
#!/bin/bash
#
# /etc/rc.d/init.d/mixmaster
#
# Start/Stop mixmaster server
#
# chkconfig: 2345 80 20
# description: mixmaster is a game server
# processname: 1
# processname: 2
# processname: 3
# pidfile: /var/run/mixmaster.pid
### BEGIN INIT INFO
# Provides: mixmaster
# Required-Start: $remote_fs $syslog $httpd $mysqld
# Required-Stop: $remote_fs $syslog $httpd $mysqld
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop mixmaster server
### END INIT INFO
# Source function library.
. /etc/init.d/functions
set -e
PIDFILE=/var/run/mixmaster.pid
magenta=`tput setaf 5` # ${magenta}
cyan=`tput setaf 6` # ${cyan}
blue=`tput setaf 4` # ${blue}
green=`tput setaf 2` # ${green}
red=`tput setaf 1` # ${red}
nocolor=`tput sgr0` # ${nocolor}
start() {
if [ `pidof ./{1,2,3}|wc -w` != 0 ]; then
echo "${red}Error${nocolor}: mixmaster is still running. You can use ${cyan}/etc/init.d/mixmaster stop ${nocolor}to stop it, or ${cyan}/etc/init.d/mixmaster force-stop ${nocolor} to kill it if ${cyan}stop${nocolor} does not work."
exit 100
fi
echo "${magenta}Starting mixmaster:${nocolor}"
cd /home/server/lgs/ && ./1 &
cd /home/server/gms/ && ./2 &
cd /home/server/zs1/ && ./3 &
pidof ./{1,2,3} > $PIDFILE
exit 0
}
stop() {
echo "${magenta}Shutting down mixmaster:${nocolor}"
kill `cat $PIDFILE`
echo "" > $PIDFILE
if [ `pidof ./{1,2,3}|wc -w` > 0 ]; then
echo "${red}Error${nocolor}: mixmaster is still running. You can use ${cyan}/etc/init.d/mixmaster stop ${nocolor}to stop it, or ${cyan}/etc/init.d/mixmaster force-stop ${nocolor} to kill it if ${cyan}stop${nocolor} does not work."
exit 1
else
exit 0
fi
}
force-stop() {
echo "${red}Forcing shutting down mixmaster:${nocolor}"
kill -9 `pidof ./{1,2,3}`
echo "" > $PIDFILE
exit 0
}
status() {
echo "${magenta}Checking nb of process runnings for mixmaster:${nocolor}"
nbprocess=`pidof ./{1,2,3} | wc -w`
if [ $nbprocess != 3 ]; then
echo "${red}Error${nocolor}: bad number of process:${cyan}" $nbprocess ${nocolor}
exit 3
else
echo "${green}OK${nocolor}: found${cyan}" $nbprocess "${nocolor}process"
fi
echo "${magenta}Checking integrity of process runnings for mixmaster:${nocolor}"
grep "`pidof ./{1,2,3}`" $PIDFILE && echo "${green}Process integrity OK${nocolor}" || (echo "${red}Something went wrong. You should manually check this.${nocolor}" exit 3)
echo "${magenta}Checking process runnings for mixmaster:${nocolor}"
checkpid `cat $PIDFILE` && echo "${green}All process are runnings${nocolor}" || (echo "${red}Something went wrong. You should manually check this.${nocolor}" exit 3)
exit 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
force-stop|kill)
force-stop
;;
status)
status
;;
restart|reload)
stop
start
;;
*)
echo "Usage: /etc/init.d/mixmaster {start|stop|status|restart|force-stop"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment