Skip to content
Snippets Groups Projects
Commit 74569780 authored by Jörg Sachse's avatar Jörg Sachse
Browse files

feat: place systemd units into '/usr/local/lib/systemd/system/' directory for improved handling

parent e57df7dd
No related branches found
No related tags found
No related merge requests found
...@@ -40,10 +40,49 @@ ...@@ -40,10 +40,49 @@
state: latest state: latest
allow_unauthenticated: "true" allow_unauthenticated: "true"
##### BEGIN #####
# Previously, our systemd unit files were installed below "/etc/systemd/user/"
# and activated semi-manually by calling
# `systemctl enable /full/path/to/systemd-unit.service`. This was the only way
# to make short names like "subapp.service" usable, which is a major
# convenience win in everyday operations. On the other hand, it also makes the
# SubApp start on bootup, which isn't always the desired and safe behaviour.
#
# To improve upon this situation, we're now moving the systemd units to
# "/usr/local/lib/systemd/system/", which, according to systemd's manual, is
# the more suitable location and also enables the use of short service names
# even if a service is not enabled and thus doesn't automatically startup on
# (re)boot.
- name: find systemd units that are installed in the wrong location
ansible.builtin.find:
paths:
- "/etc/systemd/user/"
patterns:
- "*.service"
register: old_unit_files
- name: disable and stop services
ansible.builtin.systemd:
unit: "{{ item.path | basename }}"
enabled: false
status: stopped
loop: "{{ old_unit_files.files }}"
when: old_unit_files.matched > 0
- name: create directory for Systemd unitfiles
ansible.builtin.file:
path: "/usr/local/lib/systemd/system/"
state: directory
mode: "0755"
- name: Systemd-Unitfiles installieren (Templates) - name: Systemd-Unitfiles installieren (Templates)
ansible.builtin.template: ansible.builtin.template:
src: "etc/systemd/user/{{ item }}.j2" src: "usr/local/lib/systemd/system/{{ item }}.j2"
dest: "/etc/systemd/user/{{ item }}" dest: "/usr/local/lib/systemd/system/{{ item }}"
owner: "{{ vault_subapp_vars.files.subapp.owner }}" owner: "{{ vault_subapp_vars.files.subapp.owner }}"
group: "{{ vault_subapp_vars.files.subapp.group }}" group: "{{ vault_subapp_vars.files.subapp.group }}"
mode: "0644" mode: "0644"
...@@ -58,8 +97,8 @@ ...@@ -58,8 +97,8 @@
- name: Systemd-Unitfiles installieren (Files) - name: Systemd-Unitfiles installieren (Files)
ansible.builtin.copy: ansible.builtin.copy:
src: "etc/systemd/user/{{ item }}" src: "usr/local/lib/systemd/system/{{ item }}"
dest: "/etc/systemd/user/{{ item }}" dest: "/usr/local/lib/systemd/system/{{ item }}"
mode: "0644" mode: "0644"
loop: loop:
- "chmod_sip_uploads.service" - "chmod_sip_uploads.service"
...@@ -82,8 +121,8 @@ ...@@ -82,8 +121,8 @@
loop: loop:
- "chmod_sip_uploads.service" - "chmod_sip_uploads.service"
- "chown_dip_access.service" - "chown_dip_access.service"
- "disapp.service" # - "disapp.service" # DO NOT ENABLE, we want to start the DisApp manually after (re)boots.
- "subapp.service" # - "subapp.service" # DO NOT ENABLE, we want to start the SubApp manually after (re)boots.
- "webservice_status_SLUBarchiv.service" - "webservice_status_SLUBarchiv.service"
register: subapp_services_enabled register: subapp_services_enabled
changed_when: false changed_when: false
...@@ -94,11 +133,13 @@ ...@@ -94,11 +133,13 @@
tags: [systemd] tags: [systemd]
- name: Services automatisch bei jedem Booten starten - name: Services automatisch bei jedem Booten starten
ansible.builtin.command: "systemctl enable /etc/systemd/user/{{ item.item }}" # noqak no-changed-when command-instead-of-module ansible.builtin.command: "systemctl enable {{ item.item }}" # noqak no-changed-when command-instead-of-module
loop: "{{ subapp_services_enabled.results }}" loop: "{{ subapp_services_enabled.results }}"
when: item.stdout != "enabled" when: item.stdout != "enabled"
tags: [systemd] tags: [systemd]
##### END #####
- name: git installieren - name: git installieren
ansible.builtin.apt: ansible.builtin.apt:
name: "git" name: "git"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment