Fix direct execution of AppImages

Fetch a list of all child PIDs before forwarding the termination signal.
Once the main process is terminated, forward that term signal to all found children also (if they are still running)
This commit is contained in:
Josh.5
2023-09-11 12:21:23 +12:00
parent 0981af0a17
commit 771c47d602
2 changed files with 20 additions and 2 deletions

View File

@@ -24,8 +24,25 @@ echo
# Trap SIGINT, SIGQUIT, SIGHUP, SIGTERM to forward signals to the child process
_term() {
if [ -n "${proc_pid}" ]; then
echo " - Forwarding signal $1 to process ${proc_pid}"
kill -s "${1}" "${proc_pid}"
# Read all child processes of proc_pid first
child_pids=$(pgrep -P $proc_pid)
# Forward the signal proc_pid
echo " - Checking for status of main process ${proc_pid}"
if kill -0 "${proc_pid}" 2>/dev/null; then
echo " - Forwarding signal $1 to process ${proc_pid}"
kill -s "${1}" "${proc_pid}"
else
echo " - Process ${proc_pid} is already stopped. Nothing to do here."
fi
for child_pid in ${child_pids:-}; do
echo " - Checking for status of child process ${child_pid}"
if kill -0 "${child_pid}" 2>/dev/null; then
echo " - Forwarding signal $1 to process ${child_pid}"
kill -s "${1}" "${child_pid}"
else
echo " - Process ${child_pid} is already stopped. Nothing to do here."
fi
done
fi
}
trap '_term INT' SIGINT

View File

@@ -36,6 +36,7 @@ echo " - Found initial sunshine-run PID '${process_pid}'."
# Send a INT signal to the PID
echo " - Sending SIGINT to PID '${process_pid}'."
kill -INT "${process_pid}" || true
sleep 1
# Run a loop to check for any other "sunshine-run" processes and send them also a INT signal
echo " - Checking for other sunshine-run processes..."