summaryrefslogtreecommitdiffstats
path: root/znc/init.d/znc
blob: 23e7c437446ad529e68339f43fdfa019283260b1 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/sbin/runscript
# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: $

opts="checkconfig reload"

ZNC_USER=${ZNC_USER:-"nobody"}
ZNC_DAEMON=${ZNC_DAEMON:-"/usr/bin/znc"}

depend() {
	need net oidentd
}

checkconfig() {
	if [ -z "${ZNC_DATADIR}" ]; then
		eerror "Please set at least one datadir for ZNC!"
		return 1
	fi

	mkdir -p /var/run/znc/
	if [ ! -d /var/run/znc ]; then
		eerror "Unable to create /var/run/znc!"
		return 1
	fi

	return 0
}

start() {
	checkconfig || return 1
	ebegin "Starting ZNC"
	eindent

	for dir in ${ZNC_DATADIR}; do
		if [ -d "${dir}" ]; then
			ebegin "${dir}"

			pidfile=$(mktemp --tmpdir=/var/run/znc)
			start-stop-daemon --start --quiet \
					  --chuid ${ZNC_USER} \
					  --exec ${ZNC_DAEMON} \
					  --pidfile ${pidfile} \
					  --make-pidfile --background \
					  --chdir ${dir} --wait 500 \
					  -- -d ${dir} -f

			eend $?
		fi
	done

	eoutdent
}

stop() {
	checkconfig || return 1
	ebegin "Stopping ZNC"
	eindent

	for pidfile in /var/run/znc/* ; do
		if [ -r ${pidfile} ]; then
			pid=$(< ${pidfile})

			if [ -L /proc/${pid}/cwd ]; then
				ebegin $(readlink /proc/${pid}/cwd)

				start-stop-daemon --stop --user ${ZNC_USER} \
						  --exec ${ZNC_DAEMON} \
			                	  --pidfile ${pidfile}

				eend $?
			fi
		fi
	done

	eoutdent
}

reload() {
	ebegin "Reloading ZNC"
	eindent

	for pidfile in /var/run/znc/* ; do
		if [ -r ${pidfile} ]; then
			pid=$(< ${pidfile})

			if [ -L /proc/${pid}/cwd ]; then
				ebegin $(readlink /proc/${pid}/cwd)
				kill -HUP ${pid}
				eend $?
			fi
		fi
	done

	eoutdent
}