gentoo-overlay/dev-vcs/gitlab-ci-runner/files/gitlab-ci-runner.init

59 lines
1.5 KiB
Text
Raw Normal View History

2014-09-24 18:00:16 +02:00
#!/sbin/runscript
2014-09-24 15:37:27 +02:00
2014-09-24 18:00:16 +02:00
name="GitLab CI Runner"
description="GitLab CI Runner, starts runners in the background"
2014-09-24 15:37:27 +02:00
2014-09-24 18:00:16 +02:00
: ${gitlab_ci_runner_user:=@USER@}
: ${gitlab_ci_runner_base:="@GITLAB_CI_RUNNER_BASE@"}
: ${gitlab_ci_runner_pidfile_base:="@RUN_DIR@/gitlab-ci-runner.pid"}
: ${gitlab_ci_runner_logfile:="@LOGS_DIR@/gitlab-ci-runner.log"}
: ${gitlab_ci_runner_num:=1} # number of runners to spawn
2014-09-24 15:37:27 +02:00
2014-09-24 18:00:16 +02:00
bundle_command="/usr/bin/bundle"
bundle_command_args="exec ./bin/runner"
2014-09-24 15:37:27 +02:00
2014-09-24 18:00:16 +02:00
depend() {
provide gitlab-ci-runner
2014-09-24 15:37:27 +02:00
}
start() {
2014-09-24 18:00:16 +02:00
ebegin "Starting ${name}"
for (( i=1; i<=${gitlab_ci_runner_num}; i++ )) ; do
einfo "Starting runner ${i} of ${gitlab_ci_runner_num} ..."
local pidfile="${gitlab_ci_runner_pidfile_base}${i}"
checkpath -d -o ${gitlab_ci_runner_user} -m755 "$(dirname "${pidfile}")"
start-stop-daemon --start \
--chdir "${gitlab_ci_runner_base}" \
--user=${gitlab_ci_runner_user} \
--make-pidfile \
--pidfile="${pidfile}" \
--background \
2014-09-24 18:52:31 +02:00
--exec /bin/bash -- -c "exec ${bundle_command} ${bundle_command_args} >> ${gitlab_ci_runner_logfile} 2>&1"
2014-09-24 18:00:16 +02:00
local success=$?
if [ ${success}!=0 ] ; then
eend ${success}
fi
done
eend 0
2014-09-24 15:37:27 +02:00
}
stop() {
2014-09-24 18:00:16 +02:00
ebegin "Stopping ${name}"
for (( i=1; i<=${gitlab_ci_runner_num}; i++ )) ; do
einfo "Stopping runner ${i} of ${gitlab_ci_runner_num} ..."
local pidfile="${gitlab_ci_runner_pidfile_base}${i}"
start-stop-daemon --stop \
--pidfile="${pidfile}"
# DO WE NEED --exec? or --startas???
local success=$?
2014-09-24 18:00:16 +02:00
if [ ${success}!=0 ] ; then
eend ${success}
fi
done
eend 0
2014-09-24 15:37:27 +02:00
}