| 1 | #!/sbin/openrc-run |
| 2 | |
| 3 | description="GitLab CI Runner" |
| 4 | name="Gitlab Runner" |
| 5 | |
| 6 | extra_started_commands="reload" |
| 7 | description_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 | |
| 17 | command="/usr/bin/gitlab-runner" |
| 18 | command_args="run |
| 19 | --config $cfgfile |
| 20 | --working-directory $datadir |
| 21 | --service $RC_SVCNAME |
| 22 | ${command_args:-$GITLAB_RUNNER_OPTS} |
| 23 | " |
| 24 | command_background="yes" |
| 25 | directory="$datadir" |
| 26 | |
| 27 | start_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). |
| 30 | supervise_daemon_args=" $supervise_daemon_args" |
| 31 | pidfile="/run/$RC_SVCNAME.pid" |
| 32 | |
| 33 | depend() { |
| 34 | need net |
| 35 | use dns logger |
| 36 | } |
| 37 | |
| 38 | start_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? |
| 54 | start_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 | |
| 62 | reload() { |
| 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 | } |