Thursday, July 24, 2014

Quake II - Amazon Linux Server: Q2R1 init.d Script

About a month ago, I was asked about the current status of my Quake 2 server. Having not checked on it in some time, I check the status and find that it is down.

I start the server again using the command mentioned in this older post, closed the terminal, and thought all was well. The next day I go to check on it again, and it's down. Every time I closed the terminal window, the server stopped. This was not a problem before, and the only thing I can figure is that some recent Amazon Linux security update is now preventing my old command from running in the background. Time to write a proper init.d script.


 I actually had an one laying around I had tried making months back, but couldn't get to work. It only needed a couple of typo fixes. After adding the script to init.d and firing the command quake2-server start, the server continues to run after closing the window and is still running as of this post. Here is a working init.d script for running R1ch's Enhanced Quake 2 server on Amazon Linux as a service:

#!/bin/sh
#
# quake2-server:       Starts the Q2R1 dedicated Quake2 Server
#
# Version:      @(#) /etc/init.d/quake2-server 1
#
# chkconfig: 2345 20 10
# description: Starts and stops the Quake2 Server at boot time and shutdown.
#
# processname: quake2-server


# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
  start)
        printf "Starting Quake2 Server: "
        cd /home/ec2-user/quake2/ && ./r1q2ded +set rcon_password '<PutYourPassFromServerCfgHere>' +set game lit                 hium +exec server.cfg > /dev/null >&1&
        echo
        ;;
  stop)
        printf "Shutting down Quake2 Server: "
        killproc r1q2ded
        rm -f /var/lock/subsys/quake2-server
        echo
        ;;
  status)
        status quake2-server
        ;;
  *)
        printf "*** Usage: quake2-server {start|stop|status}\n"
        exit 1
esac

exit 0


I hope someone else finds a use for this. If you are and would like some assistance or have any suggestions, please leave a comment.