PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ein linux Script per PhP Starten, Stoppen



Nerospeed
21-07-2006, 10:35
Hallo,

ich suche ein PhP Script, was ein Linux Script ausführt. Leider bin ich bis jetzt noch nicht auf was funktionierendes gestoßen.
Folgendes Script soll gestartet werden und gestoppt werden


#! /bin/sh
#
# Start the Counter-Strike dedicated server as non-root.
#
# A modification of the CS Server startup script, to run the server
# as a non-root user.
#
# ORIGINAL AUTHORS :
#
# Julien Escario ( pandemik@asylog.net )
# &
# Cedric Rochat ( crochat@younics.org )
#
# ===========================================
#
# What you need:
#
# Linux :)
# awk
# screen
# the hlds_l & cstrike-files OR
# a STEAM-installation
#
# YES, this script works fine with STEAM and CS 1.6
#
# How to use:
#
# Edit the DIR-var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-var to fit your needs
# Edit the CS_USER-var to the name of the user that will run the server
#
# How to see the server-console:
#
# Just type in: screen -r hlds (or whatever you set $NAME to)
# More info about screen can be found by typing "man screen" or using this nice link
# http://server.counter-strike.net/server.php?cmd=howto&show=screen
#
# The easist way is to use this script simple as a start-script for your server
# If you want to use it as a script to start the server at boot-time:
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# (THIS IS FOR DEBIAN! If you use e.g. Redhat you must change these dirs!!!)
#
# ln -s /etc/init.d/asgard /etc/init.d/rc3.d/S90asgard
# ln -s /etc/init.d/asgard /etc/init.d/rc3.d/K50asgard
#
# Or use it manualy like:
# /etc/rc.d/init.d/hlds start
# /etc/rc.d/init.d/hlds stop
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
#
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)

# The user that will run the server
CS_USER=server

# Leave this alone.
NAME=asgard

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

# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/home/server/asgard

# Leave this alone.
DAEMON=srcds_run

# Internet-server:
PARAMS=" -autoupdate -game dod -debug +map dod_kalt -maxplayers 14 -ip 85.14.217.254 -port 27040 -tickrate 100"

# Leave this alone.
DESC="Asgard"

case "$1" in
start)
if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
then
echo "HLDS is already running!"
else
echo "Starting $DESC: $NAME"
su $CS_USER -c "cd $DIR; screen -m -d -S asgard ./$DAEMON $PARAMS"
fi
;;

stop)
if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;

restart)
if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `ps aux | grep -v grep | grep -i $CS_USER | grep -i screen | grep -i $NAME | awk '{print $2}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi

echo -n "Starting $DESC: $NAME"
su $CS_USER -c "cd $DIR; screen -m -d -S asgard ./$DAEMON $PARAMS"
echo " ... done."
;;

status)
ps aux | grep -v grep | grep hlds_r > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

exit 0


Hoffe ihr könnt mir da weiter helfen ;)

MfG NeroSpeed

nul
21-07-2006, 10:50
Ich denke die Richtigen Stichwoerter sind dabei sudo und exec [1]

[1] http://www.php.net/manual/de/function.exec.php