diff --git a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh index 57696ff..b53a207 100755 --- a/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh +++ b/rootfs/usr/local/etc/docker/init.d/zz-act_runner.sh @@ -239,33 +239,33 @@ RUNNER_HOSTNAME="${INSTANCE_HOSTNAME:-http://127.0.0.1:8000}" CONTAINER_IP4_ADDRESS="${CONTAINER_IP4_ADDRESS}" EOF fi - if [ ! -f "$CONF_DIR/runners" ]; then - for runner in "$CONF_DIR/reg"/*.reg; do - exitStatus=0 - RUNNER_NAME="$(basename "${runner//.reg/}")" - while :; do - [ -f "$runner" ] && . "$runner" - [ -f "$RUN_DIR/act_runner.$RUNNER_NAME.pid" ] && break - RUNNER_HOME="${RUNNER_HOME:-$CONF_DIR/multi/$RUNNER_NAME}" - if [ -z "$RUNNER_AUTH_TOKEN" ]; then - [ -f "$CONF_DIR/tokens/system" ] && RUNNER_AUTH_TOKEN="$(<"$CONF_DIR/tokens/system")" - [ -f "$CONF_DIR/tokens/$RUNNER_NAME" ] && RUNNER_AUTH_TOKEN="$(<"$CONF_DIR/tokens/$RUNNER_NAME")" || { [ -n "$SYS_AUTH_TOKEN" ] && echo "$SYS_AUTH_TOKEN" >"$CONF_DIR/tokens/$RUNNER_NAME"; } - chmod -Rf 600 "$CONF_DIR/tokens/system" "$CONF_DIR/tokens/$RUNNER_NAME" 2>/dev/null - chown -Rf "$SERVICE_USER":"$SERVICE_GROUP" "$CONF_DIR" "$ETC_DIR" "$DATA_DIR" 2>/dev/null - echo "Error: RUNNER_AUTH_TOKEN is not set - visit $INSTANCE_HOSTNAME/admin/actions/runners" >&2 - echo "Then edit $runner or set in $CONF_DIR/tokens/$RUNNER_NAME" >&2 - sleep 120 - else - echo "RUNNER_AUTH_TOKEN has been set: trying to register $RUNNER_NAME" + for runner in "$CONF_DIR/reg"/*.reg; do + exitStatus=0 + RUNNER_NAME="$(basename "${runner//.reg/}")" + while :; do + [ -f "$runner" ] && . "$runner" + [ -f "$RUN_DIR/act_runner.$RUNNER_NAME.pid" ] && break + RUNNER_HOME="${RUNNER_HOME:-$CONF_DIR/multi/$RUNNER_NAME}" + mkdir -p "$RUNNER_HOME" + if [ -z "$RUNNER_AUTH_TOKEN" ]; then + [ -f "$CONF_DIR/tokens/system" ] && RUNNER_AUTH_TOKEN="$(<"$CONF_DIR/tokens/system")" + [ -f "$CONF_DIR/tokens/$RUNNER_NAME" ] && RUNNER_AUTH_TOKEN="$(<"$CONF_DIR/tokens/$RUNNER_NAME")" || { [ -n "$SYS_AUTH_TOKEN" ] && echo "$SYS_AUTH_TOKEN" >"$CONF_DIR/tokens/$RUNNER_NAME"; } + chmod -Rf 600 "$CONF_DIR/tokens/system" "$CONF_DIR/tokens/$RUNNER_NAME" 2>/dev/null + chown -Rf "$SERVICE_USER":"$SERVICE_GROUP" "$CONF_DIR" "$ETC_DIR" "$DATA_DIR" 2>/dev/null + echo "Error: RUNNER_AUTH_TOKEN is not set - visit $INSTANCE_HOSTNAME/admin/actions/runners" >&2 + echo "Then edit $runner or set in $CONF_DIR/tokens/$RUNNER_NAME" >&2 + sleep 120 + else + echo "RUNNER_AUTH_TOKEN has been set: trying to register $RUNNER_NAME" + if [ ! -f "$RUNNER_HOME/runners" ]; then + cp -Rf "$CONF_DIR/multi.yaml" "$RUNNER_HOME/$RUNNER_NAME.yaml" + __replace "REPLACE_RUNNER_HOME" "$RUNNER_HOME" "$RUNNER_HOME/$RUNNER_NAME.yaml" act_runner register --config "$RUNNER_HOME/$RUNNER_NAME.yaml" --labels "$RUNNER_LABELS" --name "$RUNNER_NAME" --instance "http://$CONTAINER_IP4_ADDRESS:8000" --token "$RUNNER_AUTH_TOKEN" --no-interactive && exitStatus=0 || exitStatus=1 echo "$!" >"$RUN_DIR/act_runner.$RUNNER_NAME.pid" if [ $exitStatus -eq 0 ]; then exitStatus=0 - mv -fv "$runner" "$RUNNER_HOME/$RUNNER_NAME.reg" - cp -Rf "$CONF_DIR/multi.yaml" "$RUNNER_HOME/$RUNNER_NAME.yaml" - __replace "REPLACE_RUNNER_HOME" "$RUNNER_HOME" "$RUNNER_HOME/$RUNNER_NAME.yaml" + cp -Rf "$runner" "$RUNNER_HOME/$RUNNER_NAME.reg" chown -Rf "$SERVICE_USER":"$SERVICE_GROUP" "$RUNNER_HOME" - act_runner daemon --config $RUNNER_HOME/$RUNNER_NAME.yaml break else [ -f "$RUN_DIR/act_runner.$RUNNER_NAME.pid" ] && rm -f "$RUN_DIR/act_runner.$RUNNER_NAME.pid" @@ -273,9 +273,9 @@ EOF sleep 20 fi fi - done - done 2>"/dev/stderr" | tee -p -a "$LOG_DIR/init.txt" >/dev/null - fi + fi + done + done 2>"/dev/stderr" | tee -p -a "$LOG_DIR/init.txt" >/dev/null echo "$$" >"$RUN_DIR/act_runner.pid" echo "$(date)" >"$CONF_DIR/.runner" return $exitStatus @@ -363,6 +363,13 @@ __post_execute() { # show message __banner "$postMessageST" # commands to execute + for multi in "$CONF_DIR/multi"/*; do + name="$(basename "$multi")" + if [ -f "$$multi/$name.yaml" ] && [ -f "$multi/runners" ]; then + act_runner daemon --config $multi/$name.yaml + fi + done + act_runner cache-server --config $CONF_DIR/daemon.yaml -s 0.0.0.0 -p $SERVICE_PORT 2>>/dev/stderr | tee -a -p "$LOG_DIR/act_runner_cache.log" & execPid=$! sleep 5 && ps ax | awk '{print $1}' | grep -v grep | grep -q "$execPid$" && return 0 || return 2