How to send an email alert when a linux service has stopped?

2

I have Systemd service that is supposed to be running all the time. I would like to get alerted by email in case the service has stopped? What is the best way to do it in linux?

motam79

Posted 2018-09-21T19:22:09.557

Reputation: 300

We use Naemon to monitor our systems. It’s easy to configure it to send an email if a service is down. – Colin 't Hart – 2018-09-21T21:39:54.803

Answers

1

You can use the ExecStopPost setting in your service configuration, as documented in systemd.service to send an email whenever the service stops. If you don't want to receive an email when the service exits cleanly, you can use the SERVICE_RESULT environment variable (documented in systemd.exec) in the script sending the email.

user2313067

Posted 2018-09-21T19:22:09.557

Reputation: 2 160

0

You can have a short bash script that checks the status of the service and pushes a notification if it is not running. For pushing notifications you can use Pushover which is pretty easy to integrate with a bash script after generating security keys. Your bash script can be added to the crontab for periodic execution say every 5 minutes(basically whatever period you want).

Prathu Baronia

Posted 2018-09-21T19:22:09.557

Reputation: 149