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

nixos/containers: use machinectl poweroff #76719

Merged
merged 1 commit into from Dec 31, 2019

Conversation

flokli
Copy link
Contributor

@flokli flokli commented Dec 30, 2019

Previously, we were storing the leader pid in a runtime file and
signalled SIGRTMIN+4 manually.

In systemd 219, the machinectl poweroff command was introduced, which
does that for us.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @arianvp

Previously, we were storing the leader pid in a runtime file and
signalled SIGRTMIN+4 manually.

In systemd 219, the `machinectl poweroff` command was introduced, which
does that for us.
@flokli
Copy link
Contributor Author

flokli commented Dec 30, 2019

@GrahamcOfBorg build nixosTests.containers-bridge nixosTests.containers-ephemeral nixosTests.containers-extra_veth nixosTests.containers-hosts nixosTests.containers-imperative nixosTests.containers-ip nixosTests.containers-macvlans nixosTests.containers-physical_interfaces nixosTests.containers-physical_interfaces nixosTests.containers-portforward nixosTests.containers-restart_networking nixosTests.containers-tmpfs

@jonringer
Copy link
Contributor

@GrahamcOfBorg test containers-bridge containers-ephemeral containers-extra_veth containers-hosts containers-ip containers-macvlans containers-physical_interfaces containers-portforward containers-restart_networking containers-tmpfs

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

locally passes:

[nix-shell:~/.cache/nix-review/pr-76719]$ nix build -f ./nixpkgs/ nixosTests.containers-bridge nixosTests.containers-ephemeral nixosTests.containers-extra_veth nixosTests.containers-hosts nixosTests.containers-imperative nixosTests.containers-ip nixosTests.containers-macvlans nixosTests.containers-physical_interfaces nixosTests.containers-physical_interfaces nixosTests.containers-portforward nixosTests.containers-restart_networking nixosTests.containers-tmpfs
[754 built, 423 copied (1181.7 MiB), 237.6 MiB DL]

@jonringer
Copy link
Contributor

these passed locally, but failed on ofborg:

error: build of '/nix/store/81s1hqa1i3l53fq9ls2b1izrc699538w-vm-test-run-containers-hosts.drv', '/nix/store/hnlggxfn5v1h49p9z0i3qbry4mwmxfhd-vm-test-run-containers-macvlans.drv' failed

@flokli
Copy link
Contributor Author

flokli commented Dec 31, 2019

@GrahamcOfBorg test containers-hosts containers-macvlans

@flokli
Copy link
Contributor Author

flokli commented Dec 31, 2019

It now succeeded on ofborg aswell, merging.

@flokli flokli merged commit d6bbe6c into NixOS:master Dec 31, 2019
@flokli flokli deleted the containers-poweroff branch December 31, 2019 13:42
@uvNikita
Copy link
Contributor

uvNikita commented Jan 7, 2020

I'm probably missing something, but why we wouldn't use the same configuration as in the upstream service file?

KillMode=mixed
Type=notify

From my basic tests, the shutdown process seems the same.

@flokli
Copy link
Contributor Author

flokli commented Jan 7, 2020 via email

danbst added a commit to danbst/nixpkgs that referenced this pull request Feb 15, 2020
Fixes NixOS#43652
Fixes NixOS#16753
Alternative fix for NixOS#39717
The fix in NixOS#76719 was not enough

`--keep-unit` ties systemd-nspawn container to systemd unit. When
unit is restarted (ie atomic operation "restart", not two separate
"stop" and "start") systemd assumes that unit didn't disappear.
Hence machine won't disappear.

If unit is stopped (or stopped due to failure), associated machine is also stopped,
so service can start fresh.

Resource slice isn't changed though - it is machine.slice by default for
nspawn containers.
zhaofengli pushed a commit to zhaofengli/nixpkgs that referenced this pull request Mar 10, 2021
Fixes NixOS#43652
Fixes NixOS#16753
Alternative fix for NixOS#39717
The fix in NixOS#76719 was not enough

`--keep-unit` ties systemd-nspawn container to systemd unit. When
unit is restarted (ie atomic operation "restart", not two separate
"stop" and "start") systemd assumes that unit didn't disappear.
Hence machine won't disappear.

If unit is stopped (or stopped due to failure), associated machine is also stopped,
so service can start fresh.

Resource slice isn't changed though - it is machine.slice by default for
nspawn containers.
zhaofengli pushed a commit to mars-research/nixpkgs that referenced this pull request Apr 14, 2021
Fixes NixOS#43652
Fixes NixOS#16753
Alternative fix for NixOS#39717
The fix in NixOS#76719 was not enough

`--keep-unit` ties systemd-nspawn container to systemd unit. When
unit is restarted (ie atomic operation "restart", not two separate
"stop" and "start") systemd assumes that unit didn't disappear.
Hence machine won't disappear.

If unit is stopped (or stopped due to failure), associated machine is also stopped,
so service can start fresh.

Resource slice isn't changed though - it is machine.slice by default for
nspawn containers.
zhaofengli pushed a commit to zhaofengli/nixpkgs that referenced this pull request Apr 30, 2021
Fixes NixOS#43652
Fixes NixOS#16753
Alternative fix for NixOS#39717
The fix in NixOS#76719 was not enough

`--keep-unit` ties systemd-nspawn container to systemd unit. When
unit is restarted (ie atomic operation "restart", not two separate
"stop" and "start") systemd assumes that unit didn't disappear.
Hence machine won't disappear.

If unit is stopped (or stopped due to failure), associated machine is also stopped,
so service can start fresh.

Resource slice isn't changed though - it is machine.slice by default for
nspawn containers.
d-xo pushed a commit to d-xo/nixpkgs that referenced this pull request Dec 4, 2023
Fixes NixOS#43652
Fixes NixOS#16753
Alternative fix for NixOS#39717
The fix in NixOS#76719 was not enough

`--keep-unit` ties systemd-nspawn container to systemd unit. When
unit is restarted (ie atomic operation "restart", not two separate
"stop" and "start") systemd assumes that unit didn't disappear.
Hence machine won't disappear.

If unit is stopped (or stopped due to failure), associated machine is also stopped,
so service can start fresh.

Resource slice isn't changed though - it is machine.slice by default for
nspawn containers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants