#!/bin/bash

set -e -u -x

RUN_DIR=/var/vcap/sys/run/gitlab-runner
LOG_DIR=/var/vcap/sys/log/gitlab-runner
STORE_DIR=/var/vcap/store/gitlab-runner
PACKAGE_DIR=/var/vcap/packages/gitlab-ci-multi-runner
WORK_DIR=${STORE_DIR}/work
PIDFILE=$RUN_DIR/pid

source /var/vcap/jobs/gitlab-runner/helpers/pid_utils.sh

PATH=$PATH:/var/vcap/packages/git/bin/

case $1 in

  start)
    pid_guard $PIDFILE "gitlab-runner"

    mkdir -p $RUN_DIR $LOG_DIR $STORE_DIR $WORK_DIR
    chown -R vcap:vcap $RUN_DIR $LOG_DIR $STORE_DIR

    echo $$ > $PIDFILE
    exec chpst $PACKAGE_DIR/bin/gitlab-ci-multi-runner run \
      --config /var/vcap/store/gitlab-runner/config.toml \
      --working-directory $WORK_DIR \
      1>>$LOG_DIR/stdout.log \
      2>>$LOG_DIR/stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

  *)
    echo "Usage: $0 {start|stop}"

    ;;

esac


#!/bin/bash

set -e -u -x

RUN_DIR=/var/vcap/sys/run/gitlab-runner
LOG_DIR=/var/vcap/sys/log/gitlab-runner
STORE_DIR=/var/vcap/store/gitlab-runner
PACKAGE_DIR=/var/vcap/packages/gitlab-ci-multi-runner
WORK_DIR=${STORE_DIR}/work
PIDFILE=$RUN_DIR/pid

source /var/vcap/jobs/gitlab-runner/helpers/pid_utils.sh

# Add all packages' /bin $PATH
for package_dir in $(ls -d /var/vcap/packages/*); do
  for package_bin_dir in $(ls -d ${package_dir}/bin); do
    export PATH=${package_bin_dir}:$PATH
  done
done

case $1 in

  start)
    pid_guard $PIDFILE "gitlab-runner"

    mkdir -p $RUN_DIR $LOG_DIR $STORE_DIR $WORK_DIR
    chown -R vcap:vcap $RUN_DIR $LOG_DIR $STORE_DIR

    echo $$ > $PIDFILE
    exec chpst $PACKAGE_DIR/bin/gitlab-ci-multi-runner run \
      --config /var/vcap/store/gitlab-runner/config.toml \
      --working-directory $WORK_DIR \
      1>>$LOG_DIR/stdout.log \
      2>>$LOG_DIR/stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

  *)
    echo "Usage: $0 {start|stop}"

    ;;

esac


Add all packge bin dirs to path
Add all packge bin dirs to path
