blob: c453cff542877f11cc0e1aa30bc84986144fba6c (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dialup/isdn4k-utils/files/isdnlog.initd,v 1.4 2006/02/04 21:14:17 sbriesen Exp $
depend() {
need isdn
}
# gets list of installed cards
card_list() { # output: <contr> <chan> <card>
local IDMAP=() IDX=1 CONTR=0 LAST='-' CARD=''
read -a IDMAP < <(/bin/head 2>/dev/null -n1 /dev/isdninfo) || return 1
while [ ${IDX} -lt ${#IDMAP[*]} ]; do
CARD=${IDMAP[$IDX]}
if [ "${CARD}" != "-" -a "${CARD}" != "${LAST}" ]; then
echo "${CONTR} $((IDX-1)) ${CARD}"; : $((CONTR++))
fi
LAST="${CARD}"; : $((IDX++))
done
}
# get info by contr, chan or card
card_info() {
local MASK
case "${1}" in
contr[0-9]*)
MASK="^${1#contr*} [0-9]\+ .*\$"
;;
isdnctrl[0-9]*)
MASK="^[0-9]\+ ${1#isdnctrl*} .*\$"
;;
*)
MASK="^[0-9]\+ [0-9]\+ ${1}\$"
;;
esac
/bin/grep "${MASK}" <(card_list)
}
start() {
local CONTR CHAN CARD TYPE="${myservice#*.*}"
read CONTR CHAN CARD < <(card_info "${TYPE}")
if [ -z "${CARD}" ]; then
eerror "ISDNLOG: Selected controller not available (${TYPE})"
return 1
fi
# try to find a configuration file
local CONFIG="/etc/isdn/isdnlog.isdnctrl${CHAN}.options"
[ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.contr${CONTR}"
[ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.isdnctrl${CHAN}"
[ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.${CARD}"
if [ ! -f "${CONFIG}" ]; then
eerror "ISDNLOG: You're missing /etc/isdn/isdnlog.options.${TYPE}"
return 1
fi
rm -f "/var/run/${myservice}" # cleanup
ebegin "Starting ISDNLOG for controller #${CONTR} (${CARD})"
start-stop-daemon --start --quiet --pidfile "/var/run/isdnlog.isdnctrl${CHAN}.pid" \
--exec /usr/sbin/isdnlog -- ${ISDNLOG_OPTIONS} -f "${CONFIG}" "/dev/isdnctrl${CHAN}" && \
echo "${CONTR} ${CHAN} ${CARD} ${CONFIG##*/}" > "/var/run/${myservice}"
eend $?
}
stop() {
if [ ! -f "/var/run/${myservice}" ]; then
eerror "ISDNLOG: Controller setup not found (${myservice#*.*})"
return 1
fi
local CONTR CHAN CARD CONF
read CONTR CHAN CARD CONF < "/var/run/${myservice}"
ebegin "Stopping ISDNLOG for controller #${CONTR} (${CARD})"
start-stop-daemon --stop --quiet --retry 5 --pidfile "/var/run/isdnlog.isdnctrl${CHAN}.pid"
eend $?
rm -f "/var/run/${myservice}"
return 0 # ignore errors
}
|