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

systemctl: add support for --wait to is-system-running #9796

Merged
merged 1 commit into from Aug 7, 2018

Conversation

@filbranden
Copy link
Member

commented Aug 4, 2018

This makes it possible to wait until boot is finished without having to poll for this command repeatedly, instead using the syntax:

$ systemctl is-system-running --wait

Waiting is implemented by waiting for the StartupFinished signal to be posted on the bus.

Register the matcher before checking for the property to avoid race conditions.

Tested by artificially delaying startup with a oneshot service and calling this command, checked that it emitted running and exited with a 0 return code as soon as the delay service completed startup.

@keszybz

keszybz approved these changes Aug 6, 2018

Copy link
Member

left a comment

I think this is reasonable as is. The timeout doesn't seem to be strictly necessary: if this command is invoked from a script in another unit, that unit will be subject to timeout anyway, so no timing in the command itself is OK.

match_startup_finished, NULL, &state);
if (r < 0) {
log_warning_errno(r, "Failed to request match for StartupFinished: %m");
arg_wait = false;

This comment has been minimized.

Copy link
@keszybz

keszybz Aug 6, 2018

Member

If this fails, the command falls back to the non-wait behaviour, and succeeds if startup is already finished, and fails if not. This is very reasonable.

@keszybz

This comment has been minimized.

Copy link
Member

commented Aug 6, 2018

Oh, but we need --help and man page additions.

@filbranden

This comment has been minimized.

Copy link
Member Author

commented Aug 6, 2018

Sounds good, I'll complete this (with docs and --help) and update the PR.

I also realized !streq(state, "running") is maybe incorrect, should be streq(state, "starting") instead, otherwise degraded or after starting shutdown will cause it to block...

@poettering

This comment has been minimized.

Copy link
Member

commented Aug 6, 2018

hmm, waht's the usecase? waiting for the system to be booted up fully? If that then we should be more careful with the system states as "degraded" should probably not be reason to wait forever here? i figure this should follow some whitelist?

@filbranden

This comment has been minimized.

Copy link
Member Author

commented Aug 6, 2018

Yes, use case is waiting for the system to be booted up fully.

In other words, out of starting state.

Indeed, I think my checking for !running is incorrect, should only block when in starting state...

systemctl: add support for --wait to is-system-running
This makes it possible to wait until boot is finished without having to poll
for this command repeatedly, instead using the syntax:

  $ systemctl is-system-running --wait

Waiting is implemented by waiting for the StartupFinished signal to be posted
on the bus.

Register the matcher before checking for the property to avoid race conditions.

Tested by artificially delaying startup with a oneshot service and calling this
command, checked that it emitted `running` and exited with a 0 return code as
soon as the delay service completed startup.

Also tested that booting to degraded state unblocks the command.

Inserted a delay between getting the property and waiting for the signal and
confirmed this seems to work free of race conditions.

Updated the --help text (under --wait) and the man page to document the new
feature.

@filbranden filbranden force-pushed the filbranden:waitrunning1 branch from 93aaa59 to 02d9350 Aug 7, 2018

@filbranden

This comment has been minimized.

Copy link
Member Author

commented Aug 7, 2018

Updated.

  • Only wait when in state "initializing" or "starting".
  • Added --help and man page updates.
  • Tested this with a sleep(10) between the property and the loop waiting for the signal, seems to be race free as far as I can tell.

Please take another look.

@poettering poettering merged commit adb6cd9 into systemd:master Aug 7, 2018

7 checks passed

Fedora Rawhide CI x86_64 rpm build [succeeded]
Details
LGTM analysis: C/C++ No alert changes
Details
LGTM analysis: JavaScript No alert changes
Details
bionic-amd64 autopkgtest finished (success)
Details
bionic-i386 autopkgtest finished (success)
Details
bionic-s390x autopkgtest finished (success)
Details
semaphoreci The build passed on Semaphore.
Details

@filbranden filbranden deleted the filbranden:waitrunning1 branch Aug 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.