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

description="IAXmodem"
description_reload="Reread configuration file and make the appropriate changes"
extra_started_commands="reload"
command="/usr/sbin/iaxmodem"
pidfile="/var/run/iaxmodem.pid"
name="iaxmodem"

depend() {
	use asterisk
	need net
}

start() {
	ebegin "Starting ${description}"
	start-stop-daemon --start --quiet --pidfile "${pidfile}" \
		--env TMPDIR="/tmp" --nice ${IAXMODEM_NICE:-0} --exec "${command}"
	eend ${?}
}

stop() {
	local childs=""
	ebegin "Stopping ${description}"
	# start-stop-daemon doesn't kill childs reliable, so we
	# use a combination of pgrep + start-stop-daemon + kill
	[ -s "${pidfile}" ] && childs=$(pgrep -P $(cat "${pidfile}"))
	start-stop-daemon --stop --quiet --pidfile "${pidfile}" --retry TERM/10/KILL/5
	if eend ${?}; then
		# if there're still childs running, kill them!
		[ -n "${childs}" ] && kill -KILL ${childs} 2>/dev/null
		return 0 
	fi
}

reload() {
	ebegin "Reloading ${description} configuration"
	start-stop-daemon --stop --signal HUP --pidfile "${pidfile}"
	eend ${?}
}