The specific line of code that I can't figure out how to make it work is:
exec('/home/SFS2X/sfs2x-service start',$output2);
Has anyone got experience of PHP exec commands / cron jobs. This is run as root as a cron job every minute.
Code: Select all
<?
date_default_timezone_set('Europe/London');
include("globals.php");
$query = mysqli_query($conn,'SELECT * FROM emergency');
if(mysqli_num_rows($query)>0) {
$delete = mysqli_query($conn,'DELETE FROM emergency WHERE 1');
exec('ps aux', $output);
// Go through all the output from ps aux to find one that is owned by root and is java
for($i=0;$i<sizeof($output);$i++)
{
if(strpos($output[$i],'/usr/bin/java')>0) {
$findNextNonNull = false;
$processID = 0;
$details = explode(' ',$output[$i]);
for($i2=0;$i2<sizeof($details);$i2++) {
if($details[$i2]=='root') {
$findNextNonNull = true;
} else {
if($findNextNonNull) {
if(strlen($details[$i2])>0) {
$processID = $details[$i2];
echo $processID;
// Kill the process, this bit works
exec('kill -9 '. $processID.'',$output1);
echo '<h1>Output from sig kill</h1>';
var_dump($output1);
sleep(5);
echo '<h1>Rebooting Server</h1>';
// This bit doesn't work...
exec('/home/SFS2X/sfs2x-service start',$output2);
var_dump($output2);
exit;
}
}
}
}
}
}
}
?>