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

RemainAfterExit should respect return codes and/or Restart= modes #3396

Open
1 of 2 tasks
binarybana opened this issue May 30, 2016 · 5 comments
Open
1 of 2 tasks

RemainAfterExit should respect return codes and/or Restart= modes #3396

binarybana opened this issue May 30, 2016 · 5 comments
Labels
pid1 RFE 🎁 Request for Enhancement, i.e. a feature request

Comments

@binarybana
Copy link

Submission type

  • Bug report
  • Request for enhancement (RFE)

systemd version the issue has been seen with

225 (but this is an RFE, and I didn't see anything in NEWS about changes to this behavior)

Used distribution

CoreOS

Using something like

[Service]
ExecStart=/usr/bin/false
Type=simple
RemainAfterExit=yes
Restart=on-failure
RestartSec=10

Despite the fact that the service fails, it does not get restarted. Ideally I could specify something like RemainAfterExit=on-success to only remain if exiting with a success return code.

My primary use case for this is using Type=simple jobs for one off scripts at bootup (like formatting drives) where I need Restart=on-failure but also RemainAfterExit. This relates to (but is distinct from) #2582, because even with that issue fixed, you'd still want to add this behavior.

@arvidjaar
Copy link
Contributor

Well, strictly speaking service had never been started in the first place, so Restart logically does not apply here. This would need new directive with semantic "keep starting this service even if initial attempt fails". Although exact semantic is rather hairy - what to do with all ExecStartPre? Should they be repeated or not? Should any cleanup be attempted (i.e. ExecStop*)?

@poettering poettering added RFE 🎁 Request for Enhancement, i.e. a feature request pid1 labels May 31, 2016
@binarybana
Copy link
Author

Perhaps something like RetryStarting=yes.

And my votes on the semantics would be: repeat ExecStartPre directives yet ExecStop* are only for explicit stop commands.

@Keruspe
Copy link
Contributor

Keruspe commented Jun 1, 2016

Note that another side-effect is that while the exit code of the unit is 1, its state is "active", not "failed" which makes systemctl is-failed claim that it's not.

I think that RemainAfterExit=on-succes at least makes sense, and I'd say that's what I would expect anyway, even with yes.

@arvidjaar
Copy link
Contributor

@binarybana I apologize, I misunderstood it. In case of simple service it is already started as soon as main process is spawned. So the problem is indeed interaction with RemainAfterExit. The same issue will have Type=forking when forked process terminates.

@Keruspe Yes, and when service is stopped (systemctl stop ...) it suddenly becomes failed.

I wonder whether RemainAfterExit should be allowed with non-oneshot services in the first place. @binarybana , could you explain why you need it and not Type=oneshot?

litew added a commit to litew/droid-config-ham that referenced this issue Jul 13, 2017
1. Instead of using hardcoded timeout (5 secs) before loading wlan we wait when wcnsscore is ready by polling wcnss_is_ready parameter.
2. Add wcnss_wlan.device as dependency, there is no point in trying to start wlan without this device.
3. Switch to Type=forking because it's only type of unit which tries to restart service in case of failed state (see systemd/systemd#3396 and systemd/systemd#2582)
litew added a commit to litew/droid-config-ham that referenced this issue Jul 14, 2017
1. Instead of using hardcoded timeout (5 secs) before loading wlan we wait when wcnsscore is ready by polling wcnss_is_ready parameter.
2. Add wcnss_wlan.device as dependency, there is no point in trying to start wlan without this device.
3. Switch to Type=forking because it's only type of unit which tries to restart service in case of failed state (see systemd/systemd#3396 and systemd/systemd#2582)
@gegenschall
Copy link

gegenschall commented Jul 26, 2017

I stumbled across this when creating a tmux.service unit. What I want to achieve is having the RemainAfterExit behavior but also have the service restarting when it exists (any exit code is fine).
This way I don't need to systemctl --user restart tmux when I accidentally quit my tmux session.

There is currently no way to achieve this, right?

edit: Actually, If you tell tmux to remain-on-exit on this all works out pretty nicely. Still, a less application specific way to achieve this would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pid1 RFE 🎁 Request for Enhancement, i.e. a feature request
Development

No branches or pull requests

5 participants