Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart=always not working with ExecStopPost and dependency on service with StopWhenUnneeded=true #1154

Closed
omgold opened this issue Sep 5, 2015 · 9 comments
Labels
bug 🐛 Programming errors, that need preferential fixing pid1

Comments

@omgold
Copy link

omgold commented Sep 5, 2015

In found that in a special situation a service is not restarted, although marked as Restart=always. I narrowed it down to the combination of the two service files below.

If I do a kill -9 on the sleep command of myd2 the service enters failed state instead of restarting. But if I remove either the StopWhenUnneeded from myd1 or the ExecStopPost from myd2 it works as expected.

I believe this is a bug.

--- myd1.service ---
[Unit]
Description=example daemon 1
StopWhenUnneeded=true

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/true
RemainAfterExit=true

--- myd2.service ---
[Unit]
Description=example daemon 2
Requires=myd1.service
After=myd1.service

[Service]
Type=simple
ExecStart=/usr/bin/sleep 100000000
ExecStopPost=/bin/true
Restart=always

@poettering poettering added the pid1 label Sep 6, 2015
@poettering
Copy link
Member

Which systemd version is this happening with?

@poettering poettering added the needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer label Sep 6, 2015
@omgold
Copy link
Author

omgold commented Sep 6, 2015

I run version 224.

@poettering poettering added bug 🐛 Programming errors, that need preferential fixing and removed needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer labels Sep 6, 2015
@digrouz
Copy link

digrouz commented Oct 20, 2016

same issue on centos 7.2 running version 219.

Is there any fix or workaround ?

@Amyyum
Copy link

Amyyum commented May 3, 2018

Has the problem been solved?

@omgold
Copy link
Author

omgold commented May 3, 2018

No. Just tested it with version v238-76-gf398c546c (f398c54). Still same behavior.

@Amyyum
Copy link

Amyyum commented May 4, 2018 via email

rafaelgieschke added a commit to rafaelgieschke/compose-unit that referenced this issue Jun 8, 2018
@bl33pbl0p
Copy link
Contributor

@omgold
This is very similar to #11456. I know what happens here too:

You have StopWhenUnneeded=true in myd2.service, you have Requires=myd2.service in myd1.service, Requires= forwards stop/restart requests on required unit to requiree, so when you go down, what happens is that the other unit has a stop job triggered from systemd due to referenced units not being active anymore, meanwhile, your ExecStopPost= keeps it hung in deactivating stage for a while. OTOH, this stop job on myd2.service is propagated to your unit back when it was triggered.

This creates a race: now, when the stop job installs itself in your unit, the state change (to failed) is attributed to it. Since Restart= only triggers when state change happens without any job's involvement, it will not fire a restart job for the same unit.

Fix is to probably introduce a version of Requires= that only has the strong effect at start and not propagation effect like PartOf=.

@bl33pbl0p
Copy link
Contributor

@omgold Note that your bug was fixed with a3c1168 so this works in v240 nicely.

@poettering This can be closed.

@dtardon
Copy link
Collaborator

dtardon commented Jul 29, 2022

ping

@dtardon dtardon closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Programming errors, that need preferential fixing pid1
Development

No branches or pull requests

6 participants