Files

35 lines
982 B
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2026 Dante <dante@seckv.com>
#
# Smart process runner & supervisor for Lucky.
# Procd executes lucky-runner as a persistent managed supervisor.
# It cleans rogue orphans, starts lucky, and waits on it.
# When lucky self-restarts from Web UI (causing os.Exit(0) in parent),
# lucky-runner detects child exit, eliminates spawned rogue orphans,
# and restarts a fresh instance within the procd-supervised hierarchy.
orphan_pids=$(pidof /usr/bin/lucky)
[ -n "$orphan_pids" ] && kill -9 $orphan_pids >/dev/null 2>&1
while true; do
/usr/bin/lucky "$@" &
LUCKY_PID=$!
trap 'kill -TERM $LUCKY_PID 2>/dev/null; exit 0' TERM INT
wait $LUCKY_PID
EXIT_CODE=$?
usleep 200000 2>/dev/null || sleep 1
NEW_PID=$(pidof /usr/bin/lucky)
if [ -n "$NEW_PID" ]; then
kill -9 $NEW_PID >/dev/null 2>&1
usleep 200000 2>/dev/null || sleep 1
continue
fi
exit $EXIT_CODE
done