Commit 65882381 authored by Franco Fichtner's avatar Franco Fichtner

cron: stop polluting the config with redundant information

This makes it easier to migrate cron jobs in the future.  Still not
all callers converted, but we'll get there.  ;)
parent 8ff7c87f
...@@ -2345,6 +2345,34 @@ function configure_cron() ...@@ -2345,6 +2345,34 @@ function configure_cron()
{ {
global $config; global $config;
$obsoletes = array(
'/usr/local/etc/rc.backup_dhcpleases',
'/usr/local/etc/rc.backup_netflow',
'/usr/local/etc/rc.backup_rrd',
);
foreach ($obsoletes as $obsolete) {
/*
* Strip old cron jobs that we no longer save explicitly.
* This can be savely removed on our final road to 17.1.
*/
install_cron_job($obsolete, false);
}
$autocron = array();
if (!empty($config['system']['rrdbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_rrd', $minute = '0', '*/' . $config['system']['rrdbackup']);
}
if (!empty($config['system']['dhcpbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_dhcpleases', $minute = '0', '*/' . $config['system']['dhcpbackup']);
}
if (!empty($config['system']['netflowbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_netflow', $minute = '0', '*/' . $config['system']['netflowbackup']);
}
$anchor = '# custom crontab entries'; $anchor = '# custom crontab entries';
/* preserve existing crontab entries */ /* preserve existing crontab entries */
...@@ -2367,7 +2395,7 @@ function configure_cron() ...@@ -2367,7 +2395,7 @@ function configure_cron()
$crontab_contents .= '# auto-generated at ' . date('F j, Y, g:i a') . "\n"; $crontab_contents .= '# auto-generated at ' . date('F j, Y, g:i a') . "\n";
$crontab_contents .= "#\n"; $crontab_contents .= "#\n";
foreach ($config['cron']['item'] as $item) { foreach (array_merge($config['cron']['item'], $autocron) as $item) {
$crontab_contents .= "\n{$item['minute']}\t"; $crontab_contents .= "\n{$item['minute']}\t";
$crontab_contents .= "{$item['hour']}\t"; $crontab_contents .= "{$item['hour']}\t";
$crontab_contents .= "{$item['mday']}\t"; $crontab_contents .= "{$item['mday']}\t";
...@@ -2389,6 +2417,21 @@ function configure_cron() ...@@ -2389,6 +2417,21 @@ function configure_cron()
killbypid('/var/run/cron.pid', 'HUP'); killbypid('/var/run/cron.pid', 'HUP');
} }
function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*', $month = '*', $weekday = '*', $who = 'root')
{
$cron_item = array();
$cron_item['minute'] = $minute;
$cron_item['hour'] = $hour;
$cron_item['mday'] = $monthday;
$cron_item['month'] = $month;
$cron_item['wday'] = $weekday;
$cron_item['who'] = $who;
$cron_item['command'] = $command;
return $cron_item;
}
function install_cron_job($command, $active=false, $minute="0", $hour="*", $monthday="*", $month="*", $weekday="*", $who="root") { function install_cron_job($command, $active=false, $minute="0", $hour="*", $monthday="*", $month="*", $weekday="*", $who="root") {
global $config; global $config;
...@@ -2411,14 +2454,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont ...@@ -2411,14 +2454,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont
} }
if ($active) { if ($active) {
$cron_item = array(); $cron_item = generate_cron_job($command, $minute, $hour, $monthday, $month, $weekday, $who);
$cron_item['minute'] = $minute;
$cron_item['hour'] = $hour;
$cron_item['mday'] = $monthday;
$cron_item['month'] = $month;
$cron_item['wday'] = $weekday;
$cron_item['who'] = $who;
$cron_item['command'] = $command;
if (!$is_installed) { if (!$is_installed) {
$config['cron']['item'][] = $cron_item; $config['cron']['item'][] = $cron_item;
write_config(sprintf(gettext("Installed cron job for %s"), $command)); write_config(sprintf(gettext("Installed cron job for %s"), $command));
......
...@@ -38,31 +38,6 @@ require_once("pfsense-utils.inc"); ...@@ -38,31 +38,6 @@ require_once("pfsense-utils.inc");
require_once("services.inc"); require_once("services.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
function install_backup_cron_jobs()
{
global $config;
/* XXX still not overly pretty */
if (!empty($config['system']['rrdbackup'])) {
install_cron_job("/usr/local/etc/rc.backup_rrd", ($config['system']['rrdbackup'] > 0), $minute = "0", "*/{$config['system']['rrdbackup']}");
} else {
install_cron_job('/usr/local/etc/rc.backup_rrd', false);
}
if (!empty($config['system']['dhcpbackup'])) {
install_cron_job("/usr/local/etc/rc.backup_dhcpleases", ($config['system']['dhcpbackup'] > 0), $minute = "0", "*/{$config['system']['dhcpbackup']}");
} else {
install_cron_job('/usr/local/etc/rc.backup_dhcpleases', false);
}
if (!empty($config['system']['netflowbackup'])) {
install_cron_job("/usr/local/etc/rc.backup_netflow", ($config['system']['netflowbackup'] > 0), $minute = "0", "*/{$config['system']['netflowbackup']}");
} else {
install_cron_job('/usr/local/etc/rc.backup_netflow', false);
}
}
function crypto_modules() function crypto_modules()
{ {
$modules = array( $modules = array(
...@@ -235,7 +210,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -235,7 +210,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
system_resolvconf_generate(true); system_resolvconf_generate(true);
install_backup_cron_jobs();
configure_cron(); configure_cron();
filter_configure(); filter_configure();
activate_powerd(); activate_powerd();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment