use /etc/crontab directly when on FreeBSD because it does not use anything like /etc/cron.d/ file-inclusion, refs and possibly fixes #1437

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2014-10-31 09:48:38 +01:00
parent 0156c3a59d
commit f303bfdbfd
3 changed files with 38 additions and 6 deletions

View File

@@ -32,9 +32,14 @@ function checkCrondConfigurationFile() {
if ($num_results > 0) {
// get all crons and their intervals
$cronfile = "# automatically generated cron-configuration by froxlor\n";
$cronfile.= "# do not manually edit this file as it will be re-generated periodically.\n";
$cronfile.= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n";
if (isFreeBSD()) {
// FreeBSD does not need a header as we are writing directly to the crontab
$cronfile = "\n";
} else {
$cronfile = "# automatically generated cron-configuration by froxlor\n";
$cronfile.= "# do not manually edit this file as it will be re-generated periodically.\n";
$cronfile.= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n";
}
// get all the crons
$result_stmt = Database::query("
@@ -90,10 +95,37 @@ function checkCrondConfigurationFile() {
}
}
if (isFreeBSD()) {
// FreeBSD handles the cron-stuff in another way. We need to directly
// write to the crontab file as there is not cron.d/froxlor file
// (settings for system.cronconfig should be set correctly of course)
$crontab = file_get_contents(Settings::Get("system.cronconfig"));
if ($crontab === false) {
die("Oh snap, we cannot read the crontab file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// now parse out / replace our entries
$crontablines = explode("\n", $crontab);
$newcrontab = "";
foreach ($crontablines as $ctl) {
$ctl = trim($ctl);
if (!empty($ctl) && !preg_match("/(.*)froxlor_master_cronjob\.php(.*)/", $ctl)) {
$newcrontab .= $ctl."\n";
}
}
// re-assemble old-content + new froxlor-content
$newcrontab .= $cronfile;
// now continue with writing the file
$cronfile = $newcrontab;
}
// write the file
if (file_put_contents(Settings::Get("system.cronconfig"), $cronfile) === false) {
// oh snap cannot create new crond-file
die("Oh snap, we cannot create the cron.d file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
die("Oh snap, we cannot create the cron-file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n");
}
// correct permissions
chmod(Settings::Get("system.cronconfig"), 0640);

View File

@@ -1800,7 +1800,7 @@ $lng['serversettings']['mtalog']['description'] = "Logfile of the Mail Transfer
$lng['panel']['ftpdesc'] = 'FTP description';
$lng['admin']['cronsettings'] = 'Cronjob settings';
$lng['serversettings']['system_cronconfig']['title'] = 'Cron configuration file';
$lng['serversettings']['system_cronconfig']['description'] = 'Path to the cron-service configuration-file. This file will be updated regularly and automatically by froxlor.<br />Note: Please <b>be sure</b> to use the same filename as for the main froxlor cronjob (default: /etc/cron.d/froxlor)!';
$lng['serversettings']['system_cronconfig']['description'] = 'Path to the cron-service configuration-file. This file will be updated regularly and automatically by froxlor.<br />Note: Please <b>be sure</b> to use the same filename as for the main froxlor cronjob (default: /etc/cron.d/froxlor)!<br><br>If you are using <b>FreeBSD</b>, please specify <i>/etc/crontab</i> here!';
$lng['tasks']['remove_ftpacc_files'] = 'Delete customer ftp-account data.';
$lng['tasks']['regenerating_crond'] = 'Rebuilding the cron.d-file';
$lng['serversettings']['system_crondreload']['title'] = 'Cron-daemon reload command';

View File

@@ -1524,7 +1524,7 @@ $lng['serversettings']['mtalog']['description'] = "Die Logdatei des Mail Transfe
$lng['panel']['ftpdesc'] = 'FTP-Beschreibung';
$lng['admin']['cronsettings'] = 'Cronjob-Einstellungen';
$lng['serversettings']['system_cronconfig']['title'] = 'Cron-Konfigurationsdatei';
$lng['serversettings']['system_cronconfig']['description'] = 'Pfad zur Konfigurationsdatei des Cron-Dienstes. Diese Datei wird von Froxlor automatisch aktualisiert.<br />Hinweis: Bitte verwenden Sie <strong>exakt</strong> die gleiche Datei wie für den Froxlor-Haupt-Cronjob (Standard: /etc/cron.d/froxlor)!';
$lng['serversettings']['system_cronconfig']['description'] = 'Pfad zur Konfigurationsdatei des Cron-Dienstes. Diese Datei wird von Froxlor automatisch aktualisiert.<br />Hinweis: Bitte verwenden Sie <strong>exakt</strong> die gleiche Datei wie für den Froxlor-Haupt-Cronjob (Standard: /etc/cron.d/froxlor)!<br><br>Wird <b>FreeBSD</b> verwendet, sollte hier <i>/etc/crontab</i> angegeben werden!';
$lng['tasks']['remove_ftpacc_files'] = 'Kunden FTP-Konto Dateien löschen';
$lng['tasks']['regenerating_crond'] = 'Neuerstellung der cron.d-Datei';
$lng['serversettings']['system_crondreload']['title'] = 'Cron-Daemon reload Befehl';