You are not logged in.

#1 2020-04-24 12:48:47

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

If systemd service fails get a dependency to fail also [solved]

I'd like to have systemd (user mode) call a bash script with different tokens under two conditions:
1) When the user starts/stops a service (token would be either "sync" or "unsync")
2) When a timer tells it to run (token would be "sync")

Thus far, I have been accomplishing these with 1 service and 1 service/timer combo:
psd.service
psd-resync.service
psd-resync.timer

So the user starts psd.service and both psd-resync.{service,timer} get brought activated and run as expected.  The problem is when the script that psd.service calls ends in an error state...

1) psd.service remains in an active state
2) psd-resync.timer remains active

I'd like:
1) both psd.service and psd-resync.service to both end in an error state.
2) psd-resync.timer to get deactivated

I've been through the man pages for systemd.service and systemd.timer to the point where I am confused who to achieve this.  What is the right strategy using services and a timer to deliver on this?

Last edited by graysky (2020-04-25 11:46:51)

Offline

#2 2020-04-24 17:10:45

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: If systemd service fails get a dependency to fail also [solved]

Have you tried replacing this line in psd-resync.service:

PartOf=psd.service

With:

Requires=psd.service

Your links are wrong btw, psd-resync.service points to psd.service.


Jin, Jîyan, Azadî

Offline

#3 2020-04-24 21:15:44

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: If systemd service fails get a dependency to fail also [solved]

I corrected the links, thanks.  I also ended up trying a different strategy retaining the files as-is: https://github.com/graysky2/profile-syn … 3d5cb19429

Basically, psd.service now has an ExecStart= that will error out if there is a problem.  If all is well, it returns 0 and psd.service pulls in psd-resync.timer which in turn starts psd-resync.service which does the initial sync.  If the first service errors out, so does the 2nd one.  The only issue I find with this setup now is that psd-resync.timer is still active even if psd-resync.service is in an error state... any way to make the timer die if the service dies?

Last edited by graysky (2020-04-25 11:46:28)

Offline

Board footer

Powered by FluxBB