function _hosting_setup_cron in Hosting 7.3
Same name and namespace in other branches
- 5 hosting.module \_hosting_setup_cron()
- 6.2 hosting.module \_hosting_setup_cron()
- 7.4 hosting.module \_hosting_setup_cron()
Set up the hosting-dispatch command in the aegir user's crontab.
Replace the crontab entry if it exists, else create it from scratch.
2 calls to _hosting_setup_cron()
- drush_hosting_pause in ./
pause.hosting.inc - Drush command to pause the Aegir frontend queues.
- drush_hosting_setup in ./
hosting.module - Initial hosting setup drush command.
File
- ./
hosting.module, line 739 - Hosting module.
Code
function _hosting_setup_cron($add = TRUE) {
$existing = FALSE;
$cron = '';
$cron_lines = array();
// Load any existing crontab.
exec('crontab -l 2> /dev/null', $cron_lines);
variable_set('hosting_cron_backup', $cron_lines);
if (count($cron_lines)) {
drush_log(dt("Replacing existing crontab"), 'notice');
$cron_lines = hosting_queues_cron_removal($cron_lines);
$cron = implode("\n", $cron_lines);
}
else {
drush_log(dt("No existing crontab was found"), 'message');
}
if ($add) {
// Append the fresh Aegir specific lines.
$cron .= "\n" . hosting_queues_cron_cmd();
drush_log(dt("Adding hosting-dispatch cron entry to run every minute"), 'ok');
}
// Write a new crontab.
$fp = popen('crontab -', 'w');
$success = TRUE;
if ($fp) {
if (fwrite($fp, $cron) && fwrite($fp, "\n")) {
$success = TRUE;
}
else {
$success = FALSE;
}
// 'pclose' returns shell exit codes (ie. 0 is success).
if (pclose($fp)) {
$success = FALSE;
}
}
else {
$success = FALSE;
}
if ($success) {
drush_log(dt("Installed a new crontab entry."), 'success');
}
else {
drush_set_error('PROVISION_CRON_FAILED', dt('Failed to install cron job'));
}
}