Skip to content

Commit 8437a44

Browse files
committed
Allow to set custom command
1 parent 4938c9f commit 8437a44

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

github_actions_runner_manager.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ is_running () {
3434
start () {
3535
local runner_path="$1"
3636
local state_path="$2"
37-
local force=$3
37+
local command="$3"
38+
local force=$4
3839

3940
# check if the runner path exists
4041
if ! [[ -d "$runner_path" ]]
@@ -50,11 +51,17 @@ start () {
5051
exit 2
5152
fi
5253

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
54+
# running as a service, see
55+
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/configuring-the-self-hosted-runner-application-as-a-service
56+
if [[ -z $command ]]
57+
then
58+
command="bin/runsvc.sh"
59+
fi
60+
5461
echo "Starting runner"
5562
echo "Starting runner on $(hostname)" >>$state_path/$LOG_FILE
5663
cd "$runner_path"
57-
bin/runsvc.sh >>$state_path/$LOG_FILE 2>&1 &
64+
$command >>$state_path/$LOG_FILE 2>&1 &
5865

5966
# create pid file
6067
echo "Creating pid file"
@@ -96,13 +103,15 @@ usage () {
96103
cat <<EOF
97104
Manage GitHub Actions Runner like a SysV init script
98105
99-
github_actions_runner_manager.sh [-r PATH] [-s PATH] [-f] [-h] {start|stop|restart|status}
106+
github_actions_runner_manager.sh [-r PATH] [-s PATH] [-c COMMAND] [-f] [-h] {start|stop|restart|status}
100107
101108
Optional arguments:
102109
-r PATH
103110
Path to GitHub Actions Runner directory. Default to $DEFAULT_RUNNER_DIR in the script directory.
104111
-s PATH
105112
Path to the state directory of the manager (where PID and log files are stored). Default to the script directory.
113+
-c COMMAND
114+
Script to execute instead of running GHAR directly.
106115
-f
107116
Force start even if the runner is running.
108117
-h
@@ -124,10 +133,11 @@ main () {
124133
# default arguments
125134
local runner_path="$SCRIPT_PATH/$DEFAULT_RUNNER_DIR"
126135
local state_path="$SCRIPT_PATH"
136+
local command=""
127137
local force=false
128138

129139
# process optional arguments
130-
while getopts ":hr:s:f" option
140+
while getopts ":hr:s:c:f" option
131141
do
132142
case $option in
133143
"h")
@@ -140,6 +150,9 @@ main () {
140150
"s")
141151
state_path="$(realpath $OPTARG)"
142152
;;
153+
"c")
154+
command="$OPTARG"
155+
;;
143156
"f")
144157
force=true
145158
;;
@@ -160,7 +173,7 @@ main () {
160173
local cmd="$1"
161174
case $cmd in
162175
"start")
163-
start "$runner_path" "$state_path" "$force"
176+
start "$runner_path" "$state_path" "$command" "$force"
164177
exit 0
165178
;;
166179
"stop")
@@ -170,7 +183,7 @@ main () {
170183
"restart")
171184
stop "$state_path"
172185
sleep 1
173-
start "$runner_path" "$state_path" "$force"
186+
start "$runner_path" "$state_path" "$command" "$force"
174187
exit 0
175188
;;
176189
"status")

0 commit comments

Comments
 (0)