You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# check if runner is running based on the existence of a state file and based
13
+
# on a valid PID
14
+
is_running () {
15
+
local state_path="$1"
16
+
17
+
# if no PID file, it's not running
18
+
if [[ !-f$state_path/$PID_FILE ]]
19
+
then
20
+
return 1
21
+
fi
22
+
23
+
local pid=$(cat $state_path/$PID_FILE)
24
+
25
+
# check PID exists
26
+
if ps -p $pid>/dev/null
27
+
then
28
+
return 0
29
+
else
30
+
return 1
31
+
fi
32
+
}
33
+
12
34
start () {
13
35
local runner_path="$1"
14
36
local state_path="$2"
@@ -21,20 +43,13 @@ start () {
21
43
exit 2
22
44
fi
23
45
24
-
if [[ -f$state_path/$PID_FILE ]]
46
+
# check if the runner is running
47
+
if is_running "$state_path"
25
48
then
26
-
# the runner is presumably already running
27
-
if$force
28
-
then
29
-
echo"Force start"
30
-
else
31
-
echo"The runner is already running"
32
-
exit 2
33
-
fi
49
+
echo"The runner is already running"
50
+
exit 2
34
51
fi
35
52
36
-
mkdir -p "$state_path"
37
-
38
53
# running as a service, see https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service
39
54
echo"Starting runner"
40
55
echo"Starting runner on $(hostname)">>$state_path/$LOG_FILE
@@ -49,18 +64,11 @@ start () {
49
64
stop () {
50
65
local state_path="$1"
51
66
52
-
if [[ !-f$state_path/$PID_FILE ]]
67
+
# check if the runner is running
68
+
if is_running "$state_path"
53
69
then
54
-
# the runner is not running
55
-
echo"The runner is not running"
56
-
exit 2
57
-
fi
70
+
local pid=$(cat $state_path/$PID_FILE)
58
71
59
-
local pid=$(cat $state_path/$PID_FILE)
60
-
61
-
# check PID exists
62
-
if ps -p $pid>/dev/null
63
-
then
64
72
echo"Stopping runner"
65
73
echo"Stopping runner on $(hostname)">>$state_path/$LOG_FILE
66
74
kill -SIGTERM $pid
@@ -69,14 +77,14 @@ stop () {
69
77
echo"Runner already stopped on $(hostname)">>$state_path/$LOG_FILE
0 commit comments