containers / toolbox

Tool for interactive command line environments on Linux
https://containertoolbx.org/
Apache License 2.0
2.61k stars 220 forks source link

Active toolbox sessions prevent systemd shutdown #993

Open djrenren opened 2 years ago

djrenren commented 2 years ago

Describe the bug If you have an active toolbox session and you try to reboot the host machine, the container will refuse to shutdown. Eventually it will timeout and systemd will forcibly kill the process.

Steps how to reproduce the behavior

  1. Enter any toolbox with toolbox enter my-container
  2. Trigger a shutdown from the host machine. (On gnome I click the top-right menu -> Power Off / Log out -> Power Off...)
  3. "A stop job is running..." from systemd

Expected behaviour The container should gracefully shutdown and shutdown should work.

Actual behaviour Wait for systemd to SIGKILL the container process.

Output of toolbox --version (v0.0.90+)

toolbox version 0.0.99.3

Toolbox package info (rpm -q toolbox)

➜  ~ pacman -Qi toolbox
Name            : toolbox
Version         : 0.0.99.3-1
Description     : Unprivileged development environment
Architecture    : x86_64
URL             : https://github.com/containers/toolbox
Licenses        : APACHE
Groups          : None
Provides        : None
Depends On      : podman  bash  flatpak
Optional Deps   : None
Required By     : None
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 7.18 MiB
Packager        : Morten Linderud <foxboron@archlinux.org>
Build Date      : Mon 13 Dec 2021 11:21:43 AM PST
Install Date    : Thu 06 Jan 2022 11:43:16 AM PST
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature

Output of podman version

Version:      3.4.4
API Version:  3.4.4
Go Version:   go1.17.4
Git Commit:   f6526ada1025c2e3f88745ba83b8b461ca659933
Built:        Thu Dec  9 10:30:40 2021
OS/Arch:      linux/amd64

Podman package info (rpm -q podman)

➜  ~ pacman -Qi podman
Name            : podman
Version         : 3.4.4-1
Description     : Tool and library for running OCI-based containers in pods
Architecture    : x86_64
URL             : https://github.com/containers/podman
Licenses        : Apache
Groups          : None
Provides        : None
Depends On      : cni-plugins  conmon  containers-common  crun  fuse-overlayfs
                  iptables  libdevmapper.so=1.02-64  libgpgme.so=11-64
                  libseccomp.so=2-64  slirp4netns
Optional Deps   : apparmor: for AppArmor support
                  btrfs-progs: support btrfs backend devices [installed]
                  catatonit: --init flag support
                  podman-docker: for Docker-compatible CLI
Required By     : toolbox
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 72.79 MiB
Packager        : David Runge <dvzrv@archlinux.org>
Build Date      : Thu 09 Dec 2021 10:30:40 AM PST
Install Date    : Thu 06 Jan 2022 11:43:16 AM PST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature

Info about your OS ArchLinux (as of Jan. 21, 2022)

Additional context I can reproduce the issue using either of these images:

➜  ~ podman images
REPOSITORY                                       TAG         IMAGE ID      CREATED       SIZE
registry.fedoraproject.org/fedora-toolbox        34          4a61e887a820  4 weeks ago   353 MB
registry.hub.docker.com/jmennius/ubuntu-toolbox  21.10       cbb6d324bf93  2 months ago  440 MB
Jmennius commented 9 months ago

I've been experiencing this issue for years, finally had some inspiration to do something about it:

cat << EOF > ~/.config/systemd/user/stop-toolbox-containers.service
[Unit]
Description=Stop all Toolbox containers on shutdown

[Service]
ExecStop=/usr/bin/podman stop --all --filter "label=com.github.containers.toolbox=true"
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=default.target
EOF

systemctl --user daemon-reload
systemctl --user enable --now stop-toolbox-containers.service

I do think this should be properly handled by the toolbx itself. Maybe whatever is preventing containers from stopping can be fixed or this service can be incorporated into the toolbox package. @debarshiray what do you think?