summaryrefslogtreecommitdiffstats
path: root/testing/xen/xendomains.initd
blob: 0f309ef3d01fd7f6ad6de883121e920070b3382a (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/sbin/runscript

CMD=xm
/usr/sbin/$CMD list &> /dev/null
if test $? -ne 0
then
	CMD=xl
fi

/usr/sbin/$CMD list &> /dev/null
if test $? -ne 0
then
	eend 1;
	exit 1;
fi

# Correct exit code would probably be 5, but it's enough 
# if xend complains if we're not running as privileged domain
if ! [ -e /proc/xen/privcmd ]; then
	eend 1;
	exit 1;
fi

# See docs/misc/distro_mapping.txt
if [ -d /var/lock/subsys ]; then
	LOCKFILE=/var/lock/subsys/xendomains
else
	LOCKFILE=/var/lock/xendomains
fi

if [ -d /etc/sysconfig ]; then
	XENDOM_CONFIG=/etc/sysconfig/xendomains
else
	XENDOM_CONFIG=/etc/default/xendomains
fi

if ! [ -r $XENDOM_CONFIG ]; then
	eend 1;
	echo "$XENDOM_CONFIG not existing";
	exit 1;
fi

. $XENDOM_CONFIG

depend() {
	need xencommons
	after net xend
}

get_domname() {
	local name_from_file=$(sed -rn 's/^name\W*=\W*\"?([[:alnum:]_\.-]+)\"?\W*;?/\1/p' "${1}" | tail -n 1)

	if [[ -z ${name_from_file} ]] ; then
		basename "${1}"
	else
		echo ${name_from_file}  
	fi
}

is_running() {
	/usr/sbin/$CMD list "${1}" >/dev/null 2>&1
}

start() {
	einfo "Starting Xen domains in ${AUTODIR:=/etc/xen/auto}"

	for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do
		name=$(get_domname ${dom})
		if ! is_running ${name} ; then
			ebegin "  Starting domain ${name}"
			/usr/sbin/$CMD create --quiet --defconfig ${dom}
			eend $?
		else
			einfo "  Not starting ${name} - already running."
		fi
	done
}

stop() {
	einfo "Stopping Xen domains in ${AUTODIR:=/etc/xen/auto}"

	for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do
		name=$(get_domname ${dom})
		if is_running ${name} ; then
			ebegin "  Sending shutdown signal to ${name}"
			/usr/sbin/$CMD shutdown ${name} >/dev/null
			eend $?
		fi
	done

	for dom in $(ls "${AUTODIR:=/etc/xen/auto}/"* 2>/dev/null | sort); do
		name=$(get_domname ${dom})
		if is_running ${name} ; then
			ebegin "  Waiting for domain ${name} to shutdown"
			/usr/sbin/$CMD shutdown --wait ${name}
			eend $?
		else
			einfo "  Not stopping ${name} - not running."
		fi
	done
}

status() {
	/usr/sbin/$CMD list
}