44
55PID_FILE=" runner.pid"
66LOG_FILE=" runner.log"
7- DEFAULT_RUNNER_DIR= " ./actions_runner "
7+ STATE_DIRNAME= " state "
88
99# directory of the script, see https://stackoverflow.com/a/4774063/19422971
1010SCRIPT_PATH=" $( cd -- " $( dirname " $0 " ) " > /dev/null 2>&1 ; pwd -P ) "
@@ -103,15 +103,13 @@ usage () {
103103 cat << EOF
104104Manage GitHub Actions Runner like a SysV init script
105105
106- github_actions_runner_manager.sh [-r PATH] [-s PATH ] [-c COMMAND] [-f] [-h] {start|stop|restart|status}
106+ github_actions_runner_manager.sh [-s STATE_PATH ] [-c COMMAND] [-f] [-h] {start|stop|restart|status} RUNNER_PATH
107107
108108Optional arguments:
109- -r PATH
110- Path to GitHub Actions Runner directory. Default to $DEFAULT_RUNNER_DIR in the script directory.
111- -s PATH
112- Path to the state directory of the manager (where PID and log files are stored). Default to the script directory.
109+ -s STATE_PATH
110+ Path to the state directory of the manager (where PID and log files are stored). Default to $STATE_DIRNAME in the runner directory.
113111 -c COMMAND
114- Script to execute instead of running GHAR directly.
112+ Script to execute instead of running the runner directly.
115113 -f
116114 Force start even if the runner is running.
117115 -h
@@ -126,29 +124,29 @@ Subcommands:
126124 Stop and start the runner.
127125 status
128126 Tell if the runner is running.
127+
128+ Mandatory arguments:
129+ RUNNER_PATH
130+ Path to a GitHub Actions Runner directory.
129131EOF
130132}
131133
132134main () {
133135 # default arguments
134- local runner_path=" $SCRIPT_PATH /$DEFAULT_RUNNER_DIR "
135- local state_path=" $SCRIPT_PATH "
136+ local state_path=" "
136137 local command=" "
137138 local force=false
138139
139140 # process optional arguments
140- while getopts " :hr:s :c:f" option
141+ while getopts " :hs :c:f" option
141142 do
142143 case $option in
143144 " h" )
144145 usage
145146 exit 0
146147 ;;
147- " r" )
148- runner_path=" $OPTARG "
149- ;;
150148 " s" )
151- state_path=" $( realpath $ OPTARG) "
149+ state_path=" $OPTARG "
152150 ;;
153151 " c" )
154152 command=" $OPTARG "
@@ -165,42 +163,51 @@ main () {
165163 done
166164 shift $(( OPTIND- 1 ))
167165
168- mkdir -p " $state_path "
166+ # process mandatory arguments
167+ if [[ -z " ${1+_} " ]] || [[ -z " ${2+_} " ]]
168+ then
169+ echo " Missing arguments"
170+ usage
171+ exit 1
172+ fi
173+
174+ local cmd=" $1 "
175+ local runner_path=" $( realpath " $2 " ) "
169176
170- # process mandatory argument
171- if [[ -n " ${1+_} " ]]
177+ if [[ -z $state_path ]]
172178 then
173- local cmd=" $1 "
174- case $cmd in
175- " start" )
176- start " $runner_path " " $state_path " " $command " " $force "
177- exit 0
178- ;;
179- " stop" )
180- stop " $state_path "
181- exit 0
182- ;;
183- " restart" )
184- stop " $state_path "
185- sleep 1
186- start " $runner_path " " $state_path " " $command " " $force "
187- exit 0
188- ;;
189- " status" )
190- status " $state_path "
191- exit 0
192- ;;
193- * )
194- echo " Unknown subcommand $cmd "
195- usage
196- exit 1
197- ;;
198- esac
179+ state_path=" $runner_path /$STATE_DIRNAME "
180+ else
181+ state_path=" $( realpath " $state_path " ) "
199182 fi
200183
201- # no arguments
202- usage
203- exit 0
184+ mkdir -p " $state_path "
185+
186+ case $cmd in
187+ " start" )
188+ start " $runner_path " " $state_path " " $command " " $force "
189+ exit 0
190+ ;;
191+ " stop" )
192+ stop " $state_path "
193+ exit 0
194+ ;;
195+ " restart" )
196+ stop " $state_path "
197+ sleep 1
198+ start " $runner_path " " $state_path " " $command " " $force "
199+ exit 0
200+ ;;
201+ " status" )
202+ status " $state_path "
203+ exit 0
204+ ;;
205+ * )
206+ echo " Unknown subcommand $cmd "
207+ usage
208+ exit 1
209+ ;;
210+ esac
204211}
205212
206213main " $@ "
0 commit comments