summaryrefslogtreecommitdiffstats
path: root/etc/initsystem/safe-reload.cmake
blob: 0cba415d00c0f52464a7e8e262bc01ccfbc3d7c4 (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
#!/bin/sh

# Load sysconf on systems where the initsystem does not pass the environment
if [ "$1" != "" ]; then
	if [ -r "$1" ]; then
		. "$1"
	else
		echo "Unable to read sysconf from '$1'. Exiting."
		exit 6
	fi
fi

# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"

: "${ICINGA2_PID_FILE:="@ICINGA2_FULL_INITRUNDIR@/icinga2.pid"}"
: "${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}"

printf "Validating config files: "

OUTPUTFILE=`mktemp`

if type selinuxenabled >/dev/null 2>&1; then
	if selinuxenabled; then
		chcon -t icinga2_tmp_t "$OUTPUTFILE" >/dev/null 2>&1
	fi
fi

if ! "$DAEMON" daemon --validate --color > "$OUTPUTFILE"; then
	echo "Failed"

	cat "$OUTPUTFILE"
	rm -f "$OUTPUTFILE"
	exit 1
fi

echo "Done"
rm -f "$OUTPUTFILE"

printf "Reloading Icinga 2: "

if [ ! -e "$ICINGA2_PID_FILE" ]; then
	exit 7
fi

pid=`cat "$ICINGA2_PID_FILE"`
if ! kill -HUP "$pid" >/dev/null 2>&1; then
	echo "Error: Icinga not running"
	exit 7
fi

echo "Done"
exit 0