Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
do_actions.php File Reference

Go to the source code of this file.

Functions

 d ($mess)
 mail_it ()
 execute_cmd ($command, $parameters=array())

Variables

 $debug = 1
 This script check the MySQL DB for actions to do, and do them one by one.
 $error_raise = ''
 $LOCK_FILE = '/var/run/alternc/do_actions_cron.lock'
 $SCRIPT = '/usr/bin/php do_actions.php'
 $MY_PID = getmypid()
 $FIXPERM = '/usr/lib/alternc/fixperms.sh'

Function Documentation

d (   $mess)

Definition at line 54 of file do_actions.php.

References $debug.

{
global $debug;
if ($debug == 1)
echo "$mess\n";
}
execute_cmd (   $command,
  $parameters = array() 
)

Definition at line 71 of file do_actions.php.

References $parameters.

{
$cmd_line = "$command ";
if (!empty($parameters)) {
if (is_array($parameters)) {
foreach($parameters as $pp) {
$cmd_line.= " ".escapeshellarg($pp)." ";
}
} else {
$cmd_line.= " ".escapeshellarg($parameters)." " ;
}
}
$cmd_line.= " 2>&1";
exec($cmd_line, $output, $code);
return array('executed' => $cmd_line, 'output'=>$output, 'return_var'=>$code);
}
require_once("/usr/share/alternc/panel/class/config_nochk.php");
$admin->stop_if_jobs_locked();
$LOCK_FILE='/var/run/alternc/do_actions_cron.lock';
$SCRIPT='/usr/bin/php do_actions.php';
$MY_PID=getmypid();
$FIXPERM='/usr/lib/alternc/fixperms.sh';
// Check if script isn't already running
if (file_exists($LOCK_FILE) !== false){
d("Lock file already exists. ");
// Check if file is in process list
$PID=file_get_contents($LOCK_FILE);
d("My PID is $MY_PID, PID in the lock file is $PID");
if ($PID == exec("pidof $SCRIPT | tr ' ' '\n' | grep -v $MY_PID")){
// Previous cron is not finished yet, just exit
d("Previous cron is already running, we just exit and let it finish :-)");
exit(0);
}else{
// Previous cron failed!
$error_raise.="Lock file already exists. No process with PID $PID found! Previous cron failed...\n";
// No need to remove anything, we're going to recreate it
//d("Removing lock file and trying to process the failed action...");
// Delete the lock and continue to the next action
//unlink($LOCK_FILE);
// Lock with the current script's PID
if (file_put_contents($LOCK_FILE,$MY_PID) === false){
$error_raise.="Cannot open/write $LOCK_FILE\n";
exit(1);
}
// Get the action(s) that was processing when previous script failed
// (Normally, there will be at most 1 job pending... but who know?)
while($cc=$action->get_job()){
$c=$cc[0];
$params=unserialize($c["parameters"]);
// We can resume these types of action, so we reset the job to process it later
d("Previous job was the n°".$c["id"]." : '".$c["type"]."'");
if($c["type"] == "CREATE_FILE" && is_dir(dirname($params["file"])) || $c["type"] == "CREATE_DIR" || $c["type"] == "DELETE" || $c["type"] == "FIX_DIR" || $c["type"] == "FIX_FILE"){
d("Reset of the job! So it will be resumed...");
$action->reset_job($c["id"]);
}else{
// We can't resume the others types, notify the fail and finish this action
$error_raise.="Can't resume the job n°".$c["id"]." action '".$c["type"]."', finishing it with a fail status.\n";
if(!$action->finish($c["id"],"Fail: Previous script crashed while processing this action, cannot resume it.")){
$error_raise.="Cannot finish the action! Error while inserting the error value in the DB for action n°".$c["id"]." : action '".$c["type"]."'\n";
break; // Else we go into an infinite loop... AAAAHHHHHH
}
}
}
}
}else{
mail_it ( )

Definition at line 61 of file do_actions.php.

References $error_raise.

{
global $error_raise,$L_FQDN;
mail("alterncpanel@$L_FQDN",'Script do_actions.php issues',"\n Errors reporting mail:\n\n$error_raise");
}

Variable Documentation

$debug = 1

This script check the MySQL DB for actions to do, and do them one by one.

Definition at line 50 of file do_actions.php.

Referenced by d().

$error_raise = ''

Definition at line 51 of file do_actions.php.

Referenced by mail_it().

$FIXPERM = '/usr/lib/alternc/fixperms.sh'

Definition at line 94 of file do_actions.php.

$LOCK_FILE = '/var/run/alternc/do_actions_cron.lock'

Definition at line 91 of file do_actions.php.

$MY_PID = getmypid()

Definition at line 93 of file do_actions.php.

$SCRIPT = '/usr/bin/php do_actions.php'

Definition at line 92 of file do_actions.php.