summaryrefslogtreecommitdiff
path: root/net-analyzer/icinga/files/icinga-init.d
blob: 3a20f31c1940b19405d8c1a0ed1a276154e821d0 (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
#!/sbin/openrc-run
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

: ${ICINGACFG:=/etc/icinga/icinga.cfg}

extra_commands="checkconfig"
extra_started_commands="reload"

command=/usr/sbin/icinga
command_args="-d ${ICINGACFG}"

get_config() {
    if [ -e "${ICINGACFG}" ]; then
	    sed -n -e 's:^[ \t]*'$1'=\([^#]\+\).*:\1:p' "${ICINGACFG}"
	fi
}

pidfile=$(get_config lock_file)
start_stop_daemon_args="-e HOME=/var/lib/icinga"

depend() {
	need net
	use dns logger firewall mysql postgresql
}

checkconfig() {
	# Silent Check
	${command} -v ${ICINGACFG} &>/dev/null && return 0
	# Now we know there's problem - run again and display errors
	${command} -v ${ICINGACFG}
	eend $? "Configuration Error. Please fix your configfile"
}

reload()
{
	checkconfig || return 1
	ebegin "Reloading configuration"
	kill -HUP $(cat ${pidfile}) &>/dev/null
	eend $?
}

start_pre() {
	checkpath -d -o icinga:icinga $(dirname $(get_config lock_file)) $(dirname $(get_config log_file)) $(dirname $(get_config status_file))
	checkpath -f -o icinga:icinga $(get_config log_file)
	rm -f $(get_config command_file)
	# Temp dir must NOT be group-writable
	# grsec: denied untrusted exec (due to file in group-writable directory)
	checkpath -d -o icinga:icinga -m 0750 $(get_config temp_path)
}

stop_post() {
	rm -f $(get_config command_file)
	rm -r /tmp/icinga
}

svc_restart() {
	checkconfig || return 1
	ebegin "Restarting icinga"
	svc_stop
	svc_start
	eend $?
}