chiark / gitweb /
Initial version.
[vmctl] / bin / vmctl
CommitLineData
da13c871
MW
1#! /bin/sh
2
3set -e
4
5VIRSH_DEFAULT_CONNECT_URI="qemu:///system"
6export VIRSH_DEFAULT_CONNECT_URI
7
8usage="Usage: $0 COMMAND [DOMAIN ARGS...]"
9groups="$VMCTL_GROUP $USERV_GROUP"
10
11case x${USERV_SERVICE+t} in
12 xt) set -- "$USERV_SERVICE" "$@" ;;
13esac
14
15case "$#,$1" in
16 1,help)
17 cat <<EOF
18$usage
19
20Commands:
21 status DOM Show domain status.
22 reset DOM Forcibly restart the domain.
23 stop DOM Forcibly turn off the domain.
24 reboot DOM Send the domain a reboot request.
25 shutdown DOM Send the domain a shutdown request.
26 save DOM Suspend the domain; restart using \`start'.
27 start DOM [-c] Start up the domain (-c: and attach to console).
28 console DOM Attach to the domain's console.
29EOF
30 exit 0
31 ;;
32 0,* | 1,*) echo >&2 "$usage"; exit 1 ;;
33 *) cmd=$1 dom=$2; shift 2 ;;
34esac
35
36allow=nil
37while read grps doms; do
38 case "$grps" in "" | \#*) continue ;; esac
39 gmatch=nil dmatch=nil
40 for g in $groups; do
41 case ",$grps," in *,$g,*) gmatch=t ;; esac
42 done
43 for d in $doms; do
44 case "$dom" in $d) dmatch=t ;; esac
45 done
46 case $gmatch,$dmatch in t,t) allow=t; break ;; esac
47done <$HOME/vmctl.conf
48
49case $allow in nil) echo >&2 "$0: not permitted"; exit 1 ;; esac
50
51case "$#,$cmd" in
52 0,status) virsh dominfo "$dom" ;;
53 0,reset) virsh reset "$dom" ;;
54 0,stop) virsh destroy "$dom" ;;
55 0,reboot) virsh reboot "$dom" ;;
56 0,shutdown) virsh shutdown "$dom" ;;
57 0,start | 1,start)
58 args=""
59 case "$#,$1" in
60 0,) ;;
61 1,-c | 1,--console) args="$args --console" ;;
62 *) echo >&2 "Usage: $0 DOMAIN start [-c]"; exit 1 ;;
63 esac
64 virsh start "$dom" $args
65 ;;
66 0,save) virsh managedsave "$dom" ;;
67 0,console) virsh console "$dom" ;;
68 *) echo >&2 "$usage"; exit 1 ;;
69esac