#!/bin/bash ################################################################################ # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Unless you change the below variables, this script assumes: # * Only one instance of hlds is being run # * hlds is installed in /usr/local/hlds/ # * The Linux user "cs" exists # * The Linux user "cs" owns /usr/local/hlds/ # * hlds_startup.sh exists in /home/cs/ # This script won't kill steam (run automatically when -autoupdate is specified) ################################################################################ . /lib/lsb/init-functions ##### You can change these variables ##### # If you're not running Debian/Ubuntu, the next line may need to be changed ID=/usr/bin/id; HLDS_PATH=/usr/local/hlds; HLDS_PID=hlds.pid; HLDS_USER=cs; ##### Don't change anything below here ##### start_hlds() { log_action_begin_msg "Starting hlds" #Make sure old hlds isn't running because they fight for same ip:port killall -q hlds_run if [ -f $HLDS_PATH/$HLDS_PID ] && [ -r $HLDS_PATH/$HLDS_PID ]; then read hpid < $HLDS_PATH/$HLDS_PID kill -TERM $hpid >/dev/null 2>&1 fi #Allow full core dumps for debugging purposes ulimit -c unlimited #Run as correct user if [ "`$ID -u`" == "0" ]; then # stdout and stderr to /dev/null su - $HLDS_USER -c /home/$HLDS_USER/hlds_startup.sh >/dev/null 2>&1 else /home/$HLDS_USER/hlds_startup.sh >/dev/null 2>&1 fi log_action_end_msg $? } stop_hlds() { log_action_begin_msg "Stopping hlds_run" killall -q hlds_run log_action_end_msg $? log_action_begin_msg "Stopping steam" killall -q steam log_action_end_msg $? log_action_begin_msg "Stopping hlds" if [ ! -f $HLDS_PATH/$HLDS_PID ]; then log_action_end_msg 1 # Fail log_failure_msg "$HLDS_PID not found. (Are you sure hlds is running?)" return elif [ ! -r $HLDS_PATH/$HLDS_PID ]; then log_action_end_msg 1 # Fail log_failure_msg "Unable to read $HLDS_PID. (Are you the correct user?)" return fi read hpid < $HLDS_PATH/$HLDS_PID kill -TERM $hpid >/dev/null 2>&1 log_action_end_msg $? if [ ! -f /proc/$hpid/exe ]; then # If not running, rm -f $HLDS_PATH/$HLDS_PID # Delete the pid file fi } case "$1" in start) start_hlds ;; stop) stop_hlds ;; restart) stop_hlds log_action_begin_msg "Sleeping" sleep 2 log_action_end_msg $? start_hlds ;; *) echo "usage: $0 {start|stop|restart}" esac