83 lines
5.8 KiB
Bash
83 lines
5.8 KiB
Bash
#!/bin/sh
|
|
. ./$1.conf
|
|
|
|
service_start() {
|
|
if [ ! -f $DSPATH/$DSNAME.pid ] && [ ! -f $DSPATH/$DSGAME/$DSNAME.pid ]; then
|
|
if [ -x $DSPATH/$DSENGINE ]; then
|
|
echo "$DSPATH/$DSENGINE $DSOPTS"
|
|
$DSINTERFACE $DSPATH/$DSENGINE $DSOPTS
|
|
sleep 1
|
|
#ps -ef | grep "$DSENGINE" | grep "$DSNAME" | grep -v grep | awk '{ print $2 }' > $DSNAME.pid
|
|
ps -ef | grep "srcds_linux" | grep -- "-pidfile $DSNAME.pid" | grep -v grep | awk '{ print $2 }' > $DSNAME.pid
|
|
echo "$DSENGINE process ID written to $DSNAME.pid"
|
|
fi
|
|
else
|
|
echo "Server is already running. Stop the server first, or use restart."
|
|
fi
|
|
}
|
|
|
|
service_stop() {
|
|
if screen -list | grep -q "\.$DSNAME"; then
|
|
echo "Stopping screen session: $DSNAME"
|
|
screen -S "$DSNAME" -X quit
|
|
sleep 1
|
|
fi
|
|
|
|
rm -f $DSPATH/$DSNAME.pid
|
|
rm -f $DSPATH/$DSGAME/$DSNAME.pid
|
|
screen -wipe 1> /dev/null 2> /dev/null
|
|
}
|
|
|
|
service_restart() {
|
|
service_stop
|
|
sleep 1
|
|
service_start
|
|
}
|
|
|
|
service_status() {
|
|
if [ -f $DSPATH/$DSNAME.pid ] && [ -f $DSPATH/$DSGAME/$DSNAME.pid ]; then
|
|
echo "$DSENGINE is running on process: `cat $DSPATH/$DSNAME.pid`"
|
|
else
|
|
echo "Server is offline."
|
|
fi
|
|
}
|
|
|
|
service_watch() {
|
|
if [ `screen -wipe | grep $DSNAME | grep -v grep | awk '{print $4}'` == '(Attached)' ]; then
|
|
echo "Someone is already attached to the console of the server."
|
|
else
|
|
script /dev/null & screen -r $DSNAME
|
|
fi
|
|
}
|
|
|
|
service_clean() {
|
|
rm -rf $DSPATH/*.pid
|
|
rm -rf $DSPATH/$DSGAME/*.pid
|
|
screen -wipe 1> /dev/null 2> /dev/null
|
|
}
|
|
|
|
case "$2" in
|
|
'start')
|
|
service_start
|
|
;;
|
|
'stop')
|
|
service_stop
|
|
;;
|
|
'restart')
|
|
service_restart
|
|
;;
|
|
'status')
|
|
service_status
|
|
;;
|
|
'watch')
|
|
service_watch
|
|
;;
|
|
'clean')
|
|
service_clean
|
|
;;
|
|
*)
|
|
echo "usage $0 start|stop|restart|status|watch|clean"
|
|
;;
|
|
esac;
|
|
|