SRCDS Steam group


Linux init script to start server on boot
#18
Nice script, but i'm trying to modify it so it will run as a user(su - srcds) but without any luck Sad
Could you give me a hand here?

Code:
#!/bin/sh
# Source Dedicated Server Init Script

# Server options
TITLE='SRCDS Startup' # Script initialization title
LONGNAME='Team Fortress 2 Server 1'        # Full title of game type
NAME='srcds-tf2-1'                          # Server handle for the screen session
DAEMON='srcds_run'                # The server daemon
STEAM='/home/srcds/srcds_tf2/orangebox'        # STEAM to Steam installation
USER='srcds'

# Game options
IP='192.168.10.14'                # IP of the server
PORT='27015'                    # Port number to
MAP='ctf_2fort'                    # Initial map to start
GAME='tf'                        # Game type (tf|cstrike|valve|hl2mp)
SIZE='24'                        # Maximum number of players

# Server options string
OPTS="-game $GAME  +map $MAP +ip $IP -port $PORT \
    -autoupdate +maxplayers $SIZE -pidfile $STEAM/$GAME/$NAME.pid"

# Screen command
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"

service_start() {
    # Check if the pid files currently exist
    if [ ! -f $STEAM/$GAME/$NAME.pid ] && [ ! -f $STEAM/$GAME/$NAME-screen.pid ]; then
        if [ -x $STEAM/$DAEMON ]; then
            echo "Starting $TITLE - $LONGNAME"
            echo "Server IP: $IP"
            echo "Server port: $PORT"
            echo "Server size: $SIZE players"
            sudo -u srcds /usr/bin/screen -A -d -m -S $NAME $STEAM/$DAEMON $OPTS
            # Prevent race condition on SMP kernels
             sleep 1
            # Find and write current process id of the screen process
            ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
            echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
            echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"

            echo "$TITLE started."
        fi
    else
        echo -e "Cannot start $TITLE.  Server is already running."
        #exit 1
    fi
}

service_stop() {
    if [ -f $STEAM/$GAME/$NAME.pid ] && [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
        echo "Stopping $TITLE - $LONGNAME."
        # Get the process ID from the pid file we created earlier
        for id in `cat $STEAM/$GAME/$NAME-screen.pid`
            do kill -9 $id
            echo "Killing process ID $id"
            echo "Removing $TITLE screen pid file"
            rm -rf $STEAM/$GAME/$NAME-screen.pid
            break
        done
        # Remove server pid file
        echo "Removing $TITLE pid file"
        rm -rf $STEAM/$GAME/$NAME.pid
        # Wipe all old screen sessions
        screen -wipe 1> /dev/null 2> /dev/null
        echo "$TITLE stopped."
    else
        echo -e "Cannot stop $TITLE.  Server is not running."
        #exit 1
    fi
}


case "$1" in
    'start')
        service_start
        ;;
    'stop')
        service_stop
        ;;
    'restart')
        service_stop
        sleep 1
        service_start
        ;;
    *)
        echo "Usage $0 start|stop|restart"
esac
Reply


Messages In This Thread
RE: Linux init script to start server on boot - Eternal Bliss - 12-21-2007, 10:43 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)