summaryrefslogtreecommitdiff
blob: 3c08c3fdc65ecdef8e09d0869f5e7dffa86688a3 (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
#!/sbin/openrc-run
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

command="/usr/bin/smokeping"
command_args="--nodaemon"
command_background="true"
command_user="smokeping:smokeping"
pidfile="/run/${RC_SVCNAME}.pid"
extra_started_commands="dump reload restore"
required_files="/etc/smokeping/config"

depend() {
	need net
	use dns
}

start_pre() {
    export LC_ALL=C
}

reload() {
	ebegin "Reloading smokeping"
	"${command}" --reload 2>&1 >/dev/null
	eend $?
}

dump() {
	ebegin "Dumping smokeping rrd files to XML for backup or upgrade use"
	if service_started "${myservice}" ; then
		eerror "You need to stop smokeping before dumping files!"
		return 1
	fi
	for f in $(find /var/lib/smokeping -name '*.rrd' -print) ; do
		f_xml=$(dirname $f)/$(basename $f .rrd).xml
		rrdtool dump "$f" > "${f_xml}"
		chown root:0 "${f_xml}"
	done
	eend $?
}

restore() {
	ebegin "Restoring smokeping rrd files from XML dump files"
	if service_started "${myservice}" ; then
		eerror "You need to stop smokeping before restoring files!"
		return 1
	fi
	for f in $(find /var/lib/smokeping -name '*.xml' -print) ; do
		f_rrd=$(dirname $f)/$(basename $f .xml).rrd
		mv -f "${f_rrd}" "${f_rrd}.bak"
		chown root:0 "${f_rrd}.bak"
		rrdtool restore "$f" "${f_rrd}"
		chown smokeping:smokeping "${f_rrd}"
	done
	eend $?
}