ansible-role-systemd_service/templates/systemd-service.j2

79 lines
2.2 KiB
Django/Jinja

# {{ ansible_managed }}
[Unit]
Description={{ item.service_name }} service
{% for item in systemd_after_targets %}
After={{ item }}
{% endfor %}
[Service]
{% set service_type = item.service_type | default(systemd_default_service_type) %}
Type={{ service_type }}
User={{ systemd_user_name }}
Group={{ systemd_group_name }}
{% set _execstarts = item.execstarts %}
{% if _execstarts is string %}
{% set _execstarts = [_execstarts] %}
{% endif %}
{% for execstart in _execstarts %}
ExecStart={{ execstart }}
{% endfor %}
{% set _execreloads = item.execreloads | default((service_type == 'simple') | ternary(['/bin/kill -HUP $MAINPID'], [])) %}
{% if _execreloads is string %}
{% set _execreloads = [_execreloads] %}
{% endif %}
{% for execreload in _execreloads %}
ExecReload={{ execreload }}
{% endfor %}
{% set _execstops = item.execstops | default([]) %}
{% if _execstops is string %}
{% set _execstops = [_execstops] %}
{% endif %}
{% for execstop in _execstops %}
ExecStop={{ execstop }}
{% endfor %}
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec={{ systemd_TimeoutSec }}
{% if service_type != 'oneshot' %}
Restart={{ systemd_Restart }}
RestartSec={{ systemd_RestartSec }}
{% endif %}
# This creates a specific slice which all services will operate from
# The accounting options give us the ability to see resource usage through
# the `systemd-cgtop` command.
Slice={{ systemd_slice_name }}.slice
# Set Accounting
{% if item.program_accounting is defined %}
{% for key, value in item.program_accounting.items() %}
{{ key }}={{ value }}
{% endfor %}
{% else %}
CPUAccounting={{ systemd_CPUAccounting }}
BlockIOAccounting={{ systemd_BlockIOAccounting }}
MemoryAccounting={{ systemd_MemoryAccounting }}
TasksAccounting={{ systemd_TasksAccounting }}
{% endif %}
{% if service_type != 'oneshot' %}
# Set Sandboxing
{% if item.program_sandboxing is defined %}
{% for key, value in item.program_sandboxing.items() %}
{{ key }}={{ value }}
{% endfor %}
{% else %}
PrivateTmp={{ systemd_PrivateTmp }}
PrivateDevices={{ systemd_PrivateDevices }}
PrivateNetwork={{ systemd_PrivateNetwork }}
PrivateUsers={{ systemd_PrivateUsers }}
{% endif %}
{% endif %}
[Install]
WantedBy=multi-user.target