Shellscript for starting/stopping/restarting an ET-Server
12 posts
• Page 1 of 1
- Stormcrow
- Posts: 990
- Joined: Mon Nov 13, 2006 1:00
- Location: World -> Europe -> Germany -> Swabia
Shellscript for starting/stopping/restarting an ET-Server
Howdy guys,
i have written a script for starting/stopping/restarting a ET-Server. Later on, I want to combine it with a PHP-Script, so that i can let other ppl do start, restart or stop the server without give them a ssh-account.
Maybe the proficient ppl here can have a look at it and try the script.
I know its not the Help Desk, but I have still a question.
I tried to run two ET-Servers on my Laptop, i installed ET in the standard-folder(usr/local/games..../) and created two more users, et1 and et2. Then tried to run the server in the individual user modes, but it doesnt work (couldn't load default.cfg). If i run one et-server on root it works perfectly, but neither i dont want them to run in superuser mode nor i only want one server running, i need two.
It's a project for university, so i hope u could help me
So long,
Michel
i have written a script for starting/stopping/restarting a ET-Server. Later on, I want to combine it with a PHP-Script, so that i can let other ppl do start, restart or stop the server without give them a ssh-account.
Maybe the proficient ppl here can have a look at it and try the script.
- Code: Select all
#!/bin/bash
##gamestart.sh
##Start/Stop/Restart Gameservers by Script ***BETA***
##Could be extended/changed for other Games
##Created by >>>|Stormcrow
##global
RED="\033[31m\t"
GREEN="\033[32m"
BLACK="\033[m"
TMP_DIR="/tmp"
PID="/tmp/$1.pid"
SCREEN="/usr/bin/screen"
## enemy territory
ET_EX="etded"
ET_NAME="EnemyTerritory"
ET_DIR="/usr/local/games/enemy-territory"
ET_PARAMS=" +set dedicated 2 +set sv_punkbuster 1 +exec server.cfg"
## usage
function usage() {
echo -e "\nusage: $0 <game> <command>"
echo -e "\t$0 status\n"
echo -e "\tgame: et"
echo -e "\tcommand: start | restart | stop | see"
}
## start server
function server_start() {
[ -f $PID ] && echo -e "\n\t$RED $5 already running!$BLACK\n" && exit 1
cd $2
$SCREEN -dmS $1 ./$3 $4
$SCREEN -ls |grep $1 |awk -F . '{print $1}'|awk '{print $1}' > $PID
echo -e "\n\t$GREEN $5 started!$BLACK\n"
exit 0
}
## restart server
function server_restart(){
if [ ! -f $PID ]; then
echo -e "\n\t$RED $5 is not running!$BLACK\n"
cd $2
$SCREEN -dmS $1 ./$3 $4
$SCREEN -ls |grep $1 |awk -F . '{print $1}'|awk '{print $1}' > $PID
echo -e "\n\t$GREEN $5 started!$BLACK\n"
exit 0
fi
kill $(head $PID -n1 -q)
rm $PID
echo -e "\n\t$GREEN $5 stopped!$BLACK\n"
sleep 1
cd $2
$SCREEN -dmS $1 ./$3 $4
$SCREEN -ls |grep $1 |awk -F . '{print $1}'|awk '{print $1}' > $PID
echo -e "\n\t$GREEN $5 restarted!$BLACK\n"
exit 0
}
## stop server
function server_stop() {
[ ! -f $PID ] && echo -e "\n\t$RED $1 is not running!$BLACK\n" && exit 1 ## server running?
kill $(head $PID -n1 -q)
rm $PID
echo -e "\n\t$GREEN $1 stopped.$BLACK\n"
exit 0
}
function server_see() {
$SCREEN -r $1
exit 0
}
[ ! -w $TMP_DIR ] && echo -e "\n\t$RED Error: TMP_DIR not writable!\n" && exit 1
[ ! -x $SCREEN ] && echo -e "\n\t$RED Error: $SCREEN could not be found!\n" && exit 1
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
usage
exit 0
fi
if [ "$1" == "status" ]; then
[ ! -f $TMP_DIR/et.pid ]
echo -e "\n\t$GREEN Gameserver is not running!$BLACK\n" && exit 0
[ -f $TMP_DIR/et.pid ] && echo -e "\n\t$GREEN $ET_NAME is running!$BLACK"
echo
exit 0
fi
if [ $# -ne 2 ]; then
echo -e "\n\t$RED Error: $BLACK wrong parameter(s)\n"
usage
exit 1
fi
case "$2" in
"start" ) ;;
"restart" ) ;;
"stop" ) ;;
"see" ) ;;
* ) echo -e "\n\t$REDError: $BLACK $2 is not valid!\n"
usage
exit 1
;;
esac
if [ "$2" == "start" ]; then
server_start $1 "$ET_DIR" "$ET_EX" "$ET_PARAMS" "$ET_NAME"
fi
if [ "$2" == "restart" ]; then
server_restart $1 "$ET_DIR" "$ET_EX" "$ET_PARAMS" "$ET_NAME"
fi
if [ "$2" == "stop" ]; then
server_stop "$ET_NAME"
fi
if [ "$2" == "see" ]; then
server_see $1
fi
;;
I know its not the Help Desk, but I have still a question.
I tried to run two ET-Servers on my Laptop, i installed ET in the standard-folder(usr/local/games..../) and created two more users, et1 and et2. Then tried to run the server in the individual user modes, but it doesnt work (couldn't load default.cfg). If i run one et-server on root it works perfectly, but neither i dont want them to run in superuser mode nor i only want one server running, i need two.
It's a project for university, so i hope u could help me
So long,
Michel
realy nice post
i dont know, but maybe needa set the chmod?
so you can start the server ... but i dont think it will work ...
i think you forgot to put a server.cfg in the mod folder (etpub / shrub / etpro) or you forgot to run a map (+map oasis)
maybe do: ./etded.x86 +set fs_homepath /usr/local.../enemy-territory +set fs_basepath /usr/local.../enemy-territory +exec server.cfg +map oasis +set com_hunkemgs 192
or maybe give your account the files ...
would be for u:
EDIT: i think you only forgot to set in startfile: +map oasis
or make +exec maprotation.cfg
and write a maprotation.cfg
like:
explanation:
stuff starts with d1 ... d1 = map oasis, after oasis (d1) it will come d2 ... d2 = goldrush after goldrush (d2) it will come d3 and d3 = fueldump ... and so on
EDIT2:
learning in school / university how to set up an etserver ... and people say they would only learn unusefull stuff in school
i dont know, but maybe needa set the chmod?
- Code: Select all
chmod -R 777 enemy-territory
so you can start the server ... but i dont think it will work ...
i think you forgot to put a server.cfg in the mod folder (etpub / shrub / etpro) or you forgot to run a map (+map oasis)
maybe do: ./etded.x86 +set fs_homepath /usr/local.../enemy-territory +set fs_basepath /usr/local.../enemy-territory +exec server.cfg +map oasis +set com_hunkemgs 192
or maybe give your account the files ...
- Code: Select all
chown -R dictionaryname:username filepath
would be for u:
- Code: Select all
chown -R enemy-territory:et1 /usr/local.../enemy-territory
EDIT: i think you only forgot to set in startfile: +map oasis
or make +exec maprotation.cfg
and write a maprotation.cfg
like:
- Code: Select all
set d1 "set g_gametype 2 ; map oasis ; set nextmap vstr d2"
set d2 "set g_gametype 2 ; map goldrush ; set nextmap vstr d3"
set d3 "set g_gametype 2 ; map fueldump ; set nextmap vstr d4"
set d4 "set g_gametype 2 ; map railgun ; set nextmap vstr d5"
set d5 "set g_gametype 2 ; map battery ; set nextmap vstr d6"
set d6 "set g_gametype 2 ; map radar ; set nextmap vstr d7"
set d7 "set g_gametype 2 ; map venice ; set nextmap vstr d1"
vstr d1
explanation:
stuff starts with d1 ... d1 = map oasis, after oasis (d1) it will come d2 ... d2 = goldrush after goldrush (d2) it will come d3 and d3 = fueldump ... and so on
EDIT2:
It's a project for university, so i hope u could help me
So long,
Michel
learning in school / university how to set up an etserver ... and people say they would only learn unusefull stuff in school
It couldn't load the default cfg??
Ehm very wierd error.
This link may help you.
http://tjw.org/etded/
Ehm very wierd error.
This link may help you.
http://tjw.org/etded/
- Stormcrow
- Posts: 990
- Joined: Mon Nov 13, 2006 1:00
- Location: World -> Europe -> Germany -> Swabia
My server.cfg looks like that
And the corresponding map.cfg
No i took
and it worked some problems with the owner rights :-P
No i have to learn how to do it not with etmain but with noquarter or etpro.
Some questions for comprehension:
If i run ET as a User, for example et1, i need to make +set fs_homepath "/home/et1/.etwolf/", right? And +set fs_basepath is the folder in which i installed ET, so /usr/local/games/enemy-territory?
Google delivered not enough answers for all my questiosn Thnx a lot
Edit:
That link is awesome Thank you!
Chrooting...well, the safety aspect is not to forget...
- Code: Select all
\\Basic\\
//set dedicated "0"
//set net_ip ""
//set net_port "27960"
\\Clients and passwords\\
set sv_maxclients "32"
set g_password ""
set sv_privateclients "2"
set sv_privatepassword "blublub"
set rconpassword "blabla"
set refereePassword "blabla1"
\\DL & RATE\\
set sv_maxRate "16000"
set sv_dl_maxRate "42000"
set sv_allowDownload "1"
set sv_wwwDownload "0"
set sv_wwwBaseURL ""
set sv_wwwDlDisconnected "0"
set sv_wwwFallbackURL ""
\\MOTD & Hostname\\
set sv_hostname "^1Test^2Server"
set server_motd0 "^WHave phun"
set server_motd1 "^PDont break the rules"
set server_motd2 "^STESTETSTEST"
set server_motd3 ""
set server_motd4 ""
set server_motd5 ""
// TEAMS
set g_autofireteams "1"
set g_teamforcebalance "1"
set g_noTeamSwitching "0"
set g_heavyWeaponRestriction "20"
set team_maxplayers "0"
set team_nocontrols "1"
\\MISC Settings\\
set g_antilag "1"
set g_altStopwatchMode "0"
set g_complaintlimit "8"
set g_ipcomplaintlimit "3"
set g_disableComplaints "7"
set g_fastres "0"
set g_friendlyFire "1"
set g_minGameClients "4"
set g_maxlives "0"
set g_alliedmaxlives "0"
set g_axismaxlives "0"
set g_teamforcebalance "1"
set g_noTeamSwitching "0"
set g_voiceChatsAllowed "4"
set g_doWarmup "1"
set g_warmup "10"
set g_inactivity "300"
set g_spectatorInactivity "600"
set sv_floodProtect "1"
set sv_pure "1"
set sv_minping "0"
set sv_maxping "180"
set match_latejoin "1"
set match_minplayers "4"
set match_mutespecs "0"
set match_readypercent "100"
set match_timeoutcount "0"
set match_warmupDamage "1"
set team_maxplayers "0"
set team_nocontrols "1"
set pmove_fixed "0"
set pmove_msec "8"
set team_maxPanzers "-1"
set sv_fps "20"
set g_autofireteams "1"
set logfile "0"
set g_log "server.log"
set g_gametype "4"
set com_hunkmegs "54"
set com_zonemegs "24"
set sv_allowAnonymous "1"
\\PunkBuster\\
//pb_sv_disable
pb_sv_autoUpdBan 1
pb_sv_CQC 1
pb_sv_KickLen 2
PB_SV_MaxConDls 4
PB_SV_MaxDlRate 4
Pb_sv_noguidgrace 30
pb_sv_updategrace 300
pb_sv_guidrelax 0
pb_sv_scoreKick -9
pb_sv_specname ETTV
pb_sv_dupNameGrace 20
pb_sv_changePeriod 20
pb_sv_changeMax 5
pb_sv_EmptyName 0
pb_sv_minName 1
pb_sv_extChar 1
pb_sv_badname 20 TEAMMATE
pb_sv_badname 20 teamate
pb_sv_badname 20 disguised
pb_sv_badname 20 disguised
pb_sv_badname 20 disgised
pb_sv_badname 20 desguised
pb_sv_badname 20 desgised
pb_sv_badname 0 teamkill
pb_sv_badname 20 hitler
pb_sv_badname 20 nazi
set g_banIPs ""
set g_filterBan "1"
pb_sv_banload
\\Extra\\
//sets CPU ""
//sets Connection ""
sets Administrator ">>>|Stormcrow"
//sets ICQ ""
//sets MSN ""
//sets MAIL ""
sets Location "Germany"
//sets URL ""
\\LMS\\
set g_lms_teamForceBalance "1"
set g_lms_roundlimit "3"
set g_lms_matchlimit "2"
set g_lms_currentMatch "0"
set g_lms_lockTeams "1"
set g_lms_followTeamOnly "1"
\\Master Servers\\
seta sv_master1 "master3.idsoftware.com"
seta sv_master2 "master0.gamespy.com"
seta sv_master3 "wolfmaster.idsoftware.com"
seta sv_master4 "clanservers.net"
\\Votes\\
set g_allowVote "1"
set vote_limit "6"
set vote_allow_comp "0"
set vote_allow_gametype "0"
set vote_allow_kick "0"
set vote_allow_map "1"
set vote_allow_matchreset "1"
set vote_allow_mutespecs "0"
set vote_allow_nextmap "1"
set vote_allow_pub "0"
set vote_allow_referee "0"
set vote_allow_shuffleteams "1"
set vote_allow_swapteams "0"
set vote_allow_friendlyfire "0"
set vote_allow_timelimit "1"
set vote_allow_warmupdamage "1"
set vote_allow_antilag "0"
set vote_allow_balancedteams "0"
set vote_allow_muting "1"
\\LOGGING\\
set g_log "etserver.log"
set logfile 2
set g_logsync 0
\\WATCHDOG\\
set com_watchdog_cmd "exec map.cfg"
\\Maprotation\\
exec map.cfg
And the corresponding map.cfg
- Code: Select all
set d1 "campaign cmpgn_map; set nextcampaign vstr d1"
set d_initial "set g_gametype 4; map oasis; set nextcampaign vstr d1"
vstr d_initial
No i took
- Code: Select all
./etded +set dedicated 2 +set sv_punkbuster 1 +exec server.cfg"
and it worked some problems with the owner rights :-P
No i have to learn how to do it not with etmain but with noquarter or etpro.
Some questions for comprehension:
If i run ET as a User, for example et1, i need to make +set fs_homepath "/home/et1/.etwolf/", right? And +set fs_basepath is the folder in which i installed ET, so /usr/local/games/enemy-territory?
Google delivered not enough answers for all my questiosn Thnx a lot
Edit:
Ammz wrote:It couldn't load the default cfg??
Ehm very wierd error.
This link may help you.
http://tjw.org/etded/
That link is awesome Thank you!
Chrooting...well, the safety aspect is not to forget...
you mean setting the game mod like shrubet or etpub?
the command therefor is: +set fs_game etpub
you only needa put etpub folder there ... (in enemy-territory folder; where etmain and pb folder are)
i used this once to start a server:
./etded.x86 +set fs_homepath /home/xy/enemy-territory set fs_basepath /home/xy/enemy-territory +set fs_game etpub +set com _hunkmegs 92 +exec server.cfg +set sv_maxclients "40"
and the map.cfg ...
i would write in:
thats the same like you had, but it works 100% and easy to edit
the command therefor is: +set fs_game etpub
you only needa put etpub folder there ... (in enemy-territory folder; where etmain and pb folder are)
i used this once to start a server:
./etded.x86 +set fs_homepath /home/xy/enemy-territory set fs_basepath /home/xy/enemy-territory +set fs_game etpub +set com _hunkmegs 92 +exec server.cfg +set sv_maxclients "40"
and the map.cfg ...
i would write in:
- Code: Select all
set d1 "set g_gametype 2 ; map oasis ; set nextmap vstr d2"
set d2 "set g_gametype 2 ; map goldrush ; set nextmap vstr d3"
set d3 "set g_gametype 2 ; map fueldump ; set nextmap vstr d4"
set d4 "set g_gametype 2 ; map railgun ; set nextmap vstr d5"
set d5 "set g_gametype 2 ; map battery ; set nextmap vstr d6"
set d6 "set g_gametype 2 ; map radar ; set nextmap vstr d1"
vstr d1
thats the same like you had, but it works 100% and easy to edit
To execute shell-script via PHP try exec()
-=RapidHail=-: Do or do not... There is no try.
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
- Stormcrow
- Posts: 990
- Joined: Mon Nov 13, 2006 1:00
- Location: World -> Europe -> Germany -> Swabia
I tried system() and shell_exec(), both functions are working, the problem is that the server then is starting as the user www-data the server seems to be running (the pid-file is generated), but i could no connect :-P
Now i had new insane idea, i am going to use ssh2_connect() to connect to the server als the user et1 and then i'll use ssh2_exec() to run the server :-P
But now i am hanging on the error
libssh2 is installed, i dont have a clue at the moment
Edit: crap idea
Now i had new insane idea, i am going to use ssh2_connect() to connect to the server als the user et1 and then i'll use ssh2_exec() to run the server :-P
But now i am hanging on the error
- Code: Select all
Fatal error: Call to undefined function ssh2_connect() in /var/www/start2.php on line 2
libssh2 is installed, i dont have a clue at the moment
Edit: crap idea
Last edited by Stormcrow on Tue Dec 05, 2006 20:50, edited 1 time in total.
You problably don't have php_ssh2 module loaded. System() and shell_exec() are thath king of functions which are waiting for output. Use exec()
-=RapidHail=-: Do or do not... There is no try.
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
- Stormcrow
- Posts: 990
- Joined: Mon Nov 13, 2006 1:00
- Location: World -> Europe -> Germany -> Swabia
It does work, the only problem is that the user which executes the command is the apache (www-data) and i want it to be the et1-user
next idea is do edit the sudoers and make a sudo -u et1...:desperate:
next idea is do edit the sudoers and make a sudo -u et1...:desperate:
Execute it through su/sudo or ssh user@password 'command'
-=RapidHail=-: Do or do not... There is no try.
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
-|PS|- Server Monitor
eRepublik Citizen
Network Toolkit
- Stormcrow
- Posts: 990
- Joined: Mon Nov 13, 2006 1:00
- Location: World -> Europe -> Germany -> Swabia
After several wiskey-cola, serveral man-pages im drunken but it works like i want it *gluks*
No i have to be patient untill Hetzner set my root-server up and then i could go on with all that stuff...thank you...no i go to PS1...hope my aiming is better than that afternoon.
So long
No i have to be patient untill Hetzner set my root-server up and then i could go on with all that stuff...thank you...no i go to PS1...hope my aiming is better than that afternoon.
So long
12 posts
• Page 1 of 1
Return to PS Forum Archives - 2006
Who is online
Users browsing this forum: No registered users and 18 guests