ID:40251
 
Keywords: tibscript
Now, if you're like me and you have a server capable of running BYOND but a host that likes to kill processes once they get over a specific amount CPU usage, you'll know the tiresome pain that is relaunching games when you wake up in the morning (or if you're like me... afternoon).

Not only is this a repetitive and tiresome process, but it also kills your players morale. Your server starts getting popular, players are having a good time and BAM, no more server. This especially kicks in if you're limited on funds and can't afford a server where you have more control.

Well, a small solution is to relaunch DreamDaemon automatically. And here is a small script I whipped up to do so.

<?
$port_num = 55678; //The port in which you want to host the game on.

$a = shell_exec("netstat -nlt | grep $port_num"); //Check to see if that port is already in use. Or DreamDaemon is still running.
if(!$a) { //If it isn't, relaunch DreamDaemon.
popen("DreamDaemon path/to/your/game.dmb $port_num -trusted &", "r");
}
?>


Now that works all fine and dandy, but what about automating that script for a set time limit. I attempted to do this using a Cron Job. But it didn't work. (Audeuro has an untested script to make it work, and once I've tested that, I'll post it here.)

Automating the script needed a finer approach. Seeing as CronDaemon wasn't successfully doing it, I needed something else to kick in. And that's where I sought assistance from BYOND's local Python Guru, Crashed.

With a little script he whipped up (able to work with Python 2.2 and onwards) we were able to automate it.

from time import sleep 
import os
while True:
os.popen('php my_php_file.php')
sleep(1800) #seconds


To execute the script, open up your command line client (in my case, PuTtY) and execute it like so: python my_python_file.py &
If the BYOND server isn't running, you'll receive DreamDaemon's execution message. Then type exit and logout.

Now, that script there will run your PHP script every half an hour to check up on your DreamDaemon. Ever looking to improve it, I'll be revising this script at a later date to check on it all. But at the moment, that should do the trick (it's working so far for me).

I should also say, that script will only work provided both the python and php script are inside your root folder (that is, the one before public_html).
Hey, I am trying to get this to work and am running into a problem in shell and was hoping you could help me. I type in [python autolaunch.py] and it comes back with [sh: autolaunch.php: command not found] I modified only the spots that needed it like the game location and port number. Any help would be appricated
Thanks
Winchester
I'm not following. The python file is the file that should be executed from the shell.

The idea is: Python file is on a continuous loop and calls the PHP file every time the loop runs through.

Calling it is just a matter of:
python myfile.py &
what it is saying is that the python file when running can't find the command in the PHP file I think, yet the file looks correct to me.
Tiberath wrote:
I'm not following. The python file is the file that should be executed from the shell.

The idea is: Python file is on a continuous loop and calls the PHP file every time the loop runs through.

Calling it is just a matter of:
python myfile.py &

"[python autolaunch.py]"

You didn't include the ampersand at the end. It's necessary to keep the script running.

Python wont return errors for PHP. Make sure both Python and PHP are installed on your server.