Skip to content

Commit

Permalink
Merge pull request #67 from toanju/dropin
Browse files Browse the repository at this point in the history
feat(unit): add dropin capability for unit files
  • Loading branch information
javierbertoli authored Apr 2, 2021
2 parents c815870 + 3d8abee commit 6999508
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ systemd:
Install:
WantedBy: multi-user.target

systemd-journald:
enabled: true
status: start
dropin: true
Unit:
Description: Fancy new description
Service:
WatchdocSec: 2min
RestartSec: 2

path:
trigger-service-on-changes:
# this parameter is passed to systemctl to enable/disable the unit
Expand Down
6 changes: 6 additions & 0 deletions systemd/units/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ include:
{% if unittype in unittypes.get('Valid') %}
{% for unit, unitconfig in units.items() %}
{% 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 }}:
file.managed:
{%- if dropin %}
- name: /etc/systemd/system/{{ unit }}.{{ unittype }}.d/salt-override.conf
- makedirs: True
{%- else %}
- name: /etc/systemd/system/{{ unit }}.{{ unittype }}
{%- endif %}
- template: jinja
- source: salt://systemd/units/unit.jinja
- context:
Expand Down
2 changes: 1 addition & 1 deletion systemd/units/unit.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file managed by Salt, do not edit
#
{% for section, sectioncontent in config.items() %}
{%- if section not in ['enabled', 'status'] %}
{%- if section not in ['enabled', 'status', 'dropin'] %}
[{{ section }}]
{%- for key, value in sectioncontent.items() %}
{%- if value is list %}
Expand Down
17 changes: 17 additions & 0 deletions test/integration/default/controls/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 'Documentation=man:rsync(1) man:rsyncd.conf(5)' }
its('content') { should include 'ConditionPathExists=/etc/rsyncd.conf' }
its('content') { should include 'ConditionPathExists=/etc/passwd' }
Expand All @@ -34,4 +35,20 @@
it { should be_enabled }
it { should be_running }
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

0 comments on commit 6999508

Please sign in to comment.