aboutsummaryrefslogtreecommitdiffstats
path: root/main/xen/xendomains.initd
blob: d12577c2b0c4e5de80674841dd4e054ee1764a87 (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
#!/sbin/runscript

depend() {
	need xend
	after dhcp
}

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/xm 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}"
				xm create --quiet ${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}"
				xm 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"
				xm shutdown --wait ${name}
			eend $?
		else
			einfo "  Not stopping ${name} - not running."
		fi
	done
}

status() {
	/usr/sbin/xm list
}