-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxen-start
More file actions
executable file
·43 lines (37 loc) · 1.19 KB
/
xen-start
File metadata and controls
executable file
·43 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
set -o nounset
set -o errexit
if [ "$(id -u)" != "0" ]; then
echo "You aren't root..." >&2
exit 2
fi
#if [ -z "$1" ]; then
if [ $# -lt 1 ]; then
echo "usage: $0 LIST,OF,DOMS,... [--force]" >&2
echo " --force: Start the VM even if its disk isn't synced"
exit 1
fi
for VM in $(echo "$1" | sed 's/,/ /g'); do
echo "Going to start $VM"
DISKS="$(grep "'phy:/dev/drbd_" "/etc/xen/$VM.cfg" | sed -e 's/^.*phy://' -e 's/,.*//' -e 's/.*drbd_//')"
for DISK in $DISKS; do
echo -n " Is $DISK in sync? "
if (drbd-overview | grep "$DISK.*UpToDate/UpToDate" > /dev/null); then
echo -n "Yes."
else
if [ $# -ge 2 ] && [ "$2" == "--force" ]; then
echo "No, but you told me to start it anyway."
else
echo "No, and I won't start that VM until it is." >&2; exit 3
fi
fi
echo -n " Is it primary somewhere? "
(drbd-overview | grep "$DISK.*Primary" > /dev/null) && (echo "Yes. Are you sure it isn't already running?" >&2; exit 4)
echo "No."
echo " Making $DISK primary here"
(drbdadm primary $DISK) || (echo "Well, that failed..." >&2; exit 5)
done
echo "Creating $VM."
(xl create /etc/xen/$VM.cfg) || (echo "I'm so sorry." >&2; exit 6)
echo "DONE with $VM."
done