@@ -12,12 +12,18 @@ SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
1212start () {
1313 local runner_path=" $1 "
1414 local state_path=" $2 "
15+ local force=$3
1516
1617 if [[ -f $state_path /$PID_FILE ]]
1718 then
18- # the runner is already running
19- echo " The runner is already running"
20- exit 2
19+ # the runner is presumably already running
20+ if $force
21+ then
22+ echo " Force start"
23+ else
24+ echo " The runner is already running"
25+ exit 2
26+ fi
2127 fi
2228
2329 # 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
@@ -64,13 +70,15 @@ usage () {
6470 cat << EOF
6571Manage GitHub Actions Runner like a SysV init script
6672
67- github_actions_runner_manager.sh [-r PATH] [-s PATH] [-h] {start|stop|restart|status}
73+ github_actions_runner_manager.sh [-r PATH] [-s PATH] [-f] [- h] {start|stop|restart|status}
6874
6975Optional arguments:
7076 -r PATH
7177 Path to GitHub Actions Runner directory. Default to $DEFAULT_RUNNER_DIR in the script directory.
7278 -s PATH
7379 Path to the state directory of the manager (where PID and log files are stored). Default to the script directory.
80+ -f
81+ Force start.
7482 -h
7583 Show this help message and exit.
7684
@@ -90,9 +98,10 @@ main () {
9098 # default arguments
9199 local runner_path=" $SCRIPT_PATH /$DEFAULT_RUNNER_DIR "
92100 local state_path=" $SCRIPT_PATH "
101+ local force=false
93102
94103 # process optional arguments
95- while getopts " :hr:s:" option
104+ while getopts " :hr:s:f " option
96105 do
97106 case $option in
98107 " h" )
@@ -103,7 +112,10 @@ main () {
103112 runner_path=" $OPTARG "
104113 ;;
105114 " s" )
106- state_path=" $OPTARG "
115+ state_path=" $( realpath $OPTARG ) "
116+ ;;
117+ " f" )
118+ force=true
107119 ;;
108120 * )
109121 echo " Unknown option $OPTARG "
@@ -120,7 +132,7 @@ main () {
120132 local cmd=" $1 "
121133 case $cmd in
122134 " start" )
123- start " $runner_path " " $state_path "
135+ start " $runner_path " " $state_path " " $force "
124136 exit 0
125137 ;;
126138 " stop" )
@@ -130,7 +142,7 @@ main () {
130142 " restart" )
131143 stop " $state_path "
132144 sleep 1
133- start " $runner_path " " $state_path "
145+ start " $runner_path " " $state_path " " $force "
134146 exit 0
135147 ;;
136148 " status" )
0 commit comments