| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\Cron; |
| 4 |
|
| 5 |
/* |
| 6 |
|
| 7 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 8 |
Copyright (C) 2024 Roland Gruber |
| 9 |
|
| 10 |
This program is free software; you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 2 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
|
| 24 |
*/ |
| 25 |
|
| 26 |
use LAMConfig; |
| 27 |
use LAMException; |
| 28 |
use ServerProfilePersistenceManager; |
| 29 |
|
| 30 |
/** |
| 31 |
* Global cron job for LAM. |
| 32 |
* |
| 33 |
* @package jobs |
| 34 |
* @author Roland Gruber |
| 35 |
*/ |
| 36 |
|
| 37 |
/** config */ |
| 38 |
include_once(__DIR__ . "/config.inc"); |
| 39 |
/** cron runner */ |
| 40 |
include_once(__DIR__ . "/cronRunner.inc"); |
| 41 |
|
| 42 |
// check parameters |
| 43 |
$isDryRun = isset($argv) && (in_array('--dryRun', $argv) || in_array('--dry-run', $argv)); |
| 44 |
$cronRunner = new CronRunner($isDryRun); |
| 45 |
|
| 46 |
$runGlobalActions = isset($argv[2]) && ($argv[2] === 'global'); |
| 47 |
$runSingleServerProfileActions = isset($argv[2]) && ($argv[2] === 'serverProfile'); |
| 48 |
$runAll = isset($argv[2]) && ($argv[2] === 'all'); |
| 49 |
if ($runAll) { |
| 50 |
try { |
| 51 |
$cronRunner->runGlobalCronJobs(); |
| 52 |
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); |
| 53 |
foreach ($serverProfilePersistenceManager->getProfiles() as $serverProfile) { |
| 54 |
$cronRunner->runSingleServerProfileActions($serverProfile); |
| 55 |
} |
| 56 |
} |
| 57 |
catch (LAMException $e) { |
| 58 |
echo escapeshellcmd($e->getTitle()) . "\n"; |
| 59 |
exit(1); |
| 60 |
} |
| 61 |
} |
| 62 |
elseif ($runGlobalActions) { |
| 63 |
try { |
| 64 |
$cronRunner->runGlobalCronJobs(); |
| 65 |
} |
| 66 |
catch (LAMException $e) { |
| 67 |
echo escapeshellcmd($e->getTitle()) . "\n"; |
| 68 |
exit(1); |
| 69 |
} |
| 70 |
} |
| 71 |
elseif ($runSingleServerProfileActions && !empty($argv[3]) && LAMConfig::isValidName($argv[3])) { |
| 72 |
try { |
| 73 |
$cronRunner->runSingleServerProfileActions($argv[3]); |
| 74 |
} |
| 75 |
catch (LAMException $e) { |
| 76 |
echo escapeshellcmd($e->getTitle()) . "\n"; |
| 77 |
exit(1); |
| 78 |
} |
| 79 |
} |
| 80 |
else { |
| 81 |
echo "LAM - Run cron jobs\n" |
| 82 |
. "\n" |
| 83 |
. "Usage:\n" |
| 84 |
. "\n" |
| 85 |
. "Run all cron jobs (global and server profiles):\n" |
| 86 |
. "\n" |
| 87 |
. " runCronJobs.sh all\n" |
| 88 |
. "\n" |
| 89 |
. "Run all cron jobs (global and server profiles) in dry-run:\n" |
| 90 |
. "\n" |
| 91 |
. " runCronJobs.sh all --dry-run\n" |
| 92 |
. "\n" |
| 93 |
. "Run all global cron jobs:\n" |
| 94 |
. "\n" |
| 95 |
. " runCronJobs.sh global\n" |
| 96 |
. "\n" |
| 97 |
. "Run all global cron jobs in dry-run:\n" |
| 98 |
. "\n" |
| 99 |
. " runCronJobs.sh global --dry-run\n" |
| 100 |
. "\n" |
| 101 |
. "Run cron jobs of a server profile:\n" |
| 102 |
. "\n" |
| 103 |
. " runCronJobs.sh serverProfile NAME\n" |
| 104 |
. "\n" |
| 105 |
. "Run cron jobs of a server profile in dry-run:\n" |
| 106 |
. "\n" |
| 107 |
. " runCronJobs.sh serverProfile NAME --dry-run\n" |
| 108 |
. "\n" |
| 109 |
. "Run cron jobs of all server profiles:\n" |
| 110 |
. "\n" |
| 111 |
. " runCronJobs.sh allServerProfiles\n" |
| 112 |
. "\n" |
| 113 |
. "Run cron jobs of all server profiles in dry-run:\n" |
| 114 |
. "\n" |
| 115 |
. " runCronJobs.sh allServerProfiles --dry-run\n" |
| 116 |
. "\n" |
| 117 |
. "\n"; |
| 118 |
} |