SRCDS Steam group


Nice bash script for server control
#1
Hello all,

As I've used this site to get CDG's CS:s server into running shape I thought it was nice to share a bit with the community, which has helped me. I recently modified a bash script that I used to control my HLDS servers.

This script assumes you have screen installed. I've tested this script on a SuSE and a Slackware distribution. If you encounter some problems with another distro you can post this ofcourse. Smile

I've attached the script: just store it on a logical location in your installation, chmod it to something executable and finish configuring some variables so that it will know where to find everything:
Code:
SERVER_ADDRESS:
  IP address on which the server should bind itself
SERVER_PORT:
  Port number on which the server should bind itself
GAME:
  Name of the mod (eg: "cstrike")
GAME_UPDATE:
  Name of the game using the steam update tool (eg: "Counter-Strike Source")
MAXPLAYERS:
  Maximum amount of players hosted on the server
STEAM_USER:
  Your steam account ID you use to update the server
STEAM_PASS:
  The password for your steam account
HEAPSIZE:
  Amount of memory reserved for the server
SCREEN:
  Location of the SCREEN binary (usually: "/usr/bin/screen")
SCREEN_NAME:
  Name of the screen session. (Handy when running multiple SCREEN SESSIONS)
SERVER_HOME:
  Location of the Half-Life Source Dedicated Server
STEAM_HOME:
  Location of the Steam update utility
Usage is very simple:
Code:
./srcds <start|stop|restart|console|status|update|help>

start:
  starts the dedicated server
stop:
  stops the dedicated server
restart:
  stops and then starts the server again
console:
  takes you to the server console, allowing you to control the server
status:
  tells you whether the server is running or not
update:
  stops server if it was running, updates it and then restarts it (if it was running)
help:
  shows the usage syntax of the tool

I hope this is any use to you. Enjoy! Wink


Attached Files
.txt   srcds_ctl.txt (Size: 3.38 KB / Downloads: 324)
[CDG]GrefTek
Clan of the Dead Goat
Portal: http://www.cdg.net/
Forums: http://www.cdg.net/forums/
Gunshop: http://www.cdg.net/gunshop/
Reply
#2
What's the difference with the standard script?

I can't check at the moment, server was down and I'm reinstalling it again Smile. But I thought that you could do the same with the script that's already there.
May the Source be with you...

Want to know which ports to forward on your router for a Source DS? Click here!
Reply
#3
To my knowledge the standard script doesn't automatically load your SRCDS server in a SCREEN session so that you can get back into the console of the server.

The added value of this script is an interface for starting, stopping and updating the server or restoring the SCREEN session to execute commands on the server console.

I've got a variant of this script running on another machine that allows multiple gameservers to be controlled by one script and makes the servers part of the runlevel configuration of the machine.
[CDG]GrefTek
Clan of the Dead Goat
Portal: http://www.cdg.net/
Forums: http://www.cdg.net/forums/
Gunshop: http://www.cdg.net/gunshop/
Reply
#4
Using the script on the tutorial it will automatically start the server, put it in a screen, and keep you at the CLI of the server.

This one just makes it a bit more easy for beginners.

Tracer
CS:Source 66.194.153.223:27015
Natural Selection 66.194.153.223:27016
Reply
#5
hate to sound like a complete idiot but hell nothing to lose. I have tried using this script with no success, maybe one you gents could point out what might be causing this error that I am getting back.
Code:
-sh-2.05b$ sh srcds_ctl start
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
'rcds_ctl: line 69: syntax error near unexpected token `{
'rcds_ctl: line 69: `die(){
I filled everything out properly and triple checked for errors or typo's but found none. I am trying this on CentOS 3.4 (REHL3).

Thanks
Reply
#6
nicotine Wrote:hate to sound like a complete idiot but hell nothing to lose. I have tried using this script with no success, maybe one you gents could point out what might be causing this error that I am getting back.
Code:
-sh-2.05b$ sh srcds_ctl start
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
'rcds_ctl: line 69: syntax error near unexpected token `{
'rcds_ctl: line 69: `die(){
I filled everything out properly and triple checked for errors or typo's but found none. I am trying this on CentOS 3.4 (REHL3).

Thanks


same here
Reply
#7
NICE SCRIPT MAN!! if its ok, i edited the script for 1.6 =P but, could you post the one you have for multiple servers? or you may send me it @ admin at bum-fight-krew.com

thanks in advanced!
Reply
#8
love to get the script for multiple as well if your allowing it out.

js
Reply
#9
I like this script. I had to modify it to not user the steam_user and steam_password options. I also added a tickrate variable, but I like it.

Thanks for sharing.

-D
Reply
#10
All I have to say is " Nice man, NICE " Thank you so much for sharing this, it makes getting things done, alot faster.

