0

On Ubuntu 18 I have a service :

[Unit]
Description=Gets CSV
OnFailure=pushovercsv.service

[Service]
ExecStart=/usr/bin/vehicles.sh

[Install]
WantedBy=multi-user.target

This works. I am trying unsuccessfully to setup another service which alerts me if the first service is stopped or in failed sate:

pushovercsv.service

[Unit]
Description=PushOver Notifaction for vehicles CSV Service

[Service]
Type=simple
ExecStart=curl -s --form-string "token=<secret>" --form-string "user=<secret>" --form-string "message=CSV service"   https://<pushover api endpoint>

[Install]
WantedBy=multi-user.target

Both services work on there own.

But it doesn't appear as if OnFailure=pushovercsv.service is calling the pushover service. If I stop the first service with systemctl stop service1 I get no alert from pushovercsv.service.

Does pushovercsv.service need to be manually started or is it started when called?

Al Grant
  • 125
  • 1
  • 1
  • 7

1 Answers1

1

As its name suggests, OnFailure= is only triggered when the unit fails (exits with a non-zero exit code, killed by a signal, or similar). If you want to run a command whenever the service stops, you don't even need a separate service, just ExecStopPost= is enough.

iBug
  • 1,212
  • 2
  • 13
  • 23
  • So if I include OnFailure and ExecStopPost it will trigger on Failure or Stop? – Al Grant Aug 20 '23 at 06:45
  • @AlGrant They'll act separately. If the service fails, both `OnFailure` unit and `ExecStopPost` command will be started/executed. – iBug Aug 20 '23 at 08:39