-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh_actions
executable file
·91 lines (80 loc) · 2.32 KB
/
gh_actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
# PROVIDE: gh_actions
# REQUIRE: NETWORKING LOGIN FILESYSTEM
# BEFORE: securelevel
# KEYWORD: shutdown
# shellcheck disable=SC2034
. /etc/rc.subr
PATH=$PATH:/usr/local64/bin
name="gh_actions"
desc="GitHub Actions"
procname="${name}"
rcvar=${name}_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
load_rc_config $name
gh_actions_running=/var/run/github-runners
gh_actions_sleep="${gh_actions_sleep:-1}"
gh_actions_start()
{
touch /var/run/github-runners
# shellcheck disable=SC2154
for RUNNER_NAME in ${gh_actions_pots} ; do
export RUNNER_NAME
run-actions-runner.sh > /dev/null 2> /dev/null &
done
}
gh_actions_stop()
{
rm -f /var/run/github-runners
for RUNNER_NAME in ${gh_actions_pots} ; do
pot info -qr -p ${RUNNER_NAME}-ephemeral > /dev/null 2>&1
if [ $? -eq 0 ] ; then
if [ -f /var/run/github-runners.${RUNNER_NAME} ]; then
# If force is specified, stop the process immediately.
if [ -n "${rc_force}" ]; then
sleep ${gh_actions_sleep}
kill "$(cat "/var/run/github-runners.${RUNNER_NAME}")"
fi
# Kill the runner if it isn't in the middle of a job.
# The script will then gracefully terminate.
echo 'pkill -INT github-act-runner' | pot term -p ${RUNNER_NAME}-ephemeral >/dev/null 2>/dev/null
echo Waiting for ${RUNNER_NAME}-ephemeral to stop gracefully.
fi
fi
done
# If this isn't a forced operation, wait
if [ -z "${rc_force}" ]; then
for RUNNER_NAME in ${gh_actions_pots} ; do
pot info -qr -p ${RUNNER_NAME}-ephemeral > /dev/null 2>&1
if [ $? -eq 0 ] ; then
COUNT=0
while [ -f /var/run/github-runners.${RUNNER_NAME} ]; do
sleep 1
COUNT=$(expr $COUNT + 1)
if [ "$(expr $COUNT % 10)" -eq 0 ] ; then
echo Waiting for ${RUNNER_NAME} to exit...
fi
done
fi
done
fi
}
gh_actions_status()
{
STATUS=$([ ! -f /var/run/github-runners ] && echo not)
echo $desc $STATUS running
for RUNNER_NAME in ${gh_actions_pots} ; do
pot info -qr -p ${RUNNER_NAME}-ephemeral > /dev/null 2>&1
if [ $? -eq 0 ] ; then
printf "%s" "${RUNNER_NAME} pot running"
if [ -f /var/run/github-runners.${RUNNER_NAME} ]; then
printf " managed by process %s\n" "$(cat /var/run/github-runners.${RUNNER_NAME})"
else
printf " but appears to be orphaned\n"
fi
fi
done
}
run_rc_command "$1"