Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/346 unify cron start scripts #377

Merged
merged 9 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lam-packaging/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ldap-account-manager (9.0.RC1-1) unstable; urgency=medium

* new upstream release

-- Roland Gruber <[email protected]> Wed, 19 Oct 2024 19:23:11 +0200

ldap-account-manager (8.9-1) unstable; urgency=medium

* new upstream release
Expand Down
2 changes: 2 additions & 0 deletions lam-packaging/docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ LDAP_USER=cn=admin,dc=my-domain,dc=com
LAM_LANG=en_US
# LAM configuration master password and password for server profile "lam"
LAM_PASSWORD=lam
# run cron jobs (LAM Pro)
LAM_CONFIGURE_CRON=false

# configuration database (files or mysql)
LAM_CONFIGURATION_DATABASE=files
Expand Down
1 change: 1 addition & 0 deletions lam-packaging/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ RUN apt-get install --no-install-recommends -y \
php-phpseclib3 \
php-voku-portable-ascii \
libphp-phpmailer \
cron \
&& \
rm /etc/apache2/sites-enabled/*default* && \
rm -rf /var/cache/apt /var/lib/apt/lists/*
Expand Down
7 changes: 7 additions & 0 deletions lam-packaging/docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ EOF

fi

LAM_CONFIGURE_CRON="${LAM_CONFIGURE_CRON:-false}"
if [ "$LAM_CONFIGURE_CRON" = "true" ]; then
echo "Configuring Cron"
echo "0 0 * * * www-data /usr/share/ldap-account-manager/lib/runCronJobs.sh all" > /etc/cron.d/ldap-account-manager
/usr/sbin/cron
fi

echo "Starting Apache"
rm -f /run/apache2/apache2.pid
set +u
Expand Down
2 changes: 2 additions & 0 deletions lam/HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ December 2024 9.0
-> Custom scripts: support custom label for module (329)
-> Custom scripts: support grouping of manual scripts (329)
-> Custom scripts: allow interactive parameters for manual scripts (327)
-> Cron jobs: new script to run all types of cron jobs (runCronJobs.sh), the scripts cron.sh and cronGlobal.sh are deprecated
-> Docker: added option to run cron jobs (346)
- Fixed bugs:
-> Windows: show more than 1000 LDAP entries when paged results is activated in server profile
-> WebAuthn: support DNs larger than 64 bytes (358)
Expand Down
2 changes: 1 addition & 1 deletion lam/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.9
9.0.RC1
4 changes: 2 additions & 2 deletions lam/docs/manual-sources/chapter-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +1302,9 @@ mysql&gt; GRANT ALL PRIVILEGES ON lam_cron.* TO 'lam_cron'@'localhost';

<para>Dry-run: You can perform a dry-run of the job. This will not
perform any actions but only print what would be done. For this please
put "--dryRun" at the end of the command. E.g.:</para>
put "--dry-run" at the end of the command. E.g.:</para>

<literallayout> /usr/share/ldap-account-manager/lib/cron.sh lam 123456789 --dryRun</literallayout>
<literallayout> /usr/share/ldap-account-manager/lib/runCronJobs.sh serverProfile lam --dry-run</literallayout>

<para/>
</section>
Expand Down
8 changes: 8 additions & 0 deletions lam/docs/manual-sources/chapter-installation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,14 @@
<para>Cron jobs of server profiles no longer use the job token
parameter</para>
</listitem>

<listitem>
<para>cron.sh and cronGlobal.sh are deprecated and will be removed
in the next release. Use the new command "runCronJobs.sh". E.g.
"runCronJobs.sh all" will run all global jobs and all server
profile jobs. Execute "runCronJobs.sh" to get a list of possible
options.</para>
</listitem>
</itemizedlist>
</section>

Expand Down
77 changes: 27 additions & 50 deletions lam/lib/cronGlobal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,47 @@

namespace LAM\Cron;

use Exception;
use LAM\DB\CronDatabase;
use LAMCfgMain;
use LAMConfig;
use LAMException;
use PDOException;
use Ldap;
use LAM\JOB\JobResultLog;
use ServerProfilePersistenceManager;

/*

This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2024 Roland Gruber
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2024 Roland Gruber

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

use LAMException;

/**
* Global cron job for LAM.
*
* @package jobs
* @author Roland Gruber
*/

/** access to configuration data */
include_once(__DIR__ . "/config.inc");
/** access to ldap data */
include_once(__DIR__ . "/ldap.inc");
/** access to modules */
include_once(__DIR__ . "/modules.inc");
/** cron runner */
include_once(__DIR__ . "/cronRunner.inc");

// check parameters
$isDryRun = (isset($argv[2]) && ($argv[2] == '--dryRun')) ? true : false;

$_SESSION['cfgMain'] = new LAMCfgMain();

if ($isDryRun) {
echo "Dry run: no changes, only logging.\n";
}
$isDryRun = isset($argv[2]) && ($argv[2] === '--dryRun');

// execute jobs
$errorsOccurred = false;
$allModules = getAllModules();
foreach ($allModules as $module) {
if (!$module->supportsGlobalCronJob()) {
continue;
}
try {
if ($isDryRun) {
echo "Started actions for " . $module->get_alias() . "\n";
}
logNewMessage(LOG_NOTICE, 'Started actions for ' . $module->get_alias());
$module->runGlobalCronActions($isDryRun);
if ($isDryRun) {
echo "Finished actions for " . $module->get_alias() . "\n";
}
logNewMessage(LOG_NOTICE, 'Finished actions for ' . $module->get_alias());
}
catch (Exception $e) {
$errorsOccurred = true;
echo "Error in " . $module->get_alias() . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
}
$cronRunner = new CronRunner($isDryRun);
try {
$cronRunner->runGlobalCronJobs();
}
if ($errorsOccurred) {
echo "Problems occurred during cron execution\n";
die(1);
catch (LAMException $e) {
echo escapeshellcmd($e->getTitle()) . "\n";
exit(1);
}
Loading
Loading