LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Does Slackware tell qemu/kvm virtual machines to shutdown? (https://www.linuxquestions.org/questions/slackware-14/does-slackware-tell-qemu-kvm-virtual-machines-to-shutdown-4175587977/)

Altiris 08-25-2016 01:37 PM

Does Slackware tell qemu/kvm virtual machines to shutdown?
 
When I do a "reboot" or "shutdown -h now", does the Slackware init system tell any virtual machines running with qemu/kvm/libvirt to also shutdown or do I need to make an rc. file with "virsh shutdown VMHERE" ? I am in the process of making one and am wondering if I need to.

Richard Cranium 08-25-2016 01:57 PM

You should make an /etc/rc.d/rc.local_shutdown file, set it executable, and add your shutdown commands in there.

Altiris 08-25-2016 06:22 PM

Quote:

Originally Posted by Richard Cranium (Post 5595993)
You should make an /etc/rc.d/rc.local_shutdown file, set it executable, and add your shutdown commands in there.

I was having some fun with seeing how the rc. files work and I decided to try and make my own for the virtual machine. One thing I notice is that my "start" and "stop" are not in the color green like in other rc. files. Do you think this looks good?

Code:

#!/bin/sh
# This rc file is to start the virtual machine on boot

VMNAME=VM1

sb-vm1_start() {
virsh start $VMNAME
echo "Telling the virtual machine [$VMNAME] to start"
}

sb-vm1_stop() {
virsh shutdown $VMNAME
echo "Telling the virtual machine [$VMNAME] to shutdown"
}


case "$1" in
'start')
  sb-vm1_start
  ;;
'stop')
  sb-vm1_stop
  ;;
*)
  echo "usage $0 start|stop"
esac


Richard Cranium 08-25-2016 08:02 PM

Sure.

If you want the colors, you should source /etc/init.d/functions in your script and use the success or failure functions.

Altiris 08-26-2016 02:00 PM

Quote:

Originally Posted by Richard Cranium (Post 5596167)
Sure.

If you want the colors, you should source /etc/init.d/functions in your script and use the success or failure functions.

Upon boot I got something like "sb-vm1_start" is not a valid identifier" and it pointed to line 9. So I guess this doesn't work? Guess I will just try regular virsh commands in there for now.

bassmadrigal 08-26-2016 02:11 PM

Quote:

Originally Posted by Altiris (Post 5596496)
Upon boot I got something like "sb-vm1_start" is not a valid identifier" and it pointed to line 9. So I guess this doesn't work? Guess I will just try regular virsh commands in there for now.

I just looked at my self-created rc files, and I notice that all of them do not use dashes in the identifiers. They all use underscores. Maybe that's your problem (I'm too lazy to google whether dashes can be used in that manner).

ponce 08-26-2016 02:13 PM

here I add a block like this to /etc/rc.d/rc.local
Code:

# Start libvirt:
if [ -x /etc/rc.d/rc.libvirt ]; then
  /etc/rc.d/rc.libvirt start
fi

and a block like this to /etc/rc.d/rc.local_shutdown
Code:

# Stop libvirt:
if [ -x /etc/rc.d/rc.libvirt ]; then
  /etc/rc.d/rc.libvirt stop
fi

like noted in libvirt's README on SBo.
when you will run "/etc/rc.d/rc.libvirt stop" all the active virtual machines will be shut down.

if you want the virtual machines to power on when the libvirtd daemon starts, you can set this option easily using a gui connecting to libvirt via virt-manager: click on the virtual machine, go to "View" -> "Details" and check it under "Boot Options" -> "Start virtual machine on host boot up".


All times are GMT -5. The time now is 10:40 PM.