SRCDS Steam group

Kill Script ?
Does anyone know of a stop server script that can be executed to stop an instance of CS:S ?

I am using Webmin with Fedora Core4 and want to have a custom command to stop a server as well as start it. The start is simple as I can script out a ./, but stopping is another thing altogether since I dont know what the PID ID would be....

I want to allow people to access startign and stopping the server via webmin since I cant always be around....

this is going to sound like a shameless plug but here ya go none the less

This can be intergrated into webmin fairly easily. If you need assistance with it let me know via email on this forum and i will respond as soon as I get it.
first of all I would like to give much respect to bloodwraith for his script. I am using it right now and with a few modifications it works flawlessly. I simplified it a bit by condensing everything into one file and added a extra variable inorder to get it to work on my Debian 3.1 rc1 linux server with Counter Strike Source and as he stated before im sure it will work with my Call of Duty server that im about to setup! Thanks again bloodwraith! GJ sir!

Heres how I did it..

Quote:#First create a user in debian that you want to run your css server. useradd username

#next log in as that user NOTE: screen will not work if you are su'd #unless you ssh to localhost i.e.
ssh username@localhost

#Create a file called copy and paste the code below into #that file and modify to your liking. OR download the attachment if you dont like editing script files. NOTE: Because this page uses #line wrap the code below will need to be checked for that occurance. #'echo statements and comments all need to be on one line if possible, #etc.

# give the script permissions to be executed
chmod +rx-w ./

#start the server
# Credit for creation of this goes to BloodWraith @ I simply modified it a bit for
# debian 3.1 sarge and CounterStrike Source.
# This script is currently being managed as a Free (as in beer) script under no specific licensing.
# Start/stop/restart a Valve dedicated server
# All configuration changes should occur in <scriptname>.conf. Only change the name of the call below if you are using a different name for the script.
### Arcanum remarked this line out and added the conf file to this file for simplicity to me.
### Unremark it and the create the file and add the below info if you want it seperated as  bloodwraith intended
### ./startscript.conf

                CLIENT='csds';                  # This is going to be the name of your SCREEN session.
                                                # Unique handle this server uses. Hostname
                                                # can be reset in your server.cfg if you use one.

                TITLE='CSDS Script';            # Name that is shown during start-up messages
                DSPATH='/home/steam/csds';      # Where Steam is installed
                GDIR='cstrike';                 # Game Directory under steam directory
                DSIP='';            # IP address you want to use to start server with
                DSNAME='srcds_run';             # Either hlds_run or srcds_run
                DSNAMESHORT='source';           # Label only
                DSGAME='cstrike';               # Game type (valve, cstrike, czero, etc)
                DSIMAP='de_nuke';               # Load this map initially
                DSPORT='27015';                 # Game server listens on this UDP port
                DSSIZE='34';                    # Maximum number of players to allow
                DSUSER=`whoami`;                # Which user is running the process

# Don't edit this unless you need the script to do something special
# Don't edit this unless you need the script to do something special
# Don't edit this unless you need the script to do something special

DSOPTS="-game $DSGAME +map $DSIMAP -ip $DSIP -port $DSPORT -autoupdate +maxplayers $DSSIZE -pidfile $ -tickrate 66"

# This is the caller for the screen process. Only change if this is different from where your screen process currently resides.
DSINTERFACE="/usr/bin/screen -A -m -d -S $CLIENT"

### this is the end of the ./startscript.conf file that was added to this one.

