Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions general/package/majestic/files/S95majestic
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,44 @@
[ -r /etc/TZ ] && export TZ=$(cat /etc/TZ)

DAEMON="majestic"
PIDFILE="/var/run/$DAEMON.pid"
DAEMON_PATH="/usr/bin/$DAEMON"
DAEMON_ARGS="-s"

# Find the daemon by executable, never through a pidfile. Given -p, busybox
# start-stop-daemon inspects only the pid that file holds and never scans
# /proc, so the moment that pid is stale it can no longer see the live daemon:
# -S starts a SECOND majestic, which dies on the busy sensor HAL and leaves its
# own dead pid behind in the file, and -K without -x signals whatever unrelated
# process has since reused the pid. -x scans every process instead, and -a
# keeps argv[0] as "majestic" so ps output and name-based tools are unchanged.
running() {
start-stop-daemon -t -K -q -x "$DAEMON_PATH"
}

start() {
echo -n "Starting $DAEMON: "
start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "$DAEMON" -- $DAEMON_ARGS
if [ $? -eq 0 ]; then
echo "OK"
else
echo "FAIL"
fi
start-stop-daemon -b -S -q -x "$DAEMON_PATH" -a "$DAEMON" -- $DAEMON_ARGS
case $? in
0) echo "OK"; return 0 ;;
1) echo "OK (already running)"; return 0 ;;
*) echo "FAIL"; return 1 ;;
esac
}

stop() {
echo -n "Stopping $DAEMON: "
start-stop-daemon -K -q -p "$PIDFILE"
if [ $? -eq 0 ]; then
rm -f "$PIDFILE"
echo "OK"
else
start-stop-daemon -K -q -x "$DAEMON_PATH"
i=0
while running && [ $i -lt 10 ]; do
i=$((i + 1))
sleep 1
done
if running; then
echo "FAIL"
return 1
fi
rm -f "/var/run/$DAEMON.pid"
echo "OK"
}

case "$1" in
Expand All @@ -37,13 +53,13 @@ case "$1" in
;;

restart)
stop
stop || exit 1
sleep 3
start
;;

reload)
killall -1 "$DAEMON"
start-stop-daemon -K -s 1 -q -x "$DAEMON_PATH"
;;

*)
Expand Down
Loading