1#!/bin/bash
2#
3# Copyright (c) 2016 SUSE Linux GmbH
4#
5# This library is free software; you can redistribute it and/or
6# modify it under the terms of version 2.1 of the GNU Lesser General Public
7# License as published by the Free Software Foundation.
8#
9# This library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public
15# License along with this library; If not, see <http://www.gnu.org/licenses/>.
16#
17
18XENSTORED=@XENSTORED@
19
20. @XEN_SCRIPT_DIR@/hotplugpath.sh
21
22test_xenstore () {
23	test -f @XEN_RUN_DIR@/xenstored.pid
24	return $?
25}
26
27timeout_xenstore () {
28	local time=0
29	local timeout=30
30
31	while [ $time -lt $timeout ] && ! test_xenstore ; do
32		echo -n .
33		time=$(($time+1))
34		sleep 1
35	done
36	echo
37
38	# Exit if we timed out
39	if ! [ $time -lt $timeout ] ; then
40		echo "Could not start $@"
41		return 1
42	fi
43
44	return 0
45}
46
47test_xenstore && exit 0
48
49test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons
50
51[ "$XENSTORETYPE" = "" ] && XENSTORETYPE=daemon
52
53/bin/mkdir -p @XEN_RUN_DIR@
54
55[ "$XENSTORETYPE" = "daemon" ] && {
56	[ -z "$XENSTORED_ROOTDIR" ] && XENSTORED_ROOTDIR="@XEN_LIB_STORED@"
57	[ -z "$XENSTORED_TRACE" ] || XENSTORED_ARGS="$XENSTORED_ARGS -T @XEN_LOG_DIR@/xenstored-trace.log"
58	[ -z "$XENSTORED" ] && XENSTORED=@XENSTORED@
59	[ -x "$XENSTORED" ] || {
60		echo "No xenstored found"
61		exit 1
62	}
63
64	echo -n Starting $XENSTORED...
65	$XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS
66
67	systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exit 1
68
69	exit 0
70}
71
72[ "$XENSTORETYPE" = "domain" ] && {
73	[ -z "$XENSTORE_DOMAIN_KERNEL" ] && XENSTORE_DOMAIN_KERNEL=@LIBEXEC@/boot/xenstore-stubdom.gz
74	XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS --kernel $XENSTORE_DOMAIN_KERNEL"
75	[ -z "$XENSTORE_DOMAIN_SIZE" ] && XENSTORE_DOMAIN_SIZE=8
76	XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS --memory $XENSTORE_DOMAIN_SIZE"
77	[ -z "$XENSTORE_MAX_DOMAIN_SIZE" ] || XENSTORE_DOMAIN_ARGS="$XENSTORE_DOMAIN_ARGS --maxmem $XENSTORE_MAX_DOMAIN_SIZE"
78
79	echo -n Starting $XENSTORE_DOMAIN_KERNEL...
80	${LIBEXEC_BIN}/init-xenstore-domain $XENSTORE_DOMAIN_ARGS || exit 1
81	systemd-notify --ready 2>/dev/null
82
83	exit 0
84}
85
86echo "illegal value $XENSTORETYPE for XENSTORETYPE"
87exit 1
88