Browse Source

init.d: do not use pgrep for firmwares compatibility

pull/828/head
bol-van 5 months ago
parent
commit
4856be4ef1
  1. 26
      init.d/sysv/functions

26
init.d/sysv/functions

@ -167,9 +167,15 @@ run_daemon()
# use $PIDDIR/$DAEMONBASE$1.pid as pidfile # use $PIDDIR/$DAEMONBASE$1.pid as pidfile
local DAEMONBASE="$(basename "$2")" local DAEMONBASE="$(basename "$2")"
local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid local PID= PIDFILE=$PIDDIR/$DAEMONBASE$1.pid
echo "Starting daemon $1: $2 $3" echo "Starting daemon $1: $2 $3"
if [ -f "$PIDFILE" ] && pgrep -F "$PIDFILE" "$DAEMONBASE" >/dev/null; then
[ -f "$PIDFILE" ] && {
read PID <"$PIDFILE"
[ -d "/proc/$PID" ] || PID=
}
if [ -n "$PID" ]; then
echo already running echo already running
else else
"$2" $3 >/dev/null & "$2" $3 >/dev/null &
@ -188,18 +194,14 @@ stop_daemon()
# $2 - daemon # $2 - daemon
# use $PIDDIR/$DAEMONBASE$1.pid as pidfile # use $PIDDIR/$DAEMONBASE$1.pid as pidfile
local DAEMONBASE="$(basename "$2")" local DAEMONBASE="$(basename "$2")"
local PIDFILE=$PIDDIR/$DAEMONBASE$1.pid local PID PIDFILE=$PIDDIR/$DAEMONBASE$1.pid
echo "Stopping daemon $1: $2" echo "Stopping daemon $1: $2"
if exists start-stop-daemon ; then if [ -f "$PIDFILE" ]; then
start-stop-daemon -K -p "$PIDFILE" -x "$2" read PID <"$PIDFILE"
kill $PID
rm -f "$PIDFILE"
else else
if [ -f "$PIDFILE" ]; then echo no pidfile : $PIDFILE
read PID <"$PIDFILE"
kill $PID
rm -f "$PIDFILE"
else
echo no pidfile : $PIDFILE
fi
fi fi
} }
do_daemon() do_daemon()

Loading…
Cancel
Save