-Thanks bro
-Nick
Reply
#11
Yeah, If you could host the multiple Script one, It would be great.
Reply
#12
very new to linux applications.. script looks great but how can i get the script to work as a process and start automatically when the computer reboots. also if someone on rcon type rcon quit will this allow it to automatically restart? another thing, does this script make it run in screens? if so can i run it in the background somehow. sorry im a big noob!

im running fedora core 2

thanks
Reply
#13
The only thing that is missing, it doesnt have a map in it.

#!/bin/sh
# half-Life Source Dedicated Server Control Script
# Adaptation of Half-Life Dedicated Controle Sctipt
#
# srcds_ctl
# Author: Rogier "GrefTek" den Dulk <rogier.dendulk@xs4all.nl>
# Date: Feb 5th 2005
#
# This script is free for distribution and/or modification.
# Any improvements may be submitted to the address above.
#

# Source Dedicated Server Configuration Variables ############################
#
# IP address the server should be bound to
#
SERVER_ADDRESS=

# Port number the server should be bound to
#
SERVER_PORT=

# Type of game
#
GAME=

#Type of game for Steam Update
#
GAME_UPDATE=""

# Maximum amount of players
#
MAXPLAYERS=

# Your steam account (for automatic updates)
#
STEAM_USER=

# The password for your steam account
#
STEAM_PASS=

# The heapsize used by the dedicated server
#
HEAPSIZE=128000

# Environmental Variables ####################################################
#
# Location of the screen binary
#
SCREEN=/usr/bin/screen

# Name of the screen session
#
SCREEN_NAME=srcds

# Location of the Half-Life Source Dedicated Server
#
SERVER_HOME=/home/hlds

# Location of the Steam update utility
#
STEAM_HOME=$SERVER_HOME

# Do not edit beyond this point unless you know what you are doing ###########
#
ACTION=$1
die(){
echo "$2"
exit $1
}

isrunning(){
return `ps -ef | grep -v grep | grep SCREEN | grep -c " $SCREEN_NAME "`
}
if [ "x$ACTION" == "x" ]; then die 1 "usage: $0 <start|stop|restart|console|status|update>"; fi

case "$ACTION" in
start|up)
echo -en "Starting server: "
isrunning; UP=$?
if [ $UP -eq 1 ]; then die 1 "Server is already running..."; fi
cd $SERVER_HOME &>/dev/null || die 1 "Cannot find server directory..."
$SCREEN -A -m -d -S $SCREEN_NAME ./srcds_run -console -autoupdate +map de_dust \
-game $GAME +maxplayers $MAXPLAYERS -heapsize $HEAPSIZE \
+ip $SERVER_ADDRESS +port $SERVER_PORT \
#-steamuser $STEAM_USER -steampass $STEAM_PASS || die 1 "FAILED"
echo "OK"
;;
stop|down)
echo -en "Stopping server: "
isrunning; UP=$?
if [ $UP -eq 0 ]; then die 7 "Server isn't running..."; fi
$SCREEN -r $SCREEN_NAME -X quit || die 1 "FAILED"
echo "OK"
;;
restart)
$0 stop
sleep 1
$0 start
;;
console)
echo -en "Connecting... "
isrunning; UP=$?
if [ $UP -eq 0 ]; then die 1 "Server isn't running..."; fi
$SCREEN -r $SCREEN_NAME || die 1 "FAILED"
;;
status)
isrunning; UP=$?
if [ $UP -eq 0 ]; then echo "Server is DOWN"; exit 3
else echo "Server is UP"; exit 0
fi
;;
update)
isrunning; UP=$?
if [ $UP -eq 1 ]; then $0 stop; fi
cd $STEAM_HOME
$STEAM_HOME/steam -command update -game "$GAME_UPDATE" -dir $SERVER_HOME -username $STEAM_USER -password $STEAM_PASS -remember_password
if [ $UP -eq 1 ]; then $0 start; fi
;;
*)
die 0 "usage: $0 <start|stop|restart|console|status|update>"
esac
exit 0


In this part...
cd $SERVER_HOME &>/dev/null || die 1 "Cannot find server directory..."
$SCREEN -A -m -d -S $SCREEN_NAME ./srcds_run -console -autoupdate +map de_dust \

Just add the map you want to start when the server starts, or else it will not do anything. I hope this haas helped any one in any way ! This is for all you ppl that are kinda like " huh, it doesnt work "

But good job tho bro on making it! and thanks again!

- Blackhawk
Reply
#14
Havent much experience with this. Just converted to Linux (gotta learn this stuff )...
I get the same errors as mentioned above:
PROMPT:~/srcds_l> sh srcds_ctl.txt start
'rcds_ctl.txt: line 56: syntax error near unexpected token `{
'rcds_ctl.txt: line 56: `die(){

This is exactly the script i've been looking for, so it would be nice to have some help, guys! Smile
Reply
#15
No help for this?

I've been running a small server for some months, would really like to make this script work, but it will not run. I've searched all over the place to find help with this, but no luck.

Can anyone help me sort out what the reasons for the errormessages are when I try to run the script?

TT
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)