mirror of
https://github.com/roles-ansible/ansible_role_forgeo_runner.git
synced 2024-08-16 10:29:50 +02:00
Create systemd unit and register
This commit is contained in:
parent
6b4d153e91
commit
f69090efeb
7 changed files with 96 additions and 0 deletions
|
@ -8,3 +8,5 @@ Ansible role to install and Setup forgeo runner. (Work in Progress...)
|
|||
|
||||
https://forgejo.org/docs/next/admin/actions/
|
||||
|
||||
|
||||
Steps
|
||||
|
|
|
@ -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
handlers/main.yml
Normal file
16
handlers/main.yml
Normal file
|
@ -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
tasks/configure_runner.yml
Normal file
21
tasks/configure_runner.yml
Normal file
|
@ -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
|
|
@ -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
tasks/systemd.yml
Normal file
28
tasks/systemd.yml
Normal file
|
@ -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
templates/forgejo_runner.service.j2
Normal file
16
templates/forgejo_runner.service.j2
Normal file
|
@ -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
|
Loading…
Reference in a new issue