Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 10th October 2007, 16:30
bernholdt bernholdt is offline
Senior Member
 
Join Date: Jun 2007
Posts: 156
Thanks: 46
Thanked 13 Times in 11 Posts
Default Need help with exec a start.sh script from php.

Hi there
i got this start script were i from command line can stop, start and restart a gameserver. What i would like to know is if there is annyway to do this trugh php ??
My start script looks like this
Quote:
#! /bin/sh
################################################## #######
# STARTSCRIPT FÜR EINEN Call of Duty 2 SERVER #
################################################## #######
# Benutzung auf eigene Gefahr!!!!!!!!!!! #
# SCREEN muss auf dem Server installiert sein! #
################################################## #######
# Vars: #
# G_USER Username #
# NAME Screen-Name #
# DESC Server-Beschreibung #
# PARAMS Start-Parameter #
# DIR HLDS Directory (absolut) #
# SCRIPT Serverstart-Script #
# DAEMON Daemon #
################################################## #######
# OPTIONS: (start|stop|restart|status) #
################################################## #######

################## User ################################
# Username unter dem der Server laufen soll
# NICHT als root laufen lassen
G_USER=etserver1
################## Vars #################################
# Screen NAME
# Attach Screen : # screen -r Etserver1
# Detach Screen : # [CTRL]+[A]; [D]
# Don't press [CTRL]+[C] it will terminate screen
NAME=Etserver1
################## Server Description ###################
# Single Word DESC=myserver
# Multiple Words DESC="This is my Server"
DESC="Enemy Territoryserver1"
################## Parameter ############################
# CAN USE: +servercfgfile server.cfg OR +exec server.cfg
PARAMS="+set vm_game 0 +set sv_pure 1 +set dedicated 2 +set net_ip 82.103.141.80 +set net_port 27960 +set fs_game etpub +set sv_punkbuster 1 +exec server.cfg"
################## Directory ############################
# Pfad zum cod2-Directory (absolute)
DIR=/home/etserver1/enemy-territory/
################## DAEMON ##############################
# Hier das Startscript platzieren, normalerweise hlds_run
SCRIPT=etded
################################################## #####
#### NICHTS UNTER DIESER ZEILE VERÄNDERN ! ! ! ####
################################################## ######

DAEMON=$DIR/$SCRIPT

case "$1" in
start)
if [[ `su $G_USER -c "screen -ls | grep $NAME"` ]]
then
echo "$DESC läuft bereits!"
else
echo "Starte $DESC "
su $G_USER -c "cd $DIR; screen -d -m -S $NAME $DAEMON $PARAMS"
fi
;;

stop)
if [[ `su $G_USER -c "screen -ls | grep $NAME"` ]]
then
echo -n "Stoppe $DESC "
kill `ps aux | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done."
else
echo "Kein laufenden $DESC gefunden!"
fi
;;

restart)
if [[ `su $G_USER -c "screen -ls | grep $NAME"` ]]
then
echo -n "Stoppe $DESC "
kill `ps aux | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done."
else
echo "Kein laufenden $DESC gefunden!"
fi

echo -n "Starte $DESC"
su $G_USER -c "cd $DIR; screen -d -m -S $NAME $DAEMON $PARAMS"
echo " ... done."
;;

status)
ps aux | grep -v grep | grep cod > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "$DESC ist online" || echo "$DESC ist offline"
;;
*)

echo "Benutze: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0

---

Anny help would be apreciated
Reply With Quote
Sponsored Links
  #2  
Old 11th October 2007, 16:20
ebal ebal is offline
Member
 
Join Date: Aug 2007
Posts: 36
Thanks: 0
Thanked 2 Times in 2 Posts
 
Default

you can use this

http://gr2.php.net/manual/en/function.shell-exec.php

but it is not any safe at all
you should create a security interface to this php script
__________________
http://ebalaskas.gr/wiki
Reply With Quote
The Following User Says Thank You to ebal For This Useful Post:
bernholdt (7th November 2007)
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
php eating cpu shajazzi Server Operation 15 15th August 2007 01:19
Slightly Confused (DNS & Server Help) JohnnyBGoode Installation/Configuration 26 14th August 2007 09:54
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18


All times are GMT +2. The time now is 23:47.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.