Skip to content

Commit

Permalink
nixos/spamassassin: Handle return codes correctly
Browse files Browse the repository at this point in the history
For sa-update we care about two successful codes:

 * 1 -> no updates available: exit successfully
 * 0 -> updates have been installed: run sa-compile and pass
   through its return code
  • Loading branch information
pkern committed Feb 11, 2021
1 parent c86b339 commit 8854b82
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions nixos/modules/services/mail/spamassassin.nix
Expand Up @@ -136,19 +136,26 @@ in
Group = "spamd";
StateDirectory = "spamassassin";
ExecStartPost = "+${pkgs.systemd}/bin/systemctl -q --no-block try-reload-or-restart spamd.service";
SuccessExitStatus = "1";
};

script = ''
set +e
${pkgs.spamassassin}/bin/sa-update --verbose --gpghomedir=%S/spamassassin/sa-update-keys/
${pkgs.spamassassin}/bin/sa-update --verbose --gpghomedir=/var/lib/spamassassin/sa-update-keys/
rc=$?
set -e
if [[ $rc -eq 0 ]]; then
# An update was available and installed.
${pkgs.spamassassin}/bin/sa-compile
if [[ $rc -gt 1 ]]; then
# sa-update failed.
exit $rc
fi
if [[ $rc -eq 1 ]]; then
# No update was available, exit successfully.
exit 0
fi
# An update was available and installed. Compile the rules.
${pkgs.spamassassin}/bin/sa-compile
'';
};

Expand Down

0 comments on commit 8854b82

Please sign in to comment.