summaryrefslogtreecommitdiff
blob: 837deccede7b45770ebddd947c98e077f189e1f5 (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
#!/sbin/runscript
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-emulation/xen-tools/files/xend.initd-r2,v 1.5 2014/01/02 04:58:53 idella4 Exp $

extra_commands="status"

depend() {
	need net xenconsoled xenstored
	before xendomains sshd
}

await_daemons_up() {
	for ((i=0; i<5; i++)); do
		sleep 1
		/usr/sbin/xend status && return 0
	done
	return 1
}

is_privileged_domain() {
	grep -qsE '^control_d$' /proc/xen/capabilities
	return $?
}

start() {
	if is_privileged_domain ; then
		ebegin "Starting Xen control daemon"
		/usr/sbin/xend start
		/usr/sbin/xend status || await_daemons_up
		eend $?
	else
		eerror "Can't start xend - this is not a privileged domain."
		return 1
	fi
}

stop() {
	if [ "$(xm list | wc -l)" -gt 2 ]; then
		ebegin "  Stopping all domains"
		/usr/sbin/xl shutdown -a -w >/dev/null
		eend $?
	fi

	ebegin "Stopping Xen control daemon"
	/usr/sbin/xend stop
	eend $?
}

status() {
	is_privileged_domain && /usr/sbin/xend status
}