1 |
chainsaw 11/09/01 14:09:56 |
2 |
|
3 |
Added: asterisk.confd asterisk.initd |
4 |
Log: |
5 |
Version bump. New & improved init script by Jaco Kroon closes bug #363267. EAPI 4 porting by Agostino "ago" Sarubbo closes bug #380359. |
6 |
|
7 |
(Portage version: 2.1.10.11/cvs/Linux x86_64) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 net-misc/asterisk/files/1.8.0/asterisk.confd |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.confd?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.confd?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: asterisk.confd |
16 |
=================================================================== |
17 |
# Copyright 1999-2011 Gentoo Foundation |
18 |
# Distributed under the terms of the GNU General Public License v2 |
19 |
# $Header: /var/cvsroot/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.confd,v 1.1 2011/09/01 14:09:56 chainsaw Exp $ |
20 |
|
21 |
# |
22 |
# Additional options for asterisk |
23 |
# |
24 |
# see "asterisk -h" for a list of options |
25 |
# |
26 |
ASTERISK_OPTS="" |
27 |
|
28 |
# |
29 |
# User and group to run asterisk as |
30 |
# |
31 |
# Value: double-colon separated list of user and group, or empty to run as root: |
32 |
# |
33 |
# |
34 |
# "asterisk:asterisk" to run as user "asterisk" and group "asterisk" |
35 |
# |
36 |
# "asterisk" to run as user "asterisk" and all groups that user "asterisk" is a member of |
37 |
# |
38 |
# ":asterisk" to run as user "root" and group "asterisk" |
39 |
# |
40 |
# "" to run as user "root" and group "root" |
41 |
# |
42 |
ASTERISK_USER="asterisk" |
43 |
|
44 |
# |
45 |
# Nicelevel |
46 |
# |
47 |
# Set the priority of the asterisk process |
48 |
# |
49 |
# Value: (highest) -20..19 (lowest) |
50 |
# |
51 |
#ASTERISK_NICE="19" |
52 |
|
53 |
# Send crash notifications emails to this address |
54 |
# (needs a working mail service and /usr/sbin/sendmail to do so (e.g. ssmtp)) |
55 |
# |
56 |
# Value: Email address or empty to disable |
57 |
# |
58 |
#ASTERISK_NOTIFY_EMAIL="root" |
59 |
|
60 |
# |
61 |
# Send asterisk's output to this terminal |
62 |
# |
63 |
# Value: Full path to device node or a number |
64 |
# |
65 |
#ASTERISK_TTY="/dev/tty9" |
66 |
|
67 |
# |
68 |
# Start an asterisk console on the terminal specified by ASTERISK_TTY |
69 |
# |
70 |
# Warning! Use only for debugging, this is a potential security issue! |
71 |
# |
72 |
# Value: yes or no/empty |
73 |
# |
74 |
ASTERISK_CONSOLE="no" |
75 |
|
76 |
# |
77 |
# Maximum size of core files. |
78 |
# |
79 |
# Value: Size in bytes, unlimited for no limit or empty to disable. |
80 |
# |
81 |
ASTERISK_CORE_SIZE="unlimited" |
82 |
|
83 |
# |
84 |
# ASTERISK_CORE_DIR |
85 |
# |
86 |
# Value: Directory (will be created if non-existant), default is /tmp |
87 |
# |
88 |
ASTERISK_CORE_DIR="/var/lib/asterisk/coredump" |
89 |
|
90 |
# |
91 |
# Max number of filedescriptors |
92 |
# |
93 |
# Value: Number of descriptors |
94 |
# |
95 |
ASTERISK_MAX_FD="4096" |
96 |
|
97 |
# |
98 |
# Delay time before restarting asterisk after a crash. |
99 |
# |
100 |
# Value: Number of seconds to sleep after a crash before restarting. |
101 |
# |
102 |
ASTERISK_RESTART_DELAY=5 |
103 |
|
104 |
# |
105 |
# Kill these tasks after asterisk crashed |
106 |
# |
107 |
# Warning! This will kill _ALL_ tasks with the specified names! |
108 |
# |
109 |
# Value: Space separated list of names in double quotes (e.g. "mpg123 mad") |
110 |
# |
111 |
#ASTERISK_CLEANUP_ON_CRASH="mpg123 asterisk-mpg123 mad" |
112 |
|
113 |
|
114 |
|
115 |
1.1 net-misc/asterisk/files/1.8.0/asterisk.initd |
116 |
|
117 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.initd?rev=1.1&view=markup |
118 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.initd?rev=1.1&content-type=text/plain |
119 |
|
120 |
Index: asterisk.initd |
121 |
=================================================================== |
122 |
#!/sbin/runscript |
123 |
# Copyright 1999-2011 Gentoo Foundation |
124 |
# Distributed under the terms of the GNU General Public License v2 |
125 |
# $Header: /var/cvsroot/gentoo-x86/net-misc/asterisk/files/1.8.0/asterisk.initd,v 1.1 2011/09/01 14:09:56 chainsaw Exp $ |
126 |
|
127 |
opts="${opts} forcestop reload" |
128 |
|
129 |
depend() { |
130 |
need net |
131 |
use nscd dns dahdi mysql postgresql slapd capi |
132 |
} |
133 |
|
134 |
is_running() { |
135 |
if [ -z "`pidof asterisk`" ]; then |
136 |
return 1 |
137 |
else |
138 |
PID="`cat /var/run/asterisk/asterisk.pid`" |
139 |
for x in `pidof asterisk`; do |
140 |
if [ "${x}" = "${PID}" ]; then |
141 |
return 0 |
142 |
fi |
143 |
done |
144 |
fi |
145 |
|
146 |
return 1 |
147 |
} |
148 |
|
149 |
asterisk_run_loop() { |
150 |
local result=0 signal=0 |
151 |
|
152 |
echo "Initializing asterisk wrapper" |
153 |
OPTS="$*" |
154 |
|
155 |
trap "rm /var/run/asterisk/wrapper_loop.pid" EXIT |
156 |
cut -f4 -d' ' < /proc/self/stat > /var/run/asterisk/wrapper_loop.pid |
157 |
|
158 |
while :; do |
159 |
if [ -n "${TTY}" ]; then |
160 |
/usr/bin/stty -F ${TTY} sane |
161 |
${NICE} /usr/sbin/asterisk ${OPTS} >${TTY} 2>&1 <${TTY} |
162 |
result=$? |
163 |
else |
164 |
set -o pipefail |
165 |
${NICE} /usr/sbin/asterisk ${OPTS} 2>&1 >/dev/null |
166 |
result=$? |
167 |
set +o pipefail |
168 |
fi |
169 |
|
170 |
if [ $result -eq 0 ]; then |
171 |
echo "Asterisk terminated normally" |
172 |
break |
173 |
else |
174 |
if [ $result -gt 128 ]; then |
175 |
signal=`expr $result - 128` |
176 |
MSG="Asterisk terminated with Signal: $signal" |
177 |
|
178 |
CORE_TARGET="core-`date +%Y%m%d-%H%M%S`" |
179 |
|
180 |
local CORE_DUMPED=0 |
181 |
if [ -f "${ASTERISK_CORE_DIR}/core" ]; then |
182 |
mv "${ASTERISK_CORE_DIR}/core" \ |
183 |
"${ASTERISK_CORE_DIR}/${CORE_TARGET}" |
184 |
CORE_DUMPED=1 |
185 |
|
186 |
elif [ -f "${ASTERISK_CORE_DIR}/core.${PID}" ]; then |
187 |
mv "${ASTERISK_CORE_DIR}/core.${PID}" \ |
188 |
"${ASTERISK_CORE_DIR}/${CORE_TARGET}" |
189 |
CORE_DUMPED=1 |
190 |
|
191 |
fi |
192 |
|
193 |
[ $CORE_DUMPED -eq 1 ] && \ |
194 |
MSG="${MSG}\n\rCore dumped: ${ASTERISK_CORE_DIR}/${CORE_TARGET}" |
195 |
else |
196 |
MSG="Asterisk terminated with return code: $result" |
197 |
fi |
198 |
|
199 |
# kill left-over tasks |
200 |
for X in ${ASTERISK_CLEANUP_ON_CRASH}; do |
201 |
kill -9 `pidof ${X}`; |
202 |
done |
203 |
fi |
204 |
|
205 |
[ -n "${TTY}" ] \ |
206 |
&& echo "${MSG}" >${TTY} \ |
207 |
|| echo "${MSG}" |
208 |
|
209 |
|
210 |
if [ -n "${ASTERISK_NOTIFY_EMAIL}" ] && \ |
211 |
[ -x /usr/sbin/sendmail ]; then |
212 |
echo -e -n "Subject: Asterisk crashed\n\r${MSG}\n\r" |\ |
213 |
/usr/sbin/sendmail "${ASTERISK_NOTIFY_EMAIL}" |
214 |
fi |
215 |
sleep "${ASTERISK_RESTART_DELAY}" |
216 |
echo "Restarting Asterisk..." |
217 |
done |
218 |
return 0 |
219 |
} |
220 |
|
221 |
start() { |
222 |
local OPTS USER GROUP PID NICE="" |
223 |
local tmp x |
224 |
|
225 |
local OPTS ARGS |
226 |
|
227 |
ebegin "Starting asterisk PBX" |
228 |
|
229 |
eindent |
230 |
|
231 |
# filter (redundant) arguments |
232 |
OPTS=`echo "${ASTERISK_OPTS}" | sed -re "s:-[cfF]::g"` |
233 |
|
234 |
# default options |
235 |
OPTS="${OPTS} -f" # don't fork / detach breaks wrapper script... |
236 |
|
237 |
# mangle yes/no options |
238 |
ASTERISK_CONSOLE="`echo ${ASTERISK_CONSOLE} | tr '[:lower:]' '[:upper:]'`" |
239 |
|
240 |
ASTERISK_RESTART_DELAY="`echo "${ASTERISK_RESTART_DELAY}" | sed -re 's/^([0-9]*).*/\1/'`" |
241 |
[ -z "${ASTERISK_RESTART_DELAY}" ] && ASTERISK_RESTART_DELAY=5 |
242 |
|
243 |
if [ -n "${ASTERISK_CORE_SIZE}" ] && |
244 |
[ "${ASTERISK_CORE_SIZE}" != "0" ]; then |
245 |
ulimit -c ${ASTERISK_CORE_SIZE} |
246 |
|
247 |
if [ -n "${ASTERISK_CORE_DIR}" ] && \ |
248 |
[ ! -d "${ASTERISK_CORE_DIR}" ] |
249 |
then |
250 |
mkdir -m750 -p "${ASTERISK_CORE_DIR}" |
251 |
|
252 |
if [ -n "${ASTERISK_USER}" ]; then |
253 |
chown -R "${ASTERISK_USER}" "${ASTERISK_CORE_DIR}" |
254 |
fi |
255 |
fi |
256 |
ASTERISK_CORE_DIR="${ASTERISK_CORE_DIR:-/tmp}" |
257 |
|
258 |
cd "${ASTERISK_CORE_DIR}" |
259 |
einfo "Core dump size : ${ASTERISK_CORE_SIZE}" |
260 |
einfo "Core dump location : ${ASTERISK_CORE_DIR}" |
261 |
|
262 |
OPTS="${OPTS} -g" |
263 |
fi |
264 |
|
265 |
if [ -n "${ASTERISK_MAX_FD}" ]; then |
266 |
ulimit -n ${ASTERISK_MAX_FD} |
267 |
einfo "Max open filedescriptors : ${ASTERISK_MAX_FD}" |
268 |
fi |
269 |
|
270 |
if [ -n "${ASTERISK_NICE}" ]; then |
271 |
if [ ${ASTERISK_NICE} -ge -20 ] && \ |
272 |
[ ${ASTERISK_NICE} -le 19 ]; then |
273 |
einfo "Nice level : ${ASTERISK_NICE}" |
274 |
NICE="nice -n ${ASTERISK_NICE} --" |
275 |
else |
276 |
eerror "Nice value must be between -20 and 19" |
277 |
return 1 |
278 |
fi |
279 |
fi |
280 |
|
281 |
if [ -n "${ASTERISK_NOTIFY_EMAIL}" ]; then |
282 |
if [ -x /usr/sbin/sendmail ]; then |
283 |
einfo "Email notifications go to : ${ASTERISK_NOTIFY_EMAIL}" |
284 |
else |
285 |
ewarn "Notifications disabled, /usr/sbin/sendmail doesn't exist or is not executable!" |
286 |
unset ASTERISK_NOTIFY_EMAIL |
287 |
fi |
288 |
fi |
289 |
|
290 |
if [ -n "${ASTERISK_TTY}" ]; then |
291 |
for x in ${ASTERISK_TTY} \ |
292 |
/dev/tty${ASTERISK_TTY} \ |
293 |
/dev/vc/${ASTERISK_TTY} |
294 |
do |
295 |
if [ -c "${x}" ]; then |
296 |
TTY="${x}" |
297 |
fi |
298 |
done |
299 |
[ -n "${TTY}" ] && \ |
300 |
einfo "Messages are sent to : ${TTY}" |
301 |
fi |
302 |
|
303 |
if [ "${ASTERISK_CONSOLE}" = "YES" ] && [ -n "${TTY}" ]; then |
304 |
einfo "Starting Asterisk console : ${ASTERISK_CONSOLE}" |
305 |
OPTS="${OPTS} -c" |
306 |
fi |
307 |
|
308 |
if [ -n "${ASTERISK_USER}" ]; then |
309 |
USER=`echo $ASTERISK_USER | sed 's/:.*//'` |
310 |
GROUP=`echo $ASTERISK_USER | awk -F: '/.*:.*/ { print $2 }'` |
311 |
if [ -n "${USER}" ]; then |
312 |
OPTS="${OPTS} -U ${USER}" |
313 |
fi |
314 |
if [ -n "${GROUP}" ]; then |
315 |
OPTS="${OPTS} -G ${GROUP}" |
316 |
GROUP=":${GROUP}" # make it look nice... |
317 |
fi |
318 |
for element in `find /var/{log,run}/asterisk`; do |
319 |
if [ `stat -c %U $element` != "${USER}" ]; then |
320 |
ewarn "${USER} is not the owner of $element, fixing." |
321 |
chown -R ${USER} /var/{log,run}/asterisk |
322 |
chmod -R u+r /var/{log,run}/asterisk |
323 |
chmod u+x /var/{log,run}/asterisk |
324 |
fi; |
325 |
done; |
326 |
einfo "Starting asterisk as : ${USER}${GROUP}" |
327 |
else |
328 |
ewarn "Starting asterisk as root is not recommended." |
329 |
fi |
330 |
|
331 |
asterisk_run_loop ${OPTS} 2>&1 | logger -t asterisk_wrapper & |
332 |
result=$? |
333 |
|
334 |
if [ $result -eq 0 ]; then |
335 |
# 2 seconds should be enough for asterisk to start |
336 |
sleep 2 |
337 |
is_running |
338 |
result=$? |
339 |
fi |
340 |
|
341 |
eoutdent |
342 |
eend $result |
343 |
} |
344 |
|
345 |
forcestop() { |
346 |
ebegin "Stopping asterisk PBX" |
347 |
start-stop-daemon --stop --pidfile /var/run/asterisk/asterisk.pid |
348 |
eend $? |
349 |
} |
350 |
|
351 |
stop() { |
352 |
if ! is_running; then |
353 |
eerror "Asterisk is not running!" |
354 |
return 0 |
355 |
fi |
356 |
|
357 |
if [ -r /var/run/asterisk/wrapper_loop.pid ]; then |
358 |
ebegin "Killing wrapper script" |
359 |
kill `cat /var/run/asterisk/wrapper_loop.pid` |
360 |
eend $? |
361 |
fi |
362 |
|
363 |
ebegin "Stopping asterisk PBX gracefully" |
364 |
/usr/sbin/asterisk -r -x "core stop gracefully" &>/dev/null |
365 |
# Now we have to wait until asterisk has _really_ stopped. |
366 |
sleep 1 |
367 |
if is_running; then |
368 |
einfon "Waiting for asterisk to shutdown ." |
369 |
local cnt=0 |
370 |
while is_running; do |
371 |
cnt=`expr $cnt + 1` |
372 |
if [ $cnt -gt 60 ] ; then |
373 |
# Waited 120 seconds now. Fail. |
374 |
echo |
375 |
eend 1 "Failed." |
376 |
return |
377 |
fi |
378 |
sleep 2 |
379 |
echo -n "." |
380 |
done |
381 |
echo |
382 |
fi |
383 |
eend 0 |
384 |
} |
385 |
|
386 |
reload() { |
387 |
if is_running; then |
388 |
ebegin "Forcing asterisk to reload configuration" |
389 |
/usr/sbin/asterisk -r -x "module reload" &>/dev/null |
390 |
eend $? |
391 |
else |
392 |
eerror "Asterisk is not running!" |
393 |
fi |
394 |
} |