'Generic Commit'

This commit is contained in:
Your Name 2025-06-01 16:48:27 +12:00
parent 9ab3b8433a
commit 8cc1db5769
3 changed files with 33 additions and 12 deletions

View File

@ -1,9 +1,10 @@
#!/bin/bash
set -euo pipefail
# shellcheck disable=SC1091
source "${AGENT_PATH}/common.sh"
_check_required_env_vars "SERVER" "SERVICE" "TEMP_DIR" "GITEA_RUNNER_DIRECTORY" "ACT_RUNNER_VERSION"
_check_required_env_vars "SERVER" "SERVICE" "TEMP_DIR" \
"GITEA_RUNNER_DIRECTORY" "ACT_RUNNER_VERSION" \
"GITEA_URL" "GITEA_TOKEN" "GITEA_RUNNER_NAME" "GITEA_RUNNER_LABELS"
echo "Downloading act_runner ${ACT_RUNNER_VERSION}..."
wget https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}/act_runner-${ACT_RUNNER_VERSION}-linux-amd64 -O "${TEMP_DIR}/act_runner"
@ -11,20 +12,29 @@ wget https://gitea.com/gitea/act_runner/releases/download/v${ACT_RUNNER_VERSION}
chmod +x "${TEMP_DIR}/act_runner" || _die "Failed to download ${TEMP_DIR}/act_runner"
ACT_RUNNER="${GITEA_RUNNER_DIRECTORY}/act_runner"
CONFIG_FILE="${GITEA_RUNNER_DIRECTORY}/config.yaml"
echo "Checking version..."
mkdir -p "${GITEA_RUNNER_DIRECTORY}" || _die "Failed to create ${GITEA_RUNNER_DIRECTORY}"
cp "${TEMP_DIR}/act_runner" "$ACT_RUNNER" || _die "Failed to copy ${TEMP_DIR}/act_runner to ${GITEA_RUNNER_DIRECTORY}/act_runner"
${ACT_RUNNER} --version || _die "Failed to run ${ACT_RUNNER}"
${ACT_RUNNER} generate-config > "${GITEA_RUNNER_DIRECTORY}/config.yaml" || _die "Failed to generate config.yaml"
${ACT_RUNNER} --config "${GITEA_RUNNER_DIRECTORY}/config.yaml" \
# only register once!
if [ ! -f "${CONFIG_FILE}" ]; then
echo "Generating config.yaml..."
${ACT_RUNNER} generate-config > "${CONFIG_FILE}" || _die "Failed to generate config.yaml"
echo "Registering runner..."
${ACT_RUNNER} --config "${CONFIG_FILE}" \
register --no-interactive \
--instance GITEA_URL \
--instance "${GITEA_URL}" \
--token "${GITEA_TOKEN}" \
--name "${GITEA_RUNNER_NAME}" \
--labels "${GITEA_RUNNER_LABELS}"
else
echo "Runner already registered."
fi
./start.sh || _die "Failed to start"

View File

@ -10,8 +10,18 @@ _check_required_env_vars "SERVER" "SERVICE" "GITEA_RUNNER_DIRECTORY"
# It is called with the path to the server specific env file as an argument.
CONFIG_FILE="${GITEA_RUNNER_DIRECTORY}/config.yaml"
ACT_RUNNER="${GITEA_RUNNER_DIRECTORY}/act_runner"
"${GITEA_RUNNER_DIRECTORY}/act_runner" daemon --config "${CONFIG_FILE}" || _die "Failed to start act_runner"
echo "Starting act_runner..."
"${ACT_RUNNER}" daemon --config "${CONFIG_FILE}" >/dev/null 2>&1 &
# Add a short delay to allow the background process to start
sleep 2
if pgrep -f "${ACT_RUNNER}" > /dev/null; then
echo "act_runner started successfully."
else
_die "Failed to start act_runner process."
fi
echo "Started $SERVICE"

View File

@ -8,7 +8,8 @@ echo "Uninstalling service ${SERVICE}..."
./stop.sh || _die "Failed to stop act_runner"
rm -rf "${GITEA_RUNNER_DIRECTORY}"
rm "${GITEA_RUNNER_DIRECTORY}/act_runner"
# leave the config.yaml file alone. Have to manually deregister in gitea.
echo "Uninstalled ${SERVICE}"