Skip to content
Snippets Groups Projects
Unverified Commit 69995082 authored by Javier Bértoli's avatar Javier Bértoli Committed by GitHub
Browse files

Merge pull request #67 from toanju/dropin

feat(unit): add dropin capability for unit files
parents c815870d 3d8abeed
No related branches found
No related tags found
No related merge requests found
...@@ -69,6 +69,16 @@ systemd: ...@@ -69,6 +69,16 @@ systemd:
Install: Install:
WantedBy: multi-user.target WantedBy: multi-user.target
systemd-journald:
enabled: true
status: start
dropin: true
Unit:
Description: Fancy new description
Service:
WatchdocSec: 2min
RestartSec: 2
path: path:
trigger-service-on-changes: trigger-service-on-changes:
# this parameter is passed to systemctl to enable/disable the unit # this parameter is passed to systemctl to enable/disable the unit
......
...@@ -7,10 +7,16 @@ include: ...@@ -7,10 +7,16 @@ include:
{% if unittype in unittypes.get('Valid') %} {% if unittype in unittypes.get('Valid') %}
{% for unit, unitconfig in units.items() %} {% for unit, unitconfig in units.items() %}
{% set unit_status = 'disable' if unitconfig.enabled is defined and unitconfig.enabled == false else 'enable' %} {% set unit_status = 'disable' if unitconfig.enabled is defined and unitconfig.enabled == false else 'enable' %}
{% set dropin = unitconfig.dropin | default(false) %}
systemd_systemd_units_file_{{ unit }}_{{ unittype }}: systemd_systemd_units_file_{{ unit }}_{{ unittype }}:
file.managed: file.managed:
{%- if dropin %}
- name: /etc/systemd/system/{{ unit }}.{{ unittype }}.d/salt-override.conf
- makedirs: True
{%- else %}
- name: /etc/systemd/system/{{ unit }}.{{ unittype }} - name: /etc/systemd/system/{{ unit }}.{{ unittype }}
{%- endif %}
- template: jinja - template: jinja
- source: salt://systemd/units/unit.jinja - source: salt://systemd/units/unit.jinja
- context: - context:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# This file managed by Salt, do not edit # This file managed by Salt, do not edit
# #
{% for section, sectioncontent in config.items() %} {% for section, sectioncontent in config.items() %}
{%- if section not in ['enabled', 'status'] %} {%- if section not in ['enabled', 'status', 'dropin'] %}
[{{ section }}] [{{ section }}]
{%- for key, value in sectioncontent.items() %} {%- for key, value in sectioncontent.items() %}
{%- if value is list %} {%- if value is list %}
......
...@@ -22,6 +22,7 @@ control 'Systemd units' do ...@@ -22,6 +22,7 @@ control 'Systemd units' do
its('group') { should eq 'root' } its('group') { should eq 'root' }
its('content') { should_not include '[status]' } its('content') { should_not include '[status]' }
its('content') { should_not include '[enabled]' } its('content') { should_not include '[enabled]' }
its('content') { should_not include '[dropin]' }
its('content') { should include 'Documentation=man:rsync(1) man:rsyncd.conf(5)' } its('content') { should include 'Documentation=man:rsync(1) man:rsyncd.conf(5)' }
its('content') { should include 'ConditionPathExists=/etc/rsyncd.conf' } its('content') { should include 'ConditionPathExists=/etc/rsyncd.conf' }
its('content') { should include 'ConditionPathExists=/etc/passwd' } its('content') { should include 'ConditionPathExists=/etc/passwd' }
...@@ -34,4 +35,20 @@ control 'Systemd units' do ...@@ -34,4 +35,20 @@ control 'Systemd units' do
it { should be_enabled } it { should be_enabled }
it { should be_running } it { should be_running }
end end
describe file('/etc/systemd/system/systemd-journald.service.d/salt-override.conf') do
its('type') { should eq :file }
its('mode') { should cmp '0644' }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('content') { should_not include '[status]' }
its('content') { should_not include '[enabled]' }
its('content') { should_not include '[dropin]' }
its('content') { should include '[Unit]' }
its('content') { should include 'Description=Fancy new description' }
its('content') { should include '[Service]' }
its('content') { should include 'WatchdocSec=2min' }
its('content') { should include 'RestartSec=2' }
its('content') { should_not include '[Install]' }
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment