Sequencing start/stop of docker and libvirt moved into emhttp. After network services (smb, afp, nfs) have

been started we start docker (if enabled) and then libvirt (if enabled), and only if array is Started in
non-maintenance mode. Upon array Stop, libvirt is stopped first, then docker, then network services.

The libvirt loopback image now exists on the "system" system share.  Script ./dynamix.vm.manager/scripts/libvirt_init
is invoked each time libvirt is started to handle initialization of the mounted image file if necessary.  Also got
rid of the old way libvirt loopback was initialized via compressed tar file.

Create/mount of docker and libvirt loopback images implemented in /usr/local/sbin/mount_image script.

The docker and libvirt loopback image files by default are located on /mnt/user/system/docker.img and
/mnt/user/system/libvirt/libvirt.img.

Default /boot/config/docker.cfg and /boot/config/domains.cfg added to flash image.  This is so that docker and
libvirt start out enabled.

The /boot/config/shares/{appdata,domains,isos,system}.cfg files are created each time array Starts if they do
not exist already. This establishes defaults for these so-called "system" shares.

The "appdata", "domains", and "system" system shares have setting shareUseCache="only".  These shares therefore
cannot be auto-created unless/until a cache disk/pool is available.
This commit is contained in:
Tom Mortensen
2016-02-21 15:18:31 -08:00
parent 2f353abfca
commit 08146b82ec
8 changed files with 20 additions and 149 deletions

View File

@@ -51,7 +51,6 @@ if (file_exists($realfile)) {
<span class="status" style="margin-top: -44px;"><input type="checkbox" class="advancedview"></span>
<form id="settingsForm" markdown="1" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="<?=$docker_cfgfile;?>" />
<input type="hidden" id="command" name="#command" value="" />
<dl>
<dt>Enable Docker:</dt>
@@ -204,8 +203,6 @@ $(function() {
return;
}
$("#command").val("/plugins/dynamix.docker.manager/event/" + ($("#DOCKER_ENABLED").val()=="yes" ? "started" : "stopping_svcs"));
if ($("#DOCKER_IMAGE_SIZE").length && $("#DOCKER_IMAGE_FILE").length) {
var isError = false;
var size = $("#DOCKER_IMAGE_SIZE").val();

View File

@@ -1,11 +0,0 @@
#!/bin/sh
# Only start if array has started in Normal operation mode
if grep -q 'fsState="Started"' /var/local/emhttp/var.ini && grep -q 'startMode="Normal"' /var/local/emhttp/var.ini; then
# Start Docker.io
if [ -x /etc/rc.d/rc.docker ]; then
echo "Starting Docker..."
/etc/rc.d/rc.docker start | logger
/usr/local/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate.php | logger
fi
fi

View File

@@ -1,7 +0,0 @@
#!/bin/sh
# Shutdown Docker.io
if [ -x /etc/rc.d/rc.docker ]; then
echo "Stopping Docker..."
/etc/rc.d/rc.docker stop | logger
fi

View File

@@ -1,74 +0,0 @@
#!/usr/bin/env php
<?php
if (!isset($argv[2]) || $argv[2] != 'start') {
exit(0);
}
$strXML = file_get_contents('php://stdin');
$doc = new DOMDocument();
$doc->loadXML($strXML);
$xpath = new DOMXpath($doc);
$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");
for ($i = 0; $i < $args->length; $i++){
$arg_list = explode(',', $args->item($i)->nodeValue);
if ($arg_list[0] !== 'vfio-pci') {
continue;
}
foreach ($arg_list as $arg) {
$keypair = explode('=', $arg);
if ($keypair[0] == 'host' && !empty($keypair[1])) {
vfio_bind($keypair[1]);
break;
}
}
}
exit(0); // end of script
function vfio_bind($strPassthruDevice) {
// Ensure we have leading 0000:
$strPassthruDeviceShort = str_replace('0000:', '', $strPassthruDevice);
$strPassthruDeviceLong = '0000:' . $strPassthruDeviceShort;
// Determine the driver currently assigned to the device
$strDriverSymlink = @readlink('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver');
if ($strDriverSymlink !== false) {
// Device is bound to a Driver already
if (strpos($strDriverSymlink, 'vfio-pci') !== false) {
// Driver bound to vfio-pci already - nothing left to do for this device now regarding vfio
return true;
}
// Driver bound to some other driver - attempt to unbind driver
if (file_put_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver/unbind', $strPassthruDeviceLong) === false) {
file_put_contents('php://stderr', 'Failed to unbind device ' . $strPassthruDeviceShort . ' from current driver');
exit(1);
return false;
}
}
// Get Vendor and Device IDs for the passthru device
$strVendor = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/vendor');
$strDevice = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/device');
// Attempt to bind driver to vfio-pci
if (file_put_contents('/sys/bus/pci/drivers/vfio-pci/new_id', $strVendor . ' ' . $strDevice) === false) {
file_put_contents('php://stderr', 'Failed to bind device ' . $strPassthruDeviceShort . ' to vfio-pci driver');
exit(1);
return false;
}
return true;
}

View File

@@ -1,43 +0,0 @@
#!/bin/sh
# Only start if array has started in Normal operation mode
if grep -q 'fsState="Started"' /var/local/emhttp/var.ini && grep -q 'startMode="Normal"' /var/local/emhttp/var.ini; then
SERVICE="disable"
if [ -f /boot/config/domain.cfg ]; then
source /boot/config/domain.cfg
fi
#copy old image to new
if [ -f /boot/config/plugins/virtMan/virtMan.img ]; then
if [ "$(mount | grep virtMan.img)" ]; then
umount /etc/libvirt
fi
if [ ! -f /boot/config/plugins/dynamix.kvm.manager/domain.img ]; then
mkdir -p /boot/config/plugins/dynamix.kvm.manager
cp /boot/config/plugins/virtMan/virtMan.img /boot/config/plugins/dynamix.kvm.manager/domain.img
fi
fi
#copy seed loopback image and qemu hook, if needed, to flash drive
if [ -d /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager ]; then
mkdir -p /boot/config/plugins/dynamix.kvm.manager
[ ! -f /boot/config/plugins/dynamix.kvm.manager/domain.img ] && tar --no-same-owner -xkf /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager/domain.tar.xz -C /boot/config/plugins/dynamix.kvm.manager/
[ ! -f /boot/config/plugins/dynamix.kvm.manager/qemu ] && cp -n /usr/local/emhttp/plugins/dynamix.vm.manager/dynamix.kvm.manager/qemu /boot/config/plugins/dynamix.kvm.manager/
fi
if [ "$SERVICE" = "enable" ]; then
# mount xml/conf image if not already mounted
if [ ! "$(mount | grep domain.img)" ]; then
mount -t ext4 /boot/config/plugins/dynamix.kvm.manager/domain.img /etc/libvirt
mkdir -p /etc/libvirt/hooks
cp /boot/config/plugins/dynamix.kvm.manager/qemu /etc/libvirt/hooks/
fi
# Start libvirt
if [ -x /etc/rc.d/rc.libvirt ]; then
echo "Starting libvirt..."
/etc/rc.d/rc.libvirt start |& logger
fi
fi
fi

View File

@@ -1,11 +0,0 @@
#!/bin/sh
# Shutdown libvirt
if [ -x /etc/rc.d/rc.libvirt ]; then
echo "Stopping libvirt..."
/etc/rc.d/rc.libvirt stop |& logger
fi
if [ "$(mount | grep domain.img)" ]; then
umount /etc/libvirt
fi

View File

@@ -0,0 +1,20 @@
#!/bin/sh
OLD_IMAGE=/boot/config/plugins/dynamix.kvm.manager/domain.img
if [ ! -f $OLD_IMAGE ]; then
OLD_IMAGE=/boot/config/plugins/virtMan/virtMan.img
if [ ! -f $OLD_IMAGE ]; then
OLD_IMAGE=
fi
fi
if [ "$OLD_IMAGE" != "" ]; then
mount $OLD_IMAGE /etc/libvirt-
cp -rp /etc/libvirt-/* /etc/libvirt
umount /etc/libvirt-
if [ ! -f /etc/libvirt/hooks/qemu ]; then
mkdir -p /etc/libvirt/hooks
cp -p /etc/libvirt-/hooks/qemu /etc/libvirt/hooks/qemu
fi
else
cp -rp /etc/libvirt-/* /etc/libvirt
fi