RedHat init script

Paul Holcomb bf1942-linuxserver at blue.cpoint.net
Thu Feb 6 16:09:12 EST 2003


I made a quick init script the other day to start and stop the bf1942
server automatically at boot and to provide an easy way to restart the
server when changes were made.  And since I saw a number of posts
about how to start the server and about nice'ing it afterwords I
thought I'd sent it out.

Things to keep in mind:

-the scripts expects to run as user "bf1942".  If you don't have such
 a user, create one.
-the script expects the game to be run from
 /bf1942/bf1942-lnxded-1.2beta1, but this location as well as the
 where the log goes to are easily changed by editing the variables at
 the top of the file.
-all arguments passed to the server go in /etc/sysconfig/bf1942 in the
 $ARGS variable.
 (e.g. ARGS="+game Desert_Combat" could be such a line)
-I didn't spend a lot of time on it, so its not perfect, but it does
 work for me.


-- 
Paul Holcomb                               *pholcomb    \@      cpoint  net*
Sr. Network Engineer                       Counterpoint Networking, Inc.
-------------- next part --------------
#!/bin/bash
#
# bf1942      This shell script takes care of starting and stopping
#               bf1942.
#
# chkconfig: 3 90 10
# description: bf1942 game 
# processname: bf1942_lnxded
# pidfile: /var/run/bf1942.pid
# 
# $Id: bf1942,v 1.7 2003/02/07 05:05:43 root Exp $
#
# Copyright (C) 2003 Paul Holcomb
#   <pholcomb at cpoint.net>, http://www.cpoint.net
#
# 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.
# http://www.gnu.org/copyleft/gpl.html
#
 

PROG_DIR=/bf1942/bf1942-lnxded-1.2beta1
PROG=bf1942_lnxded
LOG=/tmp/bf1942
PIDFILE=/var/run/bf1942.pid

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

# Source networking configuration.
. /etc/sysconfig/network

# Source bf1942 configureation.
if [ -f /etc/sysconfig/bf1942 ] ; then
	. /etc/sysconfig/bf1942
fi

# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0

[ -x ${PROG_DIR}/${PROG} ] || exit 0

RETVAL=0
prog="bf1942"

start() {
	# Start daemons.

	echo -n $"Starting $prog: "
	daemon -19 "su bf1942 -c \"(cd $PROG_DIR; ./$PROG $ARGS > $LOG 2>&1 &)\""
	RETVAL=$?
	#make sure we get the pid
	sleep 2
	pidof $PROG > $PIDFILE
	renice -19 $(head -1 $PIDFILE) > /dev/null 2>&1
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/bf1942
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n $"Shutting down $prog: "
	killproc $PROG
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/bf1942
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $RETVAL


More information about the Bf1942 mailing list