summaryrefslogtreecommitdiff
blob: b34a5a7257c28cc3426d7a91bf91d5bb32c45941 (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
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

opts="start stop status restart"

depend() {
	need net
	before xendomains sshd ntp-client ntpd nfs nfsmount rsyncd portmap dhcp
}

await_daemons_up() {
	for ((i=0; i<5; i++)); do
		/usr/sbin/xend status && return 0
		sleep 1
	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 && await_daemons_up
		eend $?
	else
		eerror "Can't start xend - this is not a privileged domain."
		return 1
	fi
}

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

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

	#ebegin "Stopping xenconsoled"
	#kill $(</var/run/xenconsoled.pid)
	#eend $?

	#ebegin "Stopping xenstored"
	#kill $(</var/run/xenstore.pid)
	#eend $?
}

restart() {
	# IMPORTANT: do NOT restart xenstored/xenconsoled when restarting
	# just xend, as this can be fatal!
	# When restarting xend, leave alone xenstored/xenconsoled and all
	# running domains.
	# See http://article.gmane.org/gmane.comp.emulators.xen.user/40656
	ebegin "Restarting Xen control daemon"
	/usr/sbin/xend restart
	eend $?
	# we fool /etc/init.d/runscript.sh:svc_restart() here: svc_stop svc_start
}

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