Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 681874

Summary: app-emulation/qemu-guest-agent can't correctly shutdown Gentoo guest OS
Product: Gentoo Linux Reporter: Vladimir B. Vinogradov <service>
Component: Current packagesAssignee: Matthias Maier <tamiko>
Status: RESOLVED FIXED    
Severity: normal CC: virtualization
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Add NOW for shutdown command

Description Vladimir B. Vinogradov 2019-03-27 19:15:28 UTC
As far as I understand, qemu-server (from Proxmox as for me) call /sbim/shutdown on guest Gentoo to shutdown it. But Gentoo with openrc /sbin/shutdown correctly operates with "-hP now" additional params to shutdown the guest.

Without any params /sbin/shutdown reports only help options and it is impossible to shutdown guest Gentoo vm from server side.
Comment 1 Michal Privoznik 2020-02-10 14:52:12 UTC
Is this true? I mean, executing the following shut off the domain instantly for me:

virsh qemu-agent-command --pretty --block gentoo '{"execute":"guest-shutdown", "arguments":{"mode":"powerdown"}}'


Maybe you're missing the proper mode (which is powerdown anyway)?

Here's the code that runs shutdown command:

https://git.qemu.org/?p=qemu.git;a=blob;f=qga/commands-posix.c;h=93474ff7701e2e176e0dc38290f8f91df9233ce1;hb=HEAD#l83
Comment 2 Brian 2020-03-21 16:33:32 UTC
I had this same problem.  The issue is that Gentoo's /sbin/shutdown from sys-apps/sysvinit (openrc) doesn't accept the "+0" argument, instead requiring "now", for an immediate shutdown.  I don't know much about systemd, but I'm guessing it provides a version of /sbin/shutdown that accepts "+0" ?

As a workaround, I renamed /sbin/shutdown to /sbin/shutdowno and wrote a simple bash script wrapper for /sbin/shutdown that changes "+0", if present as $3, to "now", and then calls shutdowno.

Probably the right approach for Gentoo is to simply patch commands-posix.c to call shutdown with "now" instead of "+0", when openrc is in use?
Comment 3 slawan 2020-03-23 08:34:23 UTC
Created attachment 624662 [details, diff]
Add NOW for shutdown command

/sbin/shutdown from sysvinit-2.96 requires "now", but qemu-ga run /sbin/shutdown without "now"...
Comment 4 slawan 2020-03-23 08:36:51 UTC
Option "now" worked with other packages, e.g. systemd, openrc etc...
Comment 5 Vladimir B. Vinogradov 2020-03-23 20:37:05 UTC
(In reply to slawan from comment #4)
> Option "now" worked with other packages, e.g. systemd, openrc etc...

It's works for me on proxmox-ve (with openrc on vm).
Thank you for a patch.
Comment 6 Larry the Git Cow gentoo-dev 2020-04-18 19:28:59 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8b8e82850dc8818b97f8bafc3ccc7982142f1cea

commit 8b8e82850dc8818b97f8bafc3ccc7982142f1cea
Author:     Matthias Maier <tamiko@gentoo.org>
AuthorDate: 2020-04-18 19:28:23 +0000
Commit:     Matthias Maier <tamiko@gentoo.org>
CommitDate: 2020-04-18 19:28:23 +0000

    app-emulation/qemu-guest-agent: fix shutdown command
    
    Closes: https://bugs.gentoo.org/681874
    Package-Manager: Portage-2.3.99, Repoman-2.3.22
    Signed-off-by: Matthias Maier <tamiko@gentoo.org>

 .../files/qemu-guest-agent-4.2.0-fix-shutdown.patch           | 11 +++++++++++
 ...st-agent-4.2.0.ebuild => qemu-guest-agent-4.2.0-r1.ebuild} |  1 +
 2 files changed, 12 insertions(+)
Comment 7 Jaak Ristioja 2020-05-29 22:25:08 UTC
I'm still experiencing this with both 4.2.0-r1 and 5.0.0. I get the following error messages logged /var/log/messages in the guest when I signal the guest to shutdown or reboot, but no shutdown or reboot occurs:

May 30 01:23:04 guest qemu-ga[5813]: info: guest-shutdown called, mode: reboot
May 30 01:23:04 guest /etc/init.d/qemu-guest-agent[5871]: openrc-shutdown: Select one of --cancel, --halt, --kexec, --poweroff, --reexec, --reboot, --single or
--write-only
May 30 01:23:12 guest qemu-ga[5813]: info: guest-shutdown called, mode: reboot
May 30 01:23:12 guest /etc/init.d/qemu-guest-agent[5874]: openrc-shutdown: Select one of --cancel, --halt, --kexec, --poweroff, --reexec, --reboot, --single or
--write-only
May 30 01:23:18 guest qemu-ga[5813]: info: guest-shutdown called, mode: reboot
May 30 01:23:18 guest /etc/init.d/qemu-guest-agent[5876]: openrc-shutdown: Select one of --cancel, --halt, --kexec, --poweroff, --reexec, --reboot, --single or
--write-only
May 30 01:23:22 guest qemu-ga[5813]: info: guest-shutdown called, mode: powerdown
May 30 01:23:25 guest qemu-ga[5813]: info: guest-shutdown called, mode: powerdown
May 30 01:23:29 guest qemu-ga[5813]: info: guest-shutdown called, mode: powerdown

Also running sys-apps/openrc-0.42.1[sysv-utils] in the guest and not using a init= kernel parameter.

Please reopen?