service_start() {

# Checking to see if root is the current user you are using to start the script
if [ $DSUSER == 'root' ]; then

# Oops is caught you running as root. Are you SURE you want to run as root? YES or NO.
echo -e "You are currently running as $DSUSER, This is dangerous and should be avoided\nAre you sure you want to do this? (yes or no please):"
case "$REPLY" in
# running it as root... This is a huge security no no!
echo -e "Alright proceeding running program as $DSUSER"

# Currently checking to see if the pid files from the startup process exsist. If not then continue normally
if [ ! -f $DSPATH/$ ] && [ ! -f $DSPATH/$GDIR/$ ]; then
if [ -x $DSPATH/$DSNAME ]; then
echo "Starting $TITLE: Services"
sleep 1 # prevent race condition on SMP kernels
ps -ef | grep SCREEN | grep "$CLIENT" | grep -v grep | awk '{ print $2 }' > $ # Finding and
writing current process id of the screen process
echo -e "$DSNAMESHORT Process ID Written to $\n$DSGAME Server Process ID Written to $"
echo -e "Found a .pid file, Server is Already running!\nIf your sure the server is not running try (./ clean)" # It found that one of the pid files exsists perhaps the server did not shut down with the script being used... if this is the case use <scriptname> clean to fix it
# Good choice... you did not choose to run as root
echo -e "Wise choice please login as a different user or run this with su - <username> -c 'command'.\nNOTE: If you su to another user you will not be able to view a screen session unless you are\ndirectly logged in as that user or you can ssh to localhost!"
# Valid responses are YES or NO
echo -e "I don't recognize $REPLY as a valid yes or no answer. Please use yes or no only"
# The script found you were not running as root so it is running like normal. Uses same calls to activate script like above just no input is require to start it this time. You should not be prompted for yes or no if you are not root running it this time
if [ ! -f $DSPATH/$ ] && [ ! -f $DSPATH/$ ]; then
if [ -x $DSPATH/$DSNAME ]; then
echo "Starting $TITLE: Services"
sleep 1 # prevent race condition on SMP kernels
ps -ef | grep SCREEN | grep "$CLIENT" | grep -v grep | awk '{ print $2 }' > $
echo -e "$DSNAME Process ID Written to $\n$DSNAMESHORT Server Process ID Written to $"
echo -e "Server is Already running!\nIf your sure the server is not running try (./ clean)"


service_stop() {

# This script is just getting the process id of the server that was written to the file it created
# earlier so it can kill it.
    for vdspid in $(cat $DSPATH/$;
        kill $vdspid;
rm -rf $DSPATH/$;echo "$DSPATH/$DSNAME $ has been deleted"
    rm -rf $DSPATH/$GDIR/$;echo "$DSPATH/$GDIR/$DSNAMESHORT $ has been deleted"
# This command is just clearing out any *DEAD* screen sessions. Those can become a pain really quick
    screen -wipe 1> /dev/null 2> /dev/null

service_restart() {

# Simple enough. It is making a call to the stop service and then it waits for a second then it calls
# the start script

  sleep 1

service_status() {
# This is checking to see if $ file exsists
if [ -f $DSPATH/$ ]; then
# Pulling in the values to evaulate if they are true or not
PROCSERV=`ps -ef | grep SCREEN | grep "$CLIENT" | grep -v grep | awk '{ print $2 }'`

# This is checking to see if the currently running process ID matches with the pid created when the
# server was started
if [ "$PROCESSRUN" == "$PROCSERV" ]; then
echo -e "$DSNAME is running on process `cat $DSPATH/$`\n " # It found this process ID matches and is outputting what it is currently running on
echo -e "$DSNAME is offline.\nSomeone or something else may have killed it." # Apparently the server is offline
if [ "$PROCSERV" ]; then
echo -e "However a Process Matching the same criteria was found at process ID $PROCSERV....\n Might be worth a investigation" # Wait, it found another server matching the same criteria running under a different process ID.

#Checking to see if this file exsists

if [ -f $DSPATH/$ ]; then
echo "$DSNAMESHORT Server is running on process `cat $DSPATH/$GDIR/$`" # It found the file exsists and is outputting the info
echo -e "$DSGAME Server is offline.\nSomeone or something else may have killed it or it is just rebooting" #Oops the server is active or the pid file got deleted.

# This service is used watch the process that is currently running

# Check if there is someone already attached

if [ `screen -wipe | grep $CLIENT | grep -v grep | awk '{ print $2 }'` == '(Attached)' ]; then
echo -e "Someone is already attached to the console of the server.\n Might want to check who"
# Oops someone is already attached to it..... better wait your turn or go chew someone $%^ out

# Looks like noone is watching it right now.... peeping tom time !!!

screen -r $CLIENT

# This service is used to clean house if the script is reporting erroneous info.


rm -rf *.pid;echo "*.pid has been deleted"
rm -rf $DSPATH/$GDIR/*.pid;echo "$DSPATH/$GDIR/*.pid has been deleted"
screen -wipe 1> /dev/null 2> /dev/null;echo "Screens have been wiped"

case "$1" in
  echo "usage $0 start|stop|restart|status|watch|clean"

Hope this helps someone!

Attached Files
.txt (Size: 8.48 KB / Downloads: 7)

Forum Jump:

Users browsing this thread: 1 Guest(s)