Go Back   Steam Users' Forums > Dedicated Server Discussions > Half-Life DS (Linux)

Reply
 
Thread Tools Display Modes
Old 10-06-2004, 11:31 AM   #1
TripHammer
 
 
 
Join Date: Oct 2004
Reputation: 1
Posts: 580
Source Dedicated Server daemon script

I just finished putting some modification on a hlds startup script originally put togeher by:

Julien Escario (pandemik@asylog.net)
Cedric Rochat (crochat@younics.org)

It is now configured to work with source dedicated server including running the server as non-root and 'screen' support.

Code:
#! /bin/sh
#
# Start the Counter-Strike Source dedicated server as non-root.
#
# A modification of the CS Server startup script, to run the server
# as a non-root user. 
#
# ORIGINAL AUTHORS :
#
# Julien Escario (pandemik@asylog.net)
# &
# Cedric Rochat (crochat@younics.org)
#
# ===========================================
#
# What you need:
#
# Linux
# awk 
# screen
# srcds & cstrike-files OR
# 
# YES, this script works fine with fine with CS 1.6
# 
# How to use:
# 
# Edit the DIR-var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-var to fit your needs 
# Edit the CS_USER-var to the name of the user that will run the server
#
# How to see the server-console:
#
# Just type in: screen -r srcds (or whatever you set $NAME to)
# More info about screen can be found by typing "man screen"
#
# The easist way is to use this script simple as a start-script for your server
# If you want to use it as a script to start the server at boot-time:
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# (THIS IS FOR DEBIAN! If you use e.g. Redhat you must change these dirs!!!)
#
# ln -s /etc/init.d/hlds /etc/rc3.d/S90hlds
# ln -s /etc/init.d/hlds /etc/rc6.d/K50hlds
#
# Or use it manualy like: 
# /etc/rc.d/init.d/hlds start 
# /etc/rc.d/init.d/hlds stop 
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
# 
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)

# The user that will run the server
CS_USER=source

# Leave this alone.
NAME=srcds

PATH=/bin:/usr/bin:/sbin:/usr/sbin

# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/games/steam/source

# Leave this alone.
DAEMON=srcds_run

# Internet-server:
PARAMS="-game cstrike +map de_dust +maxplayers 16 -autoupdate"

# Leave this alone.
DESC="Counter-Strike Source Dedicated Server"

case "$1" in
 start)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo "$DESC is already running"
    else 
       echo "Starting $DESC: $NAME"
       su $CS_USER -c "cd $DIR; screen -m -d -S srcds ./$DAEMON $PARAMS"
    fi
    ;;

 stop)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo -n "Stopping $DESC: $NAME"
       kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
       echo " ... done."
    else
       echo "Coulnd't find a running $DESC"
    fi
    ;;

 restart)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo -n "Stopping $DESC: $NAME"
       kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
       echo " ... done."
    else
       echo "Coulnd't find a running $DESC"
    fi
   
    echo -n "Starting $DESC: $NAME"
    su $CS_USER -c "cd $DIR; screen -m -d -S srcds ./$DAEMON $PARAMS"
    echo " ... done."
    ;;

 status)
    ps aux | grep -v grep | grep srcds_r > /dev/null
    CHECK=$?
    [ $CHECK -eq 0 ] && echo "$DESC is UP" || echo "$DESC is DOWN"
    ;; 
 *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
    ;;
esac

exit 0
#edited#
Changed "-update" to "-autoupdate" sorry for the user error

Last edited by TripHammer: 10-15-2004 at 09:19 AM.
TripHammer is offline  
Reply With Quote
Old 10-15-2004, 12:07 AM   #2
parasite131184
 
Guest
Posts: n/a
thx works fine....

Nice work
  Reply With Quote
Old 10-15-2004, 06:24 AM   #3
Phalck
 
Guest
Posts: n/a
Great stuff!!

I will modify this script to put the IP number on the command line for those with dynamic IPs (to get rcon to work for everyone)

Here is my modification to this script:

Changed -update to -autoupdate
Added -binary to fix Fedora Core 1 bug not recognizing a Pentium III processor as a i686 processor. Remove if you like.

Code:
#! /bin/sh
#
# Start the Counter-Strike Source dedicated server as non-root.
#
# A modification of the CS Server startup script, to run the server
# as a non-root user.
#
# This version of the script have been modified to start servers
# with the +ip option even though the server has a dynamic IP
# number.
#
# Dynamic ip modification by:
# Mattias Falck (phalck@skormod.com)
#
# ORIGINAL AUTHORS :
#
# TripHammer
#
# Julien Escario (pandemik@asylog.net)
# &
# Cedric Rochat (crochat@younics.org)
#
# ===========================================
#
# What you need:
#
# Linux
# awk
# screen
# srcds & cstrike-files OR
#
# YES, this script works fine with CS 1.6
#
# How to use:
#
# Edit the DIR-var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-var to fit your needs
# Edit the CS_USER-var to the name of the user that will run the server
#
# How to see the server-console:
#
# Just type in: screen -r srcds (or whatever you set $NAME to)
# More info about screen can be found by typing "man screen"
#
# The easist way is to use this script simple as a start-script for your server
# If you want to use it as a script to start the server at boot-time:
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# (THIS IS FOR DEBIAN! If you use e.g. Redhat you must change these dirs!!!)
#
# ln -s /etc/init.d/hlds /etc/rc3.d/S90hlds
# ln -s /etc/init.d/hlds /etc/rc6.d/K50hlds
#
# Or use it manualy like:
# /etc/rc.d/init.d/hlds start
# /etc/rc.d/init.d/hlds stop
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
#
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)

# The user that will run the server
CS_USER=halflife

# Leave this alone.
NAME=srcds

PATH=/bin:/usr/bin:/sbin:/usr/sbin

# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/usr/steam/cssds

# Leave this alone.
DAEMON=srcds_run

# Internet-server:
# Static IP command line
# PARAMS="-game cstrike +map de_office +maxplayers 16 -autoupdate"

# Dynamic IP command line. Uncomment the one above OR the one below NOT both.
PARAMS="-game cstrike -binary ./srcds_i486 +map de_office +maxplayers 20 +ip $serverip -autoupdate"

# Leave this alone.
DESC="Counter-Strike Source Dedicated Server"

case "$1" in
 start)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo "$DESC is already running"
    else
       echo "Starting $DESC: $NAME"
       serverip="`ifconfig | grep -A 4 eth0 | awk ' /inet/ { print $2 } ' |  sed -e s/addr://`"
       su $CS_USER -c "cd $DIR; screen -m -d -S srcds ./$DAEMON $PARAMS"
    fi
    ;;

 stop)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo -n "Stopping $DESC: $NAME"
       kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
       echo " ... done."
    else
       echo "Coulnd't find a running $DESC"
    fi
    ;;

 restart)
    if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
       then
       echo -n "Stopping $DESC: $NAME"
       kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
       echo " ... done."
    else
       echo "Coulnd't find a running $DESC"
    fi

    echo -n "Starting $DESC: $NAME"
    serverip="`ifconfig | grep -A 4 eth0 | awk ' /inet/ { print $2 } ' |  sed -e s/addr://`"
    su $CS_USER -c "cd $DIR; screen -m -d -S srcds ./$DAEMON $PARAMS"
    echo " ... done."
    ;;

 status)
    ps aux | grep -v grep | grep srcds_r > /dev/null
    CHECK=$?
    [ $CHECK -eq 0 ] && echo "$DESC is UP" || echo "$DESC is DOWN"
    ;;
 *)
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
    ;;
esac

exit 0
/Phalck

Last edited by Phalck: 10-15-2004 at 07:12 AM.
  Reply With Quote
Old 10-15-2004, 07:19 AM   #4
parasite131184
 
Guest
Posts: n/a
i already done that but thx
  Reply With Quote
Old 12-04-2004, 11:24 AM   #5
null_bit
 
Guest
Posts: n/a
I find this thread very usefull - but I am new to linux and deian. I have a running deian system with hlds running without problems, but what is the syntax to create a non-root user?

Is there a small "cookbook" somewhere?

/nullbit
  Reply With Quote
Old 12-04-2004, 11:28 AM   #6
Phalck
 
Guest
Posts: n/a
You need a tutorial on how to add new users to a linux system. Any basic Linux tutorial site should have that. The only thing you then do is to put that newly created username on this line in the script:

# The user that will run the server
CS_USER=halflife

Done.

/Phalck
  Reply With Quote
Old 12-04-2004, 12:02 PM   #7
Điego-
 
Guest
Posts: n/a
adduser --help

chown --help

And it's Debian..


Đ
  Reply With Quote
Reply

Go Back   Steam Users' Forums > Dedicated Server Discussions > Half-Life DS (Linux)


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -7. The time now is 08:49 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site Content Copyright Valve Corporation 1998-2012, All Rights Reserved.