From 942f1949ac56352e915de2d1d5e4c38d3b19492f Mon Sep 17 00:00:00 2001 From: tuankiet2s Date: Mon, 11 Aug 2025 11:30:28 +0700 Subject: [PATCH] Add jq installation check and systemd service setup for act_runner --- install.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/install.sh b/install.sh index 6d80928..7aedff5 100644 --- a/install.sh +++ b/install.sh @@ -9,6 +9,49 @@ check_version() { echo $act_runner_version } +# Ensure jq is installed (attempt auto-install on common distros) +ensure_jq() { + if check_command jq; then + return 0 + fi + + echo "jq not found. Attempting to install..." + + SUDO="" + if [ "$EUID" -ne 0 ]; then + if check_command sudo; then + SUDO="sudo" + else + echo "Error: jq is required and sudo is not available. Please install jq manually and re-run." + exit 1 + fi + fi + + if check_command apt-get; then + $SUDO apt-get update -y && $SUDO apt-get install -y jq + elif check_command dnf; then + $SUDO dnf install -y jq + elif check_command yum; then + $SUDO yum install -y jq + elif check_command apk; then + $SUDO apk add --no-cache jq + elif check_command pacman; then + $SUDO pacman -Sy --noconfirm jq + elif check_command zypper; then + $SUDO zypper install -y jq + else + echo "Error: Unsupported package manager. Please install 'jq' manually and re-run." + exit 1 + fi + + if ! check_command jq; then + echo "Error: Failed to install 'jq'. Please install it manually and re-run." + exit 1 + fi +} + +ensure_jq + if check_command act_runner; then current_version=$(check_version) echo "Current act_runner version: $current_version" @@ -37,6 +80,7 @@ filename=$(basename $url_binary) if [ -z "$current_version" ] || [ "$current_version" != "$latest_version" ]; then echo "Updating act_runner to version: $latest_version" wget $url_binary + wget $url_checksum sha256sum -c $checksum_filename rm $checksum_filename unxz $filename @@ -47,3 +91,50 @@ if [ -z "$current_version" ] || [ "$current_version" != "$latest_version" ]; the else echo "act_runner is up to date." fi + +# Generate default configuration after install and before setting up systemd +mkdir -p /etc/act_runner /var/lib/act_runner +if [ ! -f /etc/act_runner/config.yaml ]; then + echo "Generating default configuration at /etc/act_runner/config.yaml" + /usr/local/bin/act_runner generate-config >/etc/act_runner/config.yaml +else + echo "Existing configuration detected at /etc/act_runner/config.yaml, skipping generation" +fi + +# Install systemd service for act_runner +if command -v systemctl >/dev/null 2>&1; then + if ! id -u act_runner >/dev/null 2>&1; then + useradd --system --home-dir /var/lib/act_runner --shell /usr/sbin/nologin act_runner + fi + + mkdir -p /var/lib/act_runner /etc/act_runner + chown -R act_runner:act_runner /var/lib/act_runner /etc/act_runner + + service_path="/etc/systemd/system/act-runner.service" + cat >"$service_path" <<'EOF' +[Unit] +Description=Gitea Actions runner +Documentation=https://gitea.com/gitea/act_runner +After=docker.service + +[Service] +ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml +ExecReload=/bin/kill -s HUP $MAINPID +WorkingDirectory=/var/lib/act_runner +TimeoutSec=0 +RestartSec=10 +Restart=always +User=act_runner + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable act-runner + if [ -f /etc/act_runner/config.yaml ]; then + systemctl start act-runner + else + echo "Systemd service installed. Create /etc/act_runner/config.yaml then run: systemctl start act-runner" + fi +fi