1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2017 OpenWrt.org
11 DEFAULT
=/etc
/default
/$DAEMON
12 LOGGER
="/usr/bin/logger -p user.err -s -t $DAEMON"
17 [ -f $DEFAULT ] && .
$DEFAULT
22 if [ "$ENABLE_BARESIP" != yes ]; then
23 $LOGGER User configuration incomplete
- not starting
$DAEMON
24 $LOGGER Check ENABLE_BARESIP
in $DEFAULT
29 procd_set_param
command $PROG
30 procd_append_param
command \
33 procd_set_param pidfile
/var
/run
/${DAEMON}.pid
34 # forward stderr to logd
35 procd_set_param stderr
1
36 # forward stdout to logd
37 #procd_set_param stdout 1
38 procd_set_param user
$DAEMON
45 local timeout
=$TIMEOUT
47 pgrep
$DAEMON &> /dev
/null
48 [ $?
-ne 0 ] && exit 0
50 [ -f /var
/run
/${DAEMON}.pid
]
53 # init script could find itself in a scenario where baresip was started
54 # very recently, so make it wait a while for a pid file to appear
55 while [ $retval -ne 0 -a $timeout -gt 0 ]; do
57 [ -f /var
/run
/${DAEMON}.pid
]
59 timeout
=$
(($timeout-1))
62 [ $retval -eq 0 ] ||
{
63 $LOGGER PID
file does not exist
67 mypid
=$
(cat /var
/run
/${DAEMON}.pid
)
69 [ "$mypid" -gt 1 ] 2> /dev
/null ||
{
70 $LOGGER PID
file contains garbage
75 kill $mypid 2>/dev
/null
76 pgrep
$DAEMON |
grep -w $mypid &>/dev
/null
79 while [ $retval -eq 0 -a $timeout -gt 0 ]; do
81 pgrep
$DAEMON |
grep -w $mypid &>/dev
/null
83 [ $retval -eq 0 ] && kill $mypid 2>/dev
/null
84 timeout
=$
(($timeout-10))
87 [ $retval -ne 1 ] && {
88 $LOGGER Failed to stop
$DAEMON