Make systemd report errors in mail

My domain is:

I ran this command:

It produced this output:

My web server is (include version): apache 2.4

The operating system my web server runs on is (include version): ubuntu 18.04

My hosting provider, if applicable, is:

I can login to a root shell on my machine (yes or no, or I don’t know): yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): no

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): 0.28

When running regular certbot renewal from cron I can get error output easily to email (cron sends output on email). How can I achieve the same functionality when running it as a systemd service? Thank you

You could try enhance the certbot.service:

systemctl edit certbot.service

(This will give you a blank inclusion file that won’t get overwritten by Certbot upgrades). That file could say:


and that could be something like:

#!/usr/bin/env bash
set -u

# EXIT_STATUS is set by systemd when this script is invoked
if [ "$EXIT_STATUS" != "0" ]; then
    mail -s "Let's Encrypt renewal failed"

(Make sure it’s executable).

Completely untested but who knows, it might be what you need.

1 Like

OK, it should be ExecStopPost, not ExitStopPost, otherwise it works great, thank you.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.