From 8f9e0ef6ae94d2741b3fedaabd0ffd93f541bfd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20G=C3=A9rczei?= Date: Fri, 29 Apr 2016 16:48:28 +0200 Subject: [PATCH] introduced a shutdown grace period defaulting to 5 minutes --- README.md | 2 +- guesthandler.xml | 8 +++++++- svc-guesthandler | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2377a51..3ce2b61 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ This will tag all VMs with the priority of 0 which will leave them stopp ...and so on. Informational messages are logged via the syslog facility as 'daemon.notice' entries tracking the determined order as well as the outcome for every step taken. The solution comprises two services backed by the same single method script: one activated before svc:/system/zones in order to convince it not to start any guests and the actual payload starting once vmadmd is available to evaluate the tags and complete the sequence. -SMF will import the manifests for the services upon boot-up when it initializes its repository. The location of the method script is configurable via the service property config/method_prefix, defaulting to /opt/custom/bin. The start-up delay defaults to 30 seconds, also configurable via the context environment variable DELAY for the method start. +SMF will import the manifests for the services upon boot-up when it initializes its repository. The location of the method script is configurable via the service property config/method_prefix, defaulting to /opt/custom/bin. The start-up delay defaults to 30 seconds, also configurable via the context environment variable DELAY for the method start. A grace period of 5 minutes is granted for shut-down, configurable via the context environment variable GRACE_PERIOD in the stop method. In the future the method script might get re-written in node.js in order to make a more human-friendly dependency notation/handling possible. This is merely the shortest path. diff --git a/guesthandler.xml b/guesthandler.xml index 1d0230b..2ac17f2 100644 --- a/guesthandler.xml +++ b/guesthandler.xml @@ -14,7 +14,13 @@ - + + + + + + + diff --git a/svc-guesthandler b/svc-guesthandler index ea316cf..847d869 100644 --- a/svc-guesthandler +++ b/svc-guesthandler @@ -5,8 +5,8 @@ if [ -z $SMF_FMRI ]; then - print "this script can only be invoked by smf(5)" - exit $SMF_EXIT_ERR_NOSMF + print "this script can only be invoked by smf(5)" + exit $SMF_EXIT_ERR_NOSMF fi ME=${0##*/svc-} @@ -58,6 +58,18 @@ case $1 in log $UUID failed to $1 fi done + + # grant the guests some time to shut down + WAIT_UNTIL=$(($(date +%s) + ${GRACE_PERIOD:-300})) + while [ $(zoneadm list | wc -l) -gt 1 ]; + do + if [ $(date +%s) -le $WAIT_UNTIL ]; + then + sleep 1 + else + exit $SMF_EXIT_ERR_FATAL + fi + done ;; disarm)