--- /dev/null
+#! /bin/sh
+
+set -e
+
+VIRSH_DEFAULT_CONNECT_URI="qemu:///system"
+export VIRSH_DEFAULT_CONNECT_URI
+
+usage="Usage: $0 COMMAND [DOMAIN ARGS...]"
+groups="$VMCTL_GROUP $USERV_GROUP"
+
+case x${USERV_SERVICE+t} in
+ xt) set -- "$USERV_SERVICE" "$@" ;;
+esac
+
+case "$#,$1" in
+ 1,help)
+ cat <<EOF
+$usage
+
+Commands:
+ status DOM Show domain status.
+ reset DOM Forcibly restart the domain.
+ stop DOM Forcibly turn off the domain.
+ reboot DOM Send the domain a reboot request.
+ shutdown DOM Send the domain a shutdown request.
+ save DOM Suspend the domain; restart using \`start'.
+ start DOM [-c] Start up the domain (-c: and attach to console).
+ console DOM Attach to the domain's console.
+EOF
+ exit 0
+ ;;
+ 0,* | 1,*) echo >&2 "$usage"; exit 1 ;;
+ *) cmd=$1 dom=$2; shift 2 ;;
+esac
+
+allow=nil
+while read grps doms; do
+ case "$grps" in "" | \#*) continue ;; esac
+ gmatch=nil dmatch=nil
+ for g in $groups; do
+ case ",$grps," in *,$g,*) gmatch=t ;; esac
+ done
+ for d in $doms; do
+ case "$dom" in $d) dmatch=t ;; esac
+ done
+ case $gmatch,$dmatch in t,t) allow=t; break ;; esac
+done <$HOME/vmctl.conf
+
+case $allow in nil) echo >&2 "$0: not permitted"; exit 1 ;; esac
+
+case "$#,$cmd" in
+ 0,status) virsh dominfo "$dom" ;;
+ 0,reset) virsh reset "$dom" ;;
+ 0,stop) virsh destroy "$dom" ;;
+ 0,reboot) virsh reboot "$dom" ;;
+ 0,shutdown) virsh shutdown "$dom" ;;
+ 0,start | 1,start)
+ args=""
+ case "$#,$1" in
+ 0,) ;;
+ 1,-c | 1,--console) args="$args --console" ;;
+ *) echo >&2 "Usage: $0 DOMAIN start [-c]"; exit 1 ;;
+ esac
+ virsh start "$dom" $args
+ ;;
+ 0,save) virsh managedsave "$dom" ;;
+ 0,console) virsh console "$dom" ;;
+ *) echo >&2 "$usage"; exit 1 ;;
+esac