Skip to content

Commit 925c36f

Browse files
committed
Allow to stop service gracefully if PID doesn't exist
1 parent b0c0f87 commit 925c36f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

github_actions_runner_manager.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,18 @@ stop () {
5656
exit 2
5757
fi
5858

59-
echo "Stopping runner"
60-
echo "Stopping runner on $(hostname)" >>$state_path/$LOG_FILE
61-
kill -SIGTERM $(cat $state_path/$PID_FILE)
59+
local pid=$(cat $state_path/$PID_FILE)
60+
61+
# check PID exists
62+
if ps -p $pid >/dev/null
63+
then
64+
echo "Stopping runner"
65+
echo "Stopping runner on $(hostname)" >>$state_path/$LOG_FILE
66+
kill -SIGTERM $pid
67+
else
68+
echo "Runner already stopped"
69+
echo "Runner already stopped on $(hostname)" >>$state_path/$LOG_FILE
70+
fi
6271

6372
echo "Removing pid file"
6473
rm -f $state_path/$PID_FILE

0 commit comments

Comments
 (0)