1#!/bin/sh
2
3# Add the following lines to /etc/rc.conf to enable iohyve:
4#
5# iohyve_enable="YES"
6#
7# PROVIDE: iohyve
8# REQUIRE: LOGIN sshd
9#
10
11. /etc/rc.subr
12
13name="iohyve"
14rcvar=iohyve_enable
15
16# read configuration and set defaults
17load_rc_config "$name"
18: ${iohyve_enable="NO"}
19: ${iohyve_flags=""}
20
21start_cmd="iohyve_start"
22stop_cmd="iohyve_stop"
23
24iohyve_start()
25{
26	echo "Starting iohyve guests..."
27	/usr/local/sbin/iohyve setup ${iohyve_flags}
28	local guests="$(zfs get -H -s local,received -o name,value -t filesystem iohyve:name | tr '\t' ',')"
29	for guest in $guests ; do
30		local dataset="$(echo $guest | cut -f1 -d,)"
31		local name="$(echo $guest | cut -f2 -d,)"
32
33		local bootprop="$(zfs get -H -o value iohyve:boot $dataset)"
34		if [ $bootprop = "1" ]; then
35			# Check dataset depth, used to ignore replication targets with boot=1 set
36			# normally dataset = "$pool/iohyve/$name"
37			depth="$(printf "$dataset" | grep -o "/" | wc -l)"
38
39			if [ "$depth" -eq 2 ]; then
40				printf "Starting $dataset\n"
41				/usr/local/sbin/iohyve start $name
42			else
43				printf "Skipping $dataset: Guest has non-standard path\n"
44			fi
45		fi
46	done
47}
48
49iohyve_stop()
50{
51	echo "Stopping all iohyve guests..."
52	/usr/local/sbin/iohyve scram
53}
54
55run_rc_command "$1"
56