ajax::success(); } if (init('action') == 'remove') { $cron = cron::byId(init('id')); if (!is_object($cron)) { throw new Exception(__('Cron id inconnu', __FILE__)); } $cron->remove(); ajax::success(); } if (init('action') == 'all') { $results = array(); $results['crons'] = utils::o2a(cron::all(true)); $results['nbCronRun'] = cron::nbCronRun(); $results['nbProcess'] = cron::nbProcess(); $results['nbMasterCronRun'] = cron::jeeCronRun() ? 1 : 0; $results['loadAvg'] = cron::loadAvg(); ajax::success($results); } if (init('action') == 'start') { $cron = cron::byId(init('id')); if (!is_object($cron)) { throw new Exception(__('Cron id inconnu', __FILE__)); } $cron->run(); sleep(1); ajax::success(); } if (init('action') == 'stop') { $cron = cron::byId(init('id')); if (!is_object($cron)) {
public static function stop() { try { echo "Desactivation de toutes les tâches"; config::save('enableCron', 0); foreach (cron::all() as $cron) { if ($cron->running()) { try { $cron->halt(); echo '.'; } catch (Exception $e) { sleep(5); $cron->halt(); } } } echo " OK\n"; } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo "\n***ERREUR*** " . $e->getMessage(); } } /* * **********Arret des crons********************* */ try { if (cron::jeeCronRun()) { echo "Arret du cron master "; $pid = cron::getPidFile(); $kill = posix_kill($pid, 15); if (!$kill) { $kill = posix_kill($pid, 9); if (!$kill) { throw new Exception('Impossible d\'arrêter le cron master : ' . $pid); } } echo " OK\n"; } } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo '***ERREUR*** ' . $e->getMessage(); } } /* * *********Arrêt des scénarios**************** */ try { echo "Désactivation de tous les scénarios"; config::save('enableScenario', 0); foreach (scenario::all() as $scenario) { try { $scenario->stop(); echo '.'; } catch (Exception $e) { sleep(5); $scenario->stop(); } } echo " OK\n"; } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo '***ERREUR*** ' . $e->getMessage(); } } }
die; } catch (Exception $e) { $cron->setState('error'); $cron->setPID(''); $cron->setServer(''); $cron->setDuration(-1); $cron->save(); $logicalId = config::genKey(); if ($e->getCode() != 0) { $logicalId = $cron->getName() . '::' . $e->getCode(); } echo '[Erreur] ' . $cron->getName() . ' : ' . print_r($e, true); log::add('cron', 'error', __('Erreur sur ', __FILE__) . $cron->getName() . ' : ' . print_r($e, true), $logicalId); } } else { if (cron::jeeCronRun()) { die; } $sleepTime = config::byKey('cronSleepTime'); $started = jeedom::isStarted(); set_time_limit(59); cron::setPidFile(); while (true) { if (config::byKey('enableCron', 'core', 1, true) == 0) { die(__('Tous les crons sont actuellement désactivés', __FILE__)); } foreach (cron::all() as $cron) { try { if (!$started && $cron->getClass() != 'jeedom' && $cron->getFunction() != 'cron') { continue; }