Skip to content

Instantly share code, notes, and snippets.

@bennet0496
Last active August 29, 2015 14:09
Show Gist options
  • Save bennet0496/e5a051db2124d8e7fb63 to your computer and use it in GitHub Desktop.
Save bennet0496/e5a051db2124d8e7fb63 to your computer and use it in GitHub Desktop.
SRCDS Wrapper
login anonymous
force_install_dir /home/valve-src/Half_Life2
app_update 232370 validate
quit
#!/bin/sh
### BEGIN INIT INFO
# Provides: hl2dmserver
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Hal-Life 2 server
# Description: Starts a Half-Life 2 server
### END INIT INFO
NAME="Half-Life 2: Deathmatch"
USER="valve-src"
SCREENREF="hl2mp_s1"
BINARYPATH="/home/valve-src/Half_Life2"
BINARYNAME="srcds_run"
PIDFILE="hl2.1.pid"
OPTS="-game hl2mp +maxplayers 32 +ip 1.2.3.4 -port 27015 +map dm_lockdown -autoupdate -steam_dir /home/valve-src/Half_Life2/ -steamcmd_script /home/valve-src/Half_Life2/hl2_ds.1.txt +sv_shutdown_timeout_minutes 5 -pingboost 3 -sys_ticrate 1001"
cd "$BINARYPATH"
running() {
if [ -n "`pgrep -f $SCREENREF`" ]; then
return 0
else
return 1
fi
}
start() {
if ! running; then
echo -n "Starting the $NAME server... "
su - $USER -c "nice -n 5 /usr/bin/screen -dmS $SCREENREF $BINARYPATH/$BINARYNAME $OPTS"
pgrep -f $SCREENREF > $PIDFILE
if [ -s $PIDFILE ]; then
echo "Done"
else
echo "Failed"
rm $PIDFILE
fi
else
echo "The $NAME server is already started."
fi
}
stop() {
if running; then
echo -n "Stopping the $NAME server... "
kill `cat $PIDFILE`
while running; do
sleep 1
done
rm $PIDFILE
echo "Done"
else
echo "The $NAME server is already stopped."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
if running; then
echo "The $NAME server is started."
else
echo "The $NAME server is stopped."
fi
;;
*)
echo "Usage: $0 (start|stop|restart|status)"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment