From 46185f389eb8dc14c70b82b820cfe288df4a20e8 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 4 Nov 2021 20:25:10 +0200 Subject: [PATCH] Update run and lock path for systemd Since /var/run is a symlink to /run and /var/lock is a symlink to /run/lock for all modern operationg systems, it makes sense to change default paths that are used. To make such changes more flexible, ``systemd_run_dir`` and ``systemd_lock_dir`` are introduced. Change-Id: I60d321fcdce3d3a94233cc25c92898d9e9f2a9b8 --- defaults/main.yml | 12 ++++++++++++ .../notes/systemd_run_lock_dir-5b4b0cad9c860ce0.yaml | 12 ++++++++++++ tasks/main.yml | 9 ++++++--- templates/systemd-tmpfiles.j2 | 5 +++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/systemd_run_lock_dir-5b4b0cad9c860ce0.yaml diff --git a/defaults/main.yml b/defaults/main.yml index a7f2c75..f344021 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -62,6 +62,16 @@ systemd_service_config_overrides: {} # https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= systemd_default_service_type: simple +# System run directory used for services by default. +# Service name will be added to make a unique path. +# This option can also be defined for specific service entries under "systemd_services". +systemd_run_dir: "/run" + +# System lock directory used for services by default. +# Service name will be added to make a unique path. +# This option can also be defined for specific service entries under "systemd_services". +systemd_lock_dir: "/run/lock" + # Global lock path used for system services. # This is an optional variable and will have no effect if undefined. # This option can also be defined for specific service entries under "systemd_services". @@ -114,6 +124,8 @@ systemd_environment: {} # will be used to generate systemd overrides in /etc/systemd/system/service_name.service.d/overrides.conf # `systemd_overrides_only` -- (optional) Boolean variable, when True no service_name.service will be generated and role # will place only overrides for the existing service. +# `systemd_run_dir` -- (optional) Run directory that will be used for service runtime. Service name is added to the path +# `systemd_lock_dir` -- (optional) Lock directory that will be used for service runtime. Service name is added to the path # Under the service dictionary the "sockets" key can be added, which may contain list of the sockets # for the given service_name. Each socket in the lsit may have following structure: diff --git a/releasenotes/notes/systemd_run_lock_dir-5b4b0cad9c860ce0.yaml b/releasenotes/notes/systemd_run_lock_dir-5b4b0cad9c860ce0.yaml new file mode 100644 index 0000000..0fbc49d --- /dev/null +++ b/releasenotes/notes/systemd_run_lock_dir-5b4b0cad9c860ce0.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Added variables ``systemd_run_dir`` and ``systemd_lock_dir`` that allows + to control run and lock path for directories that will be used by systemd + services. Variables should not include service name since it will be added + by default at the end of the provided path. + These variables could be also defined as keys inside ``systemd_services`` + and this will have prescedence over default behaviour. + - | + Default run path for systemd services has been changed to ``/run`` and + lock path to ``/run/lock``. diff --git a/tasks/main.yml b/tasks/main.yml index 5ad7dc1..a0083ad 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -30,7 +30,7 @@ - name: Create TEMP run dir file: - path: "/var/run/{{ item.service_name | replace(' ', '_') }}" + path: "{{ item.systemd_run_dir | default(systemd_run_dir) }}/{{ item.service_name | replace(' ', '_') }}" state: directory owner: "{{ item.systemd_user_name | default(systemd_user_name) }}" group: "{{ item.systemd_group_name | default(systemd_group_name) }}" @@ -41,16 +41,19 @@ - name: Create TEMP service lock dir file: - path: "/var/lock/{{ item.service_name | replace(' ', '_') }}" + path: "{{ item.systemd_lock_dir | default(systemd_lock_dir) }}/{{ item.service_name | replace(' ', '_') }}" state: directory owner: "{{ item.systemd_user_name | default(systemd_user_name) }}" group: "{{ item.systemd_group_name | default(systemd_group_name) }}" mode: "02755" with_items: "{{ systemd_services }}" + when: + - (item.systemd_lock_path is not defined) and + (systemd_lock_path is not defined) tags: - systemd-service -- name: Create TEMP defined lock dir +- name: Create TEMP defined lock path file: path: "{{ item.systemd_lock_path | default(systemd_lock_path) }}" state: directory diff --git a/templates/systemd-tmpfiles.j2 b/templates/systemd-tmpfiles.j2 index cebb645..21bd066 100644 --- a/templates/systemd-tmpfiles.j2 +++ b/templates/systemd-tmpfiles.j2 @@ -3,6 +3,7 @@ {% if (item.systemd_lock_path is defined) or (systemd_lock_path is defined) %} D {{ item.systemd_lock_path | default(systemd_lock_path) }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} D {{ (item.systemd_lock_path | default(systemd_lock_path)) | replace('lock', 'run') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} +{% else %} +D {{ item.systemd_lock_dir | default(systemd_lock_dir) }}/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} +D {{ item.systemd_run_dir | default(systemd_run_dir) }}/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} {% endif %} -D /var/lock/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} -D /var/run/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }}