Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

PHP script for starting/stopping custom services

gsrdgrdghdgsrdgrdghd Member
edited November 2011 in General

Hey
I have a LEB with some game servers on it. However i can't run all the gameservers at the same time because of CPU/RAM usage so i just turn them on and off when i need them.
Is there some PHP script that would let me do this via a webinterface? Most gameservers have custom startup scripts and run inside a screen. The script would just have to be able to start/stop a service and tell if it was running.
Thanks in advance

Comments

  • Cron maybe?

    Really depends on the specific gameservers that you are trying to run. Some of them have either built in functions that will allow you to do this and/or requirements that mean that they shouldn't be started in such a way.

  • Just use shell_exec.

    If you need it to gain root, use ssh2 on localhost.

  • @drmike said: Cron maybe?

    Nah i don't want them to be started/stopped at certain times/intervalls.
    I am running 2 HL2 based servers (Killing Floor and Pirates, Vikings and Knights), Minecraft and Battlefield 1942. Usually i run the servers like this:
    screen -S pvkii ./srcds_i486 -game pvkii +map bt_island +maxplayers 18 -console -autoupdate -secure

    @Daniel said: Just use shell_exec.

    That looks good to start the servers, but i don't know how i could use it to check if a server is running or stop it.

  • mrm2005mrm2005 Member
    edited November 2011

    Hi,

    Google found these:

    For Minecraft :
    http://www.minecraftwiki.net/wiki/Multicraft

    for HL2 (may also works with minecraft too):
    http://sourceforge.net/projects/hldstart/

    and a commercial package : http://www.servergears.net/

  • @gsrdgrdghd said: That looks good to start the servers, but i don't know how i could use it to check if a server is running or stop it.

    Pidfiles. look some init scripts and use the same strategy (or check start-stop-daemon, on debian).

  • Why not create a bash file? (.sh)
    And can i ask wich VPS you got and from wich Provider?

  • MrAndroidMrAndroid Member
    edited November 2011

    I used these sort of commands for my Minecraft Panel, they will probably be useful.

    Submitting Text/Command (e.g. send save to a game server) to a Screen Session - screen -p 0 -S (screen name) -X eval 'stuff \"save\"\015'

    Checking if a Program is Online - ps ax | grep -v grep | grep -v -i SCREEN | grep (binary name)

  • That would mean checking once for each.

    ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS |tail -n1

    That will show the process using the most memory (aka the game server) running a l4d server it shows

    324600 ./srcds_linux l4d -autoupdate +ip ........ etc (the whole command used to start the server)

    Then in PHP look for the game, in this case l4d - if you get a match its running

  • LongShotLongShot Member
    edited November 2011

    Web-based Webmin has a module that allows you to start/stop programs by clicking on a button.

  • LongShotLongShot Member
    edited November 2011

    I run my game servers using the "nohup" prefix on the command line (not "screen"). Is there an advantage to using "screen"?

  • you can reattach a screen if needed. For game servers it may be useful to see output but i highly doubt it.

    Webmin will be doing something similar to one of the commands shown in this thread

Sign In or Register to comment.