I converted some cron jobs to systemd.timer units and want to send a mail on each job failure and success.

The excellent ArchLinux wiki page provides information about this and the setup runs smoothly on failure. Now I want to add an email notification whenever the unit ran successful, but according to systemd.unit there is no configuration named OnSuccess=.

How to handle this use case?


You could use ExecStartPost=/bin/systemctl start some-other-service if the Type= is oneshot.

Read about the details in man systemd.service

To review a full list of directions, use man systemd.directives, which lists all the directions and where they are documented.

|improve this answer|||||
  • 1
    Currently I go with Type=simple, but I might migrate to oneshot without problem. Nice catch that ExecStartPost= fires after successful termination if the Type= is set accordingly. – maxik Jun 16 '17 at 8:39
  • PLEASE, abstain from controlling other services explicitely from unit scripts like seen here. This might create endless activating/deactivating service loop hells. Instead, try to use SystemD to express this. Example: In this.service use Wants: other.service and in other.service use Requisite: this.service and After: this.service. So other.service starts after this.service only if this.service does not fail. (I am not sure, but documentation seems to say that.) – Tino Sep 21 '18 at 18:20
  • @Tino Wants= and After= are only about starting services at boot. This question was about running other services when run (possibly after boot). There is no need for the approach to cause a loop. Like everything else, you should test it to see if it works. – Mark Stosberg Sep 25 '18 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.