projects/aports·blob master · refs

71 lines · 1.8 KiB

1#!/sbin/openrc-run
2
3description="GitLab CI Runner"
4name="Gitlab Runner"
5
6extra_started_commands="reload"
7description_reload="Reload configuration"
8
9# NOTE: All SCREAMING_CASE variables are here for backward compatibility only (Alpine <3.17).
10
11: ${cfgfile:="/etc/gitlab-runner/config.toml"}
12: ${datadir:="/var/lib/gitlab-runner"}
13: ${log_syslog:="no"}
14: ${start_wait:=50} # milliseconds
15: ${command_user:="${GITLAB_RUNNER_USER:-gitlab-runner}:${GITLAB_RUNNER_GROUP:-gitlab-runner}"}
16
17command="/usr/bin/gitlab-runner"
18command_args="run
19 --config $cfgfile
20 --working-directory $datadir
21 --service $RC_SVCNAME
22 ${command_args:-$GITLAB_RUNNER_OPTS}
23 "
24command_background="yes"
25directory="$datadir"
26
27start_stop_daemon_args="--wait $start_wait $start_stop_daemon_args"
28# The leading space is to avoid fallback to $start_stop_daemon_args when this
29# is empty (supervise-daemon doesn't support --wait).
30supervise_daemon_args=" $supervise_daemon_args"
31pidfile="/run/$RC_SVCNAME.pid"
32
33depend() {
34 need net
35 use dns logger
36}
37
38start_pre() {
39 export CLICOLOR=0 # disable colors (ANSI sequences) in the log output
40
41 if yesno "$log_syslog"; then
42 export LOG_FORMAT="syslog"
43 command_args="$command_args --syslog"
44 else
45 export LOG_FORMAT="text" # format with timestamps
46 : ${error_log="/var/log/gitlab-runner.log"}
47 fi
48 if [ "${error_log:-}" ]; then
49 checkpath -f -m 644 -o "$command_user" "$error_log" || return 1
50 fi
51}
52
53# TODO: Shouldn't this be in start_pre and fail if the config doesn't exist?
54start_post() {
55 if ! [ -e "$cfgfile" ]; then
56 einfo "Config file $cfgfile doesn't exist"
57 einfo "You need to register the runner with command: gitlab-runner register"
58 fi
59 return 0
60}
61
62reload() {
63 ebegin "Reloading $name configuration"
64
65 if [ "$supervisor" ]; then
66 $supervisor "$RC_SVCNAME" --signal HUP
67 else
68 start-stop-daemon --pidfile "$pidfile" --signal HUP
69 fi
70 eend $?
71}