Skip to content

Commit

Permalink
Create systemd unit and register
Browse files Browse the repository at this point in the history
  • Loading branch information
DO1JLR committed Mar 21, 2024
1 parent 6b4d153 commit f69090e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Ansible role to install and Setup forgeo runner. (Work in Progress...)

https://forgejo.org/docs/next/admin/actions/


Steps
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ forgejo_runner__user_home: '/var/lib/forgejo-runner'
forgejo_runner__full_executable_path: '/usr/local/bin/forgejo_runner'
forgejo_runner__gpg_id: 'EB114F5E6C0DC2BCDD183550A4B61A2DC5923710'

forgejo_runner__instance_address: ''
forgejo_runner__token: ''
forgejo_runner__mode: "daemon"

# should we do a version check? (recomended)
submodules_versioncheck: false
16 changes: 16 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: "Restart forgejo-runner"
listen: "systemctl restart forgejo-runner"
become: true
ansible.builtin.systemd:
name: 'forgejo-runner'
state: 'restarted'
when: ansible_service_mgr == "systemd"

- name: "Reload systemd"
listen: 'systemctl daemon-reload'
become: true
ansible.builtin.systemd:
daemon_reload: true
when: ansible_service_mgr == "systemd"
notify: 'systemctl restart forgejo-runner'
21 changes: 21 additions & 0 deletions tasks/configure_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Make Sure Forgejo runner instace address is set
ansible.builtin.fail:
msg: "Please set forgejo_runner__instance_address"
when: forgejo_runner__instance_address == ''

- name: Make Sure Forgejo runner token is set
ansible.builtin.fail:
msg: "Please set forgejo_runner__token"
when: forgejo_runner__token == ''

- name: Register Forgejo runner
ansible.builtin.command:
chdir: "{{ forgejo_runner__user_home }}"
cmd: |
{{ forgejo_runner__full_executable_path }} register --no-interactive \
--token '{{ forgejo_runner__token }}' \
--instance '{{ forgejo_runner__instance_address }}' \
--name '{{ inventory_hostname }}@ansible'
creates: "{{ forgejo_runner__user_home }}/.runner"
become: true
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@
- name: Install forgejo runner binary
ansible.builtin.include_tasks:
file: 'install_runner.yml'

- name: Configure forgejo runner
ansible.builtin.include_tasks:
file: 'configure_runner.yml'

- name: Start forgejo runner as systemd service
ansible.builtin.include_tasks:
file: 'systemd.yml'
when: ansible_service_mgr == "systemd"
28 changes: 28 additions & 0 deletions tasks/systemd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: "Setup systemd service"
become: true
when: ansible_os_family == "Debian"
ansible.builtin.template:
src: 'forgejo_runner.service.j2'
dest: '/lib/systemd/system/forgejo-runner.service'
owner: 'root'
group: 'root'
mode: '0644'
notify:
- 'systemctl restart forgejo-runner'
- 'systemctl daemon-reload'

- name: "Reload systemd"
become: true
ansible.builtin.systemd:
daemon_reload: true
notify: 'systemctl restart forgejo-runner'

- name: "Start and enable forgejo-runner"
become: true
ansible.builtin.systemd:
name: 'forgejo-runner'
state: started
enabled: true
when: ansible_service_mgr == "systemd"
notify: 'systemctl restart forgejo-runner'
16 changes: 16 additions & 0 deletions templates/forgejo_runner.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ ansible_managed | comment }}
[Unit]
Description=Forgejo runner
After=network.target

[Service]
Type=simple
User={{ forgejo_runner__user }}
Group={{ forgejo_runner__group }}
WorkingDirectory={{ forgejo_runner__user_home }}
ExecStart={{ forgejo_runner__full_executable_path }} {{ forgejo_runner__mode }}
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target

0 comments on commit f69090e

Please sign in to comment.