PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Screen Script



Jerrycan
24.09.2010, 19:16
Hi ich habe ein Startscript für mein CSS Server

#! /bin/bash
#
# Start the Counter-Strike: Source dedicated server.
#
# AUTHORS :
#
# Julien Escario ( pandemik@azilog.net )
# &
# Cedric Rochat ( crochat@younics.org )
# &
# Cmdr._Firewalker ( cmdr._firewalker@web.de )
#
# ===========================================
#
# What you need:
#
# Linux :)
# awk
# screen
# the srcds_l & cstrike files (obtainable via steam)
#
# How to use:
#
# Edit the CS_USER-Var to the user running your cs-servers
# Edit the DIR-Var to fit your system (just contains the path to the dir that contains srcds_run)
# Edit the PARAMS-Var to fit your needs
# - standard is startup as internet server
# if you use multiple scripts on one system you should change the NAME-var (otherwise
# all will be stopped if you run the script with "stop", and status will be useless)
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services) and set the execute permission.
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# ln -s /etc/rc.d/init.d/srcds /etc/rc.d/rc3.d/S90srcds
# ln -s /etc/rc.d/init.d/srcds /etc/rc.d/rc3.d/K50srcds
# or use update-rc.d if you got a system using that tool (like Debian, see manpage)
#
# Or use it manually like:
# ./srcds start
# ./srcds stop
#
# To see the server-console start the script with the parameter "watch".
#
# DOC by jwm (jwm@counter-strike.de)

# !!!!!!!!!!!!!! CHANGE THIS TO THE USER YOU USE FOR YOUR SERVER !!!!!!!!!!!!!!!
CS_USER=gmod

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

# # DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/home/gmod/srcds/orangebox/

DAEMON=srcds_run

# LAN server:
# PARAMS="-game cstrike -nomaster -insecure +sv_lan 1 +maxplayers 16 +map de_dust"
# Internet server:
PARAMS="-game cstrike +map de_dust2 +maxplayers 10 -port 27016 +autoupdate"

NAME=css
DESC="CS:S dedicated server"

# No edits (should be) necessary beyond this line

if [ ! -x `which awk` ]; then echo "You need awk for this script"; exit 1; fi
if [ ! -x `which screen` ]; then echo "You need screen (the program, moron!) for this script"; exit 1; fi

if [ `whoami` = root ]
then
usagetype=root
else
usagetype=nonroot
fi

start() {
if [ ! -d $DIR ]; then echo " ... No such directory: $DIR!"; exit 1; fi
if [ ! -x $DIR/$DAEMON ]; then echo "$DIR/$DAEMON does not exist or is not executable!"; exit 1; fi
if status; then echo " ... $DESC: $NAME is already running!"; exit 1; fi

case "$usagetype" in
root)
su - $CS_USER -c "cd $DIR ; screen -AmdS $NAME ./$DAEMON $PARAMS"
;;
nonroot)
cd $DIR ; screen -AmdS $NAME ./$DAEMON $PARAMS
;;
esac

}

stop () {
if ! status; then echo " ... $DESC $NAME could not be found. Probably not running."; exit 1; fi

case "$usagetype" in
root)
tmp=$(su - $CS_USER -c "screen -ls" | awk -F . "\$2 ~ /^$NAME[[:space:]].*/ {print \$1}" | awk '{print $1}')
su - $CS_USER -c "screen -r $tmp -X quit"
;;
nonroot)
screen -r $(screen -ls | awk -F . "\$2 ~ /^$NAME[[:space:]].*/ {print \$1}" | awk '{print $1}') -X quit
;;
esac
}

status () {
case "$usagetype" in
root)
su - $CS_USER -c "screen -ls" | grep [.]$NAME[[:space:]] > /dev/null
;;
nonroot)
screen -ls | grep [.]$NAME[[:space:]] > /dev/null
;;
esac
}

watch () {
if ! status; then echo "$DESC $NAME could not be found. Probably not running."; exit 1; fi

case "$usagetype" in
root)
tmp=$(su - $CS_USER -c "screen -ls" | awk -F . "\$2 ~ /^$NAME[[:space:]].*/ {print \$1}" | awk '{print $1}')
su - $CS_USER -c "screen -r $tmp"
;;
nonroot)
screen -r $(screen -ls | awk -F . "\$2 ~ /^$NAME[[:space:]].*/ {print \$1}" | awk '{print $1}')
;;
esac
}

case "$1" in
start)
echo "Starting $DESC: $NAME"
start
echo " ... done."
;;

stop)
echo "Stopping $DESC: $NAME"
stop
echo " ... done."
;;

restart)
echo "Restarting $DESC: $NAME"
status && stop
start
echo " ... done."
;;

status)
if status
then echo "$DESC: $NAME is UP"
else echo "$DESC: $NAME is DOWN"
fi
;;
watch)
watch
;;

*)
echo "Usage: $0 {start|stop|status|restart|watch}\nWhile watching press ctrl-a, ctrl-d to stop watching without stopping the server."
exit 1
;;

esac


exit 0

Das starten und die status abfrage funktionieren ohne Probleme.
Aber bei watch, stop und restart listet er mir alle laufenden screen prozesse auf(da noch andere sachen so laufen) und macht nix weiter

*****:~$ ./css_start.sh watch
There are several suitable screens on:
27681.css (09/24/2010 07:55:45 PM) (Detached)
** (09/22/2010 04:03:21 PM) (Detached)
** (09/18/2010 01:20:22 PM) (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

Plx help

LuLu-X
25.09.2010, 10:44
Okay, zum einen versteh ich zwar nicht warum Leute soetwas brauchen, aber naja :D.

Das starten und die status abfrage funktionieren ohne Probleme.
Aber bei watch, stop und restart listet er mir alle laufenden screen prozesse auf(da noch andere sachen so laufen) und macht nix weiter
Bei start und status versucht das Skript keine der Screen-Sessions wieder zu starten. Zeigt Screen dir alle verfügbaren Sessions an, ist die Angabe welche Session du wiederherstellen willst nicht eindeutig und muss genauer genannt werden. So kannst du zB mit screen -r 2 (das reicht bei deiner angabe da schon) den Screen 27681.css wieder öffnen. Was die beiden ** Screens sind kann ich dir leider so direkt nicht sagen, würde sie mal schließen, vll läuft das Skript anschließend besser.
Andernfalls die Filtermethoden in den Funktionen anpassen, dazu fehlt mir selber gerade die Lust (ich mag awk nicht :D), zumal die Bedienung eines CSS-Servers, bzw, die, die dein Skript da kann auch händisch via Konsole sehr simpel ist.

Jerrycan
25.09.2010, 18:22
Ja ich machs eig. auch manuel aber da ich ein restart in einem cronjob machen will meinem die im forum das das mit sonem script geht

LuLu-X
25.09.2010, 22:41
Ja, aber du kannst dir auch selber eins schreiben :o



#!/bin/bash
cd /home/gmod/srcds/orangebox/
screen -AmdS css ./srcds_run -game cstrike +map de_dust2 +maxplayers 10 -port 27016 +autoupdate


Das als Skript nach init.d linken oder nach "Benennungsrechten" dort anlegen oder ins passende runlevel Startverzeichnis und schon startet dein Server von selber (was du ja willst)
Kannst dann auch via Screen den Prozess beobachten. Sollte eigentlich reichen wie du deine Bedürfnisse beschrieben hast.
Grüße

PS: Tippfehler ggf. ausbessern :o