#!/bin/sh
#
# This is a simple init script to auto-start/auto-stop KVM VMs
# when the host server boots or shuts down.
#
# This script should be set to run after networking is configured.
#
# Paths to kvmctl and the auto-start directory:
kvmctl=/usr/sbin/kvmctrl
autodir=/etc/kvm/auto

# Functions used in this script
do_action()
{
	for I in $( ls ${autodir} ); do
		NAME=$( echo $I | awk -F. '{ print $1 }')
		${kvmctl} "${1}" ${NAME}
	done
}

do_status()
{
	${kvmctl} status
}

# Main script
case "$1" in
	start)
		do_action "$1"
		;;
	stop)
		do_action destroy
		;;
	restart)
		do_action reset
		;;
	status)
		do_status
		;;
	*)
		echo "Usage: ${0} [start|stop|restart|status]"
		;;
esac
