diff --git a/.forgejo/workflows/example-lxc-systemd.yml b/.forgejo/workflows/example-lxc-systemd.yml index f027426..7b7614c 100644 --- a/.forgejo/workflows/example-lxc-systemd.yml +++ b/.forgejo/workflows/example-lxc-systemd.yml @@ -43,7 +43,7 @@ jobs: done cd examples/lxc-systemd - VERBOSE=true ./forgejo-runner-service.sh upgrade 1.2.3 $(pwd)/forgejo-runner-service.sh + VERBOSE=true ./forgejo-runner-service.sh upgrade file://$(pwd)/forgejo-runner-service.sh for script in $scripts; do ! grep --quiet something $bin/$script diff --git a/examples/lxc-systemd/README.md b/examples/lxc-systemd/README.md index eaabff2..d1d1b1d 100644 --- a/examples/lxc-systemd/README.md +++ b/examples/lxc-systemd/README.md @@ -23,20 +23,13 @@ forgejo-runner-service.sh installs a [Forgejo runner](https://forgejo.org/docs/n The following will be upgraded: -- `forgejo-runner-service.sh` will replace itself with the version found at `https://code.forgejo.org/forgejo/runner/src/tag/vX.Y.Z/examples/lxc-systemd/forgejo-runner-service.sh` +- `forgejo-runner-service.sh` will replace itself with the script found at the provided URL (e.g. `https://code.forgejo.org/forgejo/runner/src/tag/v6.3.1/examples/lxc-systemd/forgejo-runner-service.sh`) - `lxc-helpers*.sh` will be replaced with the version pinned in `forgejo-runner-service.sh` +- `forgejo-runner-X.Y.Z` will default to the version hardcoded in `forgejo-runner-service.sh` -Upgrade to the version X.Y.Z (e.g 6.2.1): +Example: -- `forgejo-runner-service.sh upgrade X.Y.Z` - -### Using a specific version of the Forgejo runner - -The goal is that a LXC container uses a version of the Forgejo runner -that is different from the default. It needs to be installed and pinned. - -- Install: `INPUTS_RUNNER_VERSION=6.3.0 forgejo-runner-service.sh install_runner` -- Pin the version in `/etc/forgejo-runner/N/env` (e.g. `INPUTS_RUNNER_VERSION=6.3.0`) +- `forgejo-runner-service.sh upgrade https://code.forgejo.org/forgejo/runner/src/tag/v6.3.1/examples/lxc-systemd/forgejo-runner-service.sh` ## Description @@ -87,3 +80,11 @@ The creation of a new runner is driven by the following environment variables: systemctl status forgejo-runner@$serial ``` - Set debug by adding `VERBOSE=true` in `/etc/forgejo-runner/$INPUTS_SERIAL/env` + +### Use a specific version of the Forgejo runner + +The goal is that a LXC container uses a version of the Forgejo runner +that is different from the default. It needs to be installed and pinned. + +- Install: `INPUTS_RUNNER_VERSION=6.3.0 forgejo-runner-service.sh install_runner` +- Pin the version in `/etc/forgejo-runner/N/env` (e.g. `INPUTS_RUNNER_VERSION=6.3.0`) diff --git a/examples/lxc-systemd/forgejo-runner-service.sh b/examples/lxc-systemd/forgejo-runner-service.sh index 1d6b965..fd4110f 100755 --- a/examples/lxc-systemd/forgejo-runner-service.sh +++ b/examples/lxc-systemd/forgejo-runner-service.sh @@ -21,7 +21,7 @@ trap "rm -fr $TMPDIR" EXIT : ${INPUTS_FORGEJO:=https://code.forgejo.org} : ${INPUTS_LIFETIME:=7d} : ${INPUTS_LXC_HELPERS_VERSION:=1.0.3} -: ${INPUTS_RUNNER_VERSION:=6.3.0} +: ${INPUTS_RUNNER_VERSION:=6.3.1} : ${KILL_AFTER:=21600} # 6h == 21600 NODEJS_VERSION=20 @@ -29,6 +29,7 @@ DEBIAN_RELEASE=bookworm YQ_VERSION=v4.45.1 SELF=${BASH_SOURCE[0]} SELF_FILENAME=$(basename "$SELF") +SELF_INSTALLED=/usr/local/bin/$SELF_FILENAME ETC=/etc/forgejo-runner LIB=/var/lib/forgejo-runner LOG=/var/log/forgejo-runner @@ -76,13 +77,11 @@ function install_or_update_lxc_helpers() { } function install_or_update_self() { - local bin=/usr/local/bin/$SELF_FILENAME - - if ! cmp --quiet $SELF $bin; then - if test -f $bin; then - $SUDO mv $bin $bin.backup + if ! cmp --quiet $SELF $SELF_INSTALLED; then + if test -f $SELF_INSTALLED; then + $SUDO mv $SELF_INSTALLED $SELF_INSTALLED.backup fi - $SUDO cp -a $SELF $bin + $SUDO cp -a $SELF $SELF_INSTALLED fi } @@ -160,6 +159,7 @@ After=network.target Restart=on-success ExecStart=/usr/local/bin/${SELF_FILENAME} run_in_copy start ExecStop=/usr/local/bin/${SELF_FILENAME} stop +TimeoutStopSec=10800 EnvironmentFile=/etc/forgejo-runner/%i/env [Install] @@ -197,6 +197,10 @@ function inside() { $SELF_FILENAME "$@" } +function display_default_runner_version() { + echo "Forgejo runner $INPUTS_RUNNER_VERSION" +} + function install_runner() { local runner=/usr/local/bin/forgejo-runner-$INPUTS_RUNNER_VERSION if test -f $runner; then @@ -355,14 +359,16 @@ function upgrade() { } function upgrade_safely() { - local version="${1:-$INPUTS_RUNNER_VERSION}" - local upgrade="${2:-$TMPDIR/$SELF_FILENAME}" + local url="$1" - if ! test -f $upgrade; then - curl --fail -sS -o $upgrade https://code.forgejo.org/forgejo/runner/raw/tag/v$version/examples/lxc-systemd/forgejo-runner-service.sh - fi + local upgrade_dir=$TMPDIR/upgrades + mkdir -p $TMPDIR/upgrades + local upgrade="$upgrade_dir/$SELF_FILENAME" + + curl --fail -sS -o $upgrade $url chmod +x $upgrade $upgrade install_runner + $upgrade display_default_runner_version $upgrade install_or_update_lxc_helpers $upgrade install_or_update_self }