PDA

View Full Version : startscript for etqw (without screen)


8Ball
08-17-2007, 07:20 PM
#! /bin/sh
################################################## #######################
# Scriptversion 1.1 by ]MaX[
#
# This script is to start a gameserver like
# Enemy Territory
# Enemy Territory Quake Wars
# Return to Castle Wolfenstein
# Should work on other games like CS, CSS or UT too.
################################################## #######################
# Use at your Own Risk !!!!!!!!!!!
################################################## #######################
# Contact: max@technik@magicon-online.de
# Contact: getthemax@web.de
# You dont need screen installed or nohup on your server
################################################## #######################
#
# You have to add to /etc/sudoers
# Youre like
# username ALL=(ALL) /home/yourdictionary/scriptname
#
# To start the server automatically after reboot
# For Debian and Ubuntu do a:
#
# ln -s /home/yourdictionary/scriptname /etc/init.d/
# and make
# update-rc.d scriptname defaults
#
# or for distributions add a cronjob
# @reboot for i in /home/yourdictionary/scriptname; do $i; done
#
# Script starts as user gameserver or the user you choose
# Make you're self happy and dont type username root
# You can run all you're servers from one dictionary, you dont need to
# create a user for every gameserver on you're server
# Script checks it self after start you will get
# Server started with Pid: xxx by succsess or
# FAILD
#########################DO NOT RUN THE SERVER AS ROOT###################
# Vars:
# USER Systemuser
# GROUP Systemgroup
# DAEMON Server binary
# DIR Dictionary where the server is installed
# IP Server IP
# Port Server Port
# Pidfile Processid will stored here
# DESC Server description War - or Publicserver
# PNAME Processname will show under pstree or ps aux
################################################## #######################
# This script stands under CC-Lizenz BY-NC-SA 2.0
# For commercial use contact the author
################################################## #######################

PATH=/sbin:/bin:/usr/sbin:/usr/bin:$DIR

USER=gameserver
GROUP=users

DIR=/home/gameserver/etqw-warserver
DAEMON=etqwded.x86

IP=88.198.46.245
PORT=27734

PIDFILE=server.pid

DESC="ETQW-Warserver1"
PNAME="ETQW-War1"


OPTIONS="+set net_serverDedicated 2 +set vm_game 0 +set in_tty 0"
NET_PARAM="+set net_ip $IP +set net_port $PORT"
GAME_PATH="+set basepath $DIR +set fs_savePath $DIR/.etqw set fs_devpath $DIR +set fs_devpath $DIR"
GAME_PARAM="+set net_serverPunkbusterEnabled 1 +set fs_game_base base +exec server.cfg"

################################################## ######
#### DONT CHANGE ANYTHING BELOW THIS LINE ! ! ! ####
################################################## ######

check_pid() {
PID=`ps aux | grep -v grep | grep $PNAME | awk '{print $2}'`
}

check_running() {
if [ ! -e "$PIDFILE" ]
then
echo "$DESC IP $IP Port $PORT"
echo ""
echo -e "\033[1mFAILED!!!\033[0m"
cd $DIR && rm $PNAME
else
echo Server started with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

check_restart() {
if [ ! -e "$PIDFILE" ]
then
echo "Restarting IP $IP Port $PORT"
echo ""
echo -e "\033[1mFAILED!!!\033[0m"
else
echo Server restarted with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

case "$1" in
start)
check_pid
if [ -z "$PID" ] ; then
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u $USER --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_running
else
echo "$DESC IP $IP Port $PORT is allready running."
exit 1
fi
;;

stop)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
echo ""
echo "$DESC IP $IP Port $PORT stopped"
;;

restart)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
sleep 1
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u $USER --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_restart
;;
*)

echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac

exit 0

