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
This commit is contained in:
Dmitriy Rabotyagov 2021-11-04 20:25:10 +02:00
parent 9d14e194ca
commit 46185f389e
4 changed files with 33 additions and 5 deletions

View File

@ -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:

View File

@ -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``.

View File

@ -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

View File

@ -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) }}