mirror of https://github.com/tgerczei/smartos-guesthandler.git synced 2024-06-15 22:22:30 +00:00
Ordered guest boot-up and shutdown sequences for SmartOS
Go to file
2018-07-07 16:56:03 +02:00
guesthandler-disarm.xml added a comment to the disarm service manifest about the dependent platform service 2016-04-19 19:35:59 +02:00
guesthandler.xml introduced the environment variable WAIT_INTERVAL for the grace period in the stop method 2016-04-30 07:26:41 +02:00
LICENSE license provided 2016-04-19 15:37:28 +02:00
README.md clarified a few, possibly dubious things in the documentation, as discussed on the SmartOS mailing list 2018-07-07 16:56:03 +02:00
svc-guesthandler introduced the environment variable WAIT_INTERVAL for the grace period in the stop method 2016-04-30 07:26:41 +02:00

A makeshift solution to extend SmartOS with the capability to order VM boot and shut-down sequences by priority. It leverages SMF 'hot-plugging' built into the platform as well as vmadm's ability to tag guests. Technically it mitigates the built-in auto-boot procedure by intervening in due time and afterwards starts/stops VMs in an order derived from the numerical value of the 'property' tag. My use-case: a single toy rig running vanilla SmartOS acting as an all-in-one system providing a range of services including infrastructural ones like name resolution and IP address allocation as well as an edge firewall; each contained in a dedicated guest which will, in turn, depend on another.

A logical pre-requisite of all this is tagging the VMs ideally upon creation or otherwise:

vmadm list -Ho uuid | while read UUID; do vmadm update $UUID <<< "{\"set_tags\": {\"priority\": 0}}"; done

This will tag all VMs with the priority of 0 which will leave them stopped. Afterwards an actual order needs to be established by assigning non-zero values to them one by one in ascending order where lesser values represent higher priorities - with the notable exception of 0 - and thus earlier start-up:

vmadm update <UUID> <<< "{\"set_tags\": {\"priority\": 100}}"

...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 (the XML documents in this repository) for the services upon boot-up when it initializes its repository, provided they are placed under a directory named /opt/custom/smf. The location of the method script is configurable via the service property config/method_prefix, defaulting to /opt/custom/bin - the file needs to be executable and this directory may have to be created first, unless another, already present one is chosen. 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 variables GRACE_PERIOD and WAIT_INTERVAL 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.