8Ball
08-18-2007, 01:56 AM
#! /bin/sh
################################################## #######################
# This script is to start a gameserver like
# Enemy Territory
# Enemy Territory Quake Wars
# Return to Castle Wolfenstein
# should work on other games like CS, CSS or UT too.
################################################## #######################
# Use at your Own Risk !!!!!!!!!!!
################################################## #######################
# Contact: max@technik@magicon-online.de
# You dont need screen installed on your server
################################################## #######################
# Vars:
# USER Systemuser
# GROUP Systemgroup
# DAEMON Server binary
# DIR Dictionary where the server is installed
# IP Server IP
# Port Server Port
# Pidfile Processid will stored here
# DESC Server description War - or Publicserver
# PNAME Processname will show under pstree or ps aux
################################################## #######################
# This stands under CC-Lizenz BY-NC-ND 2.0
################################################## #######################

PATH=/sbin:/bin:/usr/sbin:/usr/bin:$DIR

USER=gameserver
GROUP=users

DIR=/home/gameserver/etqw-warserver
DAEMON=etqwded.x86

IP=88.198.46.245
PORT=27734

PIDFILE=server.pid

DESC="ETQW-Warserver1"
PNAME="ETQW-War1"


OPTIONS="+set net_serverDedicated 2 +set vm_game 0 +set in_tty 0"
NET_PARAM="+set net_ip $IP +set net_port $PORT"
GAME_PATH="+set basepath $DIR +set fs_savePath $DIR/.etqw set fs_devpath $DIR +set fs_devpath $DIR"
GAME_PARAM="+set net_serverPunkbusterEnabled 1 +set fs_game_base base +exec server.cfg"

################################################## ######
#### DONT CHANGE ANYTHING BELOW THIS LINE ! ! ! ####
################################################## ######

check_pid() {
PID=`ps aux | grep -v grep | grep $PNAME | awk '{print $2}'`
}

check_running() {
if [ ! -e "$PIDFILE" ]
then
echo "$DESC IP $IP Port $PORT FAILED"
cd $DIR && rm $PNAME
else
echo Server started with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

check_restart() {
if [ ! -e "$PIDFILE" ]
then
echo "FAILED Restarting IP $IP Port $PORT"
else
echo Server restarted with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

case "$1" in
start)
check_pid
if [ -z "$PID" ] ; then
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u gameserver --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_running
else
echo "$DESC IP $IP Port $PORT is allready running."
exit 1
fi
;;

stop)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
echo ""
echo "$DESC IP $IP Port $PORT stopped"
;;

restart)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
sleep 1
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u gameserver --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_restart
;;
*)

echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac

exit 0



This is the final version of the script witout screen, i hope it works fine its tested for bugs so feel free to use it !

escapedturkey
08-18-2007, 06:02 AM
cd ~/quakewars

quakewarscron

*/10 * * * * ~/run_quakewars.bsh >/dev/null 2>&1

run_quakewars.bsh

#!/bin/bash
serverpid=`ps ux | grep etqwded.x86 | grep -v grep`
if [ -z "$serverpid" ]; then
crontab ~/quakewars/quakewarscron
cd ~/quakewars
rm -f nohup.out
nohup ./etqwded.x86 +set net_serverDedicated 1 +set in_tty 0 +set net_ip IP-address +set net_port 27733 +set fs_basepath /home/username/quakewars +set fs_savepath /home/username/quakewars +set fs_devpath /home/username/quakewars +set net_serverPunkbusterEnabled 1 +set fs_game "" +set fs_game_base base +exec server.cfg &
fi
exit 0
#EOF

Start QuakeWars:

chmod +x run_quakewars.bsh
./run_quakewars.bsh

Stop QuakeWars:

killall etqwded.x86 && crontab -r

]MaX[
08-18-2007, 11:22 PM
Here is the new version of the script. You dont need screen or nohup.


#! /bin/sh
################################################## #######################
# Scriptversion 1.1 by ]MaX[
#
# This script is to start a gameserver like
# Enemy Territory
# Enemy Territory Quake Wars
# Return to Castle Wolfenstein
# Should work on other games like CS, CSS or UT too.
################################################## #######################
# Use at your Own Risk !!!!!!!!!!!
################################################## #######################
# Contact: max@technik@magicon-online.de
# Contact: getthemax@web.de
# You dont need screen installed or nohup on your server
################################################## #######################
#
# You have to add to /etc/sudoers
# Youre like
# username ALL=(ALL) /home/yourdictionary/scriptname
#
# To start the server automatically after reboot
# For Debian and Ubuntu do a:
#
# ln -s /home/yourdictionary/scriptname /etc/init.d/
# and make
# update-rc.d scriptname defaults
#
# for other distributions add a cronjob
# @reboot for i in /home/yourdictionary/scriptname; do $i; done
#
# Script starts as user gameserver or the user you choose
# Make you're self happy and dont type username root
# You can run all you're servers from one dictionary, you dont need to
# create a user for every gameserver on you're server
# Script checks it self after start you will get
# Server started with Pid: xxx by succsess or
# FAILD
#########################DO NOT RUN THE SERVER AS ROOT###################
# Vars:
# USER Systemuser
# GROUP Systemgroup
# DAEMON Server binary
# DIR Dictionary where the server is installed
# IP Server IP
# Port Server Port
# Pidfile Processid will stored here
# DESC Server description War - or Publicserver
# PNAME Processname will show under pstree or ps aux
################################################## #######################
# This script stands under CC-Lizenz BY-NC-SA 2.0
# For commercial use contact the author
################################################## #######################

PATH=/sbin:/bin:/usr/sbin:/usr/bin:$DIR

USER=gameserver
GROUP=users

DIR=/home/gameserver/etqw-warserver
DAEMON=etqwded.x86

IP=88.198.46.245
PORT=27734

PIDFILE=server.pid

DESC="ETQW-Warserver1"
PNAME="ETQW-War1"


OPTIONS="+set net_serverDedicated 2 +set vm_game 0 +set in_tty 0"
NET_PARAM="+set net_ip $IP +set net_port $PORT"
GAME_PATH="+set basepath $DIR +set fs_savePath $DIR/.etqw set fs_devpath $DIR +set fs_devpath $DIR"
GAME_PARAM="+set net_serverPunkbusterEnabled 1 +set fs_game_base base +exec server.cfg"

################################################## ######
#### DONT CHANGE ANYTHING BELOW THIS LINE ! ! ! ####
################################################## ######

check_pid() {
PID=`ps aux | grep -v grep | grep $PNAME | awk '{print $2}'`
}

check_running() {
if [ ! -e "$PIDFILE" ]
then
echo "$DESC IP $IP Port $PORT"
echo ""
echo -e "\033[1mFAILED!!!\033[0m"
cd $DIR && rm $PNAME
else
echo Server started with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

check_restart() {
if [ ! -e "$PIDFILE" ]
then
echo "Restarting IP $IP Port $PORT"
echo ""
echo -e "\033[1mFAILED!!!\033[0m"
else
echo Server restarted with Pid: `tail $DIR/$PIDFILE`
fi
exit 0
}

case "$1" in
start)
check_pid
if [ -z "$PID" ] ; then
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u $USER --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_running
else
echo "$DESC IP $IP Port $PORT is allready running."
exit 1
fi
;;

stop)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
echo ""
echo "$DESC IP $IP Port $PORT stopped"
;;

restart)
start-stop-daemon --stop --pidfile $DIR/$PIDFILE
cd $DIR && rm $PNAME $PIDFILE
sleep 1
cd $DIR && cp -a $DAEMON $PNAME
start-stop-daemon --start --make-pidfile --pidfile $DIR/$PIDFILE \
--chdir $DIR sudo -u $USER --startas $PNAME $OPTIONS $NET_PARAM $GAME_PARAM $GAME_PATH --background
check_restart
;;
*)

echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac

exit 0

_KaszpiR_
08-22-2008, 09:51 PM
your script has typos, in example there is
set fs_devpath
instead of
+set fs_devpath