[Bug 44314] New: koha-sitemap always exits 0, even when sitemap generation fails
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 Bug ID: 44314 Summary: koha-sitemap always exits 0, even when sitemap generation fails Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Packaging Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org CC: mtj@kohaaloha.com Target Milestone: --- koha-sitemap --generate always exits with status 0, even when sitemap.pl fails for an instance. generate_sitemap returns 1 on failure, but the main loop ignores it and the script ends with an unconditional "exit 0". As a result, a cron job like koha-sitemap --quiet --generate $(koha-list --enabled) never reports a failed sitemap generation: the job always succeeds and monitoring based on exit codes cannot notice that sitemaps are stale. Expected: * koha-sitemap exits with a non-zero status if generation failed for any of the given instances (it should still process the remaining instances). * The failure is reported on stderr, also with --quiet (which is meant to silence notices such as non-existent instance names, not errors). * Cases that are not failures keep exiting 0: instances without sitemap generation enabled, or no instance names at all (e.g. an empty koha-list output with --quiet). -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|koha-sitemap always exits |koha-sitemap stops at the |0, even when sitemap |first failure (or |generation fails |non-enabled instance with | |--quiet) and doesn't report | |errors Depends on| |44315 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Correction to the description: the actual behaviour on main is different from "always exits 0". 1. misc/cronjobs/sitemap.pl itself exits with status 0 when it fails (Koha::Sitemapper calls exit), so koha-sitemap never sees the failure. That is now bug 44315, which this bug depends on. 2. koha-sitemap runs with 'set -e', so the first generate_sitemap call returning non-zero ends the script, and the remaining instances are not processed. This also happens, with exit status 1, for instances that don't have sitemap generation enabled when --quiet is used (the function ends with '[ "$quiet" = "no" ] && warn ...', which returns 1). So koha-sitemap --quiet --generate $(koha-list --enabled) stops at the first instance without sitemaps enabled. The patch makes koha-sitemap: * treat instances without sitemap generation enabled as not an error (exit 0) * keep processing the remaining instances when generation fails for one, and exit 1 at the end if any failed * report each failure on stderr, also with --quiet * document the exit status in the man page Tested in KTD: not enabled (exit 0, silent with --quiet), success (exit 0), forced failure listing the instance twice (both processed, error reported twice, exit 1, also with --quiet), no instance names (exit 0). Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 [Bug 44315] Koha::Sitemapper exits with status 0 on errors -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212746 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212746&action=edit Bug 44314: Make koha-sitemap report failures and process all instances koha-sitemap runs with 'set -e', so a failing generate_sitemap call ended the script right there, without processing the remaining instances. This also happened, with exit status 1, for instances that don't have sitemap generation enabled when --quiet is used: the function ended with '[ "$quiet" = "no" ] && warn ...', which returns 1. As a result, the natural cron job koha-sitemap --quiet --generate $(koha-list --enabled) stopped at the first instance without sitemaps enabled. This patch: * Makes generate_sitemap return 0 for instances without sitemap generation enabled (not an error). * Keeps processing the remaining instances when generation fails for one of them, and exits with status 1 at the end if any failed (0 otherwise). * Reports each failure on stderr ("Error: sitemap generation failed for <instance>"), also with --quiet, which is meant to silence notices, not errors. * Documents the exit status in the man page. Test plan: 1. Apply this patch 2. Enable sitemaps for the instance and generate them: $ ktd --shell k$ sudo koha-sitemap --enable kohadev k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev ; echo "exit=$?" => SUCCESS: exit=0, /var/lib/koha/kohadev/sitemap/sitemapindex.xml exists 3. Make generation fail (a directory where the sitemap file should go) and repeat the command, listing the instance twice: k$ sudo rm -f /var/lib/koha/kohadev/sitemap/*.xml k$ sudo mkdir /var/lib/koha/kohadev/sitemap/sitemap_0001.xml k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev kohadev ; echo "exit=$?" => SUCCESS: "Error: sitemap generation failed for kohadev" is shown twice (both are processed) and exit=1 4. Disable sitemaps and generate with --quiet: k$ sudo koha-sitemap --disable kohadev k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev ; echo "exit=$?" => SUCCESS: No output, exit=0 (on main: exit=1) 5. Clean up: k$ sudo rm -rf /var/lib/koha/kohadev/sitemap 6. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212746|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 --- Comment #3 from David Nind <david@davidnind.com> --- Created attachment 212752 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212752&action=edit Bug 44314: Make koha-sitemap report failures and process all instances koha-sitemap runs with 'set -e', so a failing generate_sitemap call ended the script right there, without processing the remaining instances. This also happened, with exit status 1, for instances that don't have sitemap generation enabled when --quiet is used: the function ended with '[ "$quiet" = "no" ] && warn ...', which returns 1. As a result, the natural cron job koha-sitemap --quiet --generate $(koha-list --enabled) stopped at the first instance without sitemaps enabled. This patch: * Makes generate_sitemap return 0 for instances without sitemap generation enabled (not an error). * Keeps processing the remaining instances when generation fails for one of them, and exits with status 1 at the end if any failed (0 otherwise). * Reports each failure on stderr ("Error: sitemap generation failed for <instance>"), also with --quiet, which is meant to silence notices, not errors. * Documents the exit status in the man page. Test plan: 1. Apply this patch 2. Enable sitemaps for the instance and generate them: $ ktd --shell k$ sudo koha-sitemap --enable kohadev k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev ; echo "exit=$?" => SUCCESS: exit=0, /var/lib/koha/kohadev/sitemap/sitemapindex.xml exists 3. Make generation fail (a directory where the sitemap file should go) and repeat the command, listing the instance twice: k$ sudo rm -f /var/lib/koha/kohadev/sitemap/*.xml k$ sudo mkdir /var/lib/koha/kohadev/sitemap/sitemap_0001.xml k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev kohadev ; echo "exit=$?" => SUCCESS: "Error: sitemap generation failed for kohadev" is shown twice (both are processed) and exit=1 4. Disable sitemaps and generate with --quiet: k$ sudo koha-sitemap --disable kohadev k$ sudo bash debian/scripts/koha-sitemap --quiet --generate kohadev ; echo "exit=$?" => SUCCESS: No output, exit=0 (on main: exit=1) 5. Clean up: k$ sudo rm -rf /var/lib/koha/kohadev/sitemap 6. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |`koha-sitemap --generate` release notes| |now processes every | |instance it is given and | |reports failures. | |Previously it stopped at | |the first instance that | |failed, leaving the | |remaining ones without a | |new sitemap. With | |`--quiet`, an instance that | |doesn't have sitemap | |generation enabled also | |stopped it, with exit | |status 1, so a cron job | |like `koha-sitemap --quiet | |--generate $(koha-list | |--enabled)` broke on | |servers where not every | |instance uses sitemaps. | | | |Instances without sitemap | |generation enabled are now | |skipped, each failure is | |reported on STDERR (also | |with `--quiet`), and the | |command exits with status 1 | |if generation failed for | |any instance, and 0 | |otherwise. The exit status | |is documented in the man | |page. Together with bug | |44315, failed sitemap | |generations can now be | |caught by monitoring based | |on exit codes. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org