Files
grm/ansible/roles/gitea-runner/templates/gitea-runner@.service.j2
T
Emil Simeonov 1bbe3b4f43 GRM-17: fix docker mode status detection and systemd template
- systemd template for docker mode now uses Type=oneshot + RemainAfterExit=yes
  so that systemctl is-active returns active when the container is running.
  Previously docker run -d exited immediately, causing systemd to mark the
  service as inactive even though the container was still up.
- grm list now tries multiple container name fallbacks for docker mode:
  1. gitea-runner-{name} (current naming)
  2. gitea-runner-{host} (legacy installs where name defaulted to host)
  3. systemctl is-active gitea-runner@{name} (for installs with fixed template)
- All tests pass, 100% coverage, ruff + pyright clean
2026-06-19 02:47:14 +02:00

36 lines
1.2 KiB
Django/Jinja

[Unit]
Description=Gitea Actions Runner %i ({% if runner_mode == 'docker' %}docker{% else %}binary{% endif %})
After=network.target{% if runner_mode == 'docker' %} docker.service
Requires=docker.service{% endif %}
[Service]
{% if runner_mode == 'docker' %}
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/usr/bin/docker rm -f gitea-runner-%i
ExecStart=/usr/bin/docker run -d --name gitea-runner-%i \
--restart=no \
-v /var/run/docker.sock:/var/run/docker.sock \
-v {{ gitea_runner_base_data_dir }}/%i:/data \
-w /data \
{{ gitea_runner_docker_image }}:{{ gitea_runner_version | regex_replace('^v', '') }} \
daemon --config /data/config.yaml
ExecStop=/usr/bin/docker stop -t 30 gitea-runner-%i
ExecStopPost=-/usr/bin/docker rm -f gitea-runner-%i
Restart=on-failure
RestartSec={{ gitea_runner_service_restart_sec }}
{% else %}
Type=simple
ExecStart={{ gitea_runner_binary_path }} daemon --config {{ gitea_runner_base_config_dir }}/%i/config.yaml
WorkingDirectory={{ gitea_runner_base_data_dir }}/%i
ExecStop=/bin/kill -TERM $MAINPID
TimeoutStopSec=30
Restart=on-failure
RestartSec={{ gitea_runner_service_restart_sec }}
User={{ gitea_runner_service_user }}
Group=docker
{% endif %}
[Install]
WantedBy=multi-user.target