forgejo-runner-service.sh installs a [Forgejo runner](https://forgejo.org/docs/next/admin/runner-installation/) within an [LXC container](https://linuxcontainers.org/lxc/) and runs it from a systemd service.
> **Warning** runners will not be upgraded immediately, the upgrade will happen when they restart (at `$INPUTS_LIFETIME` intervals).
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`
-`lxc-helpers*.sh` will be replaced with the version pinned in `forgejo-runner-service.sh`
-`systemctl start forgejo-runner@$INPUTS_SERIAL` will do the following when it starts and every `$INPUTS_LIFETIME` interval after that:
- attempt to gracefully stop (SIGTERM) the runner, waiting for all jobs to complete
- forcibly kill the runner if it does not stop within 6h
- shutdown the LXC container and delete it (the volumes bind mounted are preserved)
- create a brand new LXC container (with the specified `$INPUTS_LXC_CONFIG`)
- install and run a Forgejo runner daemon in the LXC container using `/etc/forgejo-runner/$INPUTS_SERIAL/config.yml`
- redirect the output of the runner to `/var/log/forgejo-runner/$INPUTS_SERIAL.log`
-`systemctl stop forgejo-runner@$INPUTS_SERIAL` will stop the runner but keep the LXC container running
## Creation
The creation of a new runner is driven by the following environment variables:
-`INPUTS_SERIAL`: unique number in the range `[10-100]` (check `/etc/forgejo-runner`)
-`INPUTS_TOKEN`: a runner registration token obtained from the web UI
-`INPUTS_FORGEJO`: the Forgejo instance from which `INPUTS_TOKEN` was obtained (e.g. https://code.forgejo.org)
-`INPUTS_RUNNER_VERSION`: the version of the Forgejo runner as found in https://code.forgejo.org/forgejo/runner/releases (e.g. 6.2.0)
-`INPUTS_LXC_CONFIG`: the value of the `--config` argument of [lxc-helpers](https://code.forgejo.org/forgejo/lxc-helpers/#usage) used when creating the LXC container for the runner (e.g. `docker`)
-`INPUTS_LIFETIME`: the LXC container is re-created when its lifetime expires (e.g. 7d)
## Hacking
- An existing LXC configuration will not be modified. If `lxc-ls` exists, it is assumed that LXC is configured and ready to be used.