Skip to content

Commit

Permalink
fix(macos): launchctl and plist fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jul 22, 2020
1 parent 274e50b commit 543d5c7
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 39 deletions.
16 changes: 10 additions & 6 deletions mongodb/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- set sls_config_clean = tplroot ~ '.config.users' %}
{%- set sls_config_clean = tplroot ~ '.config.clean' %}
{%- set sls_service_clean = tplroot ~ '.service.clean' %}
{%- set formula = d.formula %}
Expand All @@ -15,14 +15,16 @@ include:
{{ formula }}-clean-prerequisites:
pip.removed:
- names: {{ d.pkg.pips|json }}
- require:
- sls: {{ sls_service_clean }}
- sls: {{ sls_config_clean }}
- require_in:
- file: {{ formula }}-clean-prerequisites
file.absent:
- names:
- {{ d.dir.tmp }}
- {{ d.dir.var }}
- /tmp/mac_shortcut.sh
- require:
- sls: {{ sls_service_clean }}
- sls: {{ sls_config_clean }}
{%- for comp in d.components %}
{%- if comp in d.wanted and d.wanted is iterable and comp in d.pkg and d.pkg[comp] is mapping %}
Expand All @@ -42,6 +44,8 @@ include:
- file: {{ formula }}-clean-prerequisites
file.absent:
- name: {{ software['path'] }}
- require:
- file: {{ formula }}-clean-prerequisites
{%- if d.use_upstream == 'repo' %}
pkgrepo.absent:
- name: {{ d.pkg['repo']['name'] }}
Expand Down Expand Up @@ -81,8 +85,8 @@ include:
- {{ d.dir.var }}/{{ name }}
- {{ d.dir.service }}/{{ name }}.service
- /Library/LaunchAgents/{{ name if 'name' not in service else service.name }}.plist
# require:
# file: {{ formula }}-clean-prerequisites
- require:
- file: {{ formula }}-clean-prerequisites
cmd.run:
- name: systemctl daemon-reload >/dev/null 2>&1 || true
- onlyif: {{ grains.kernel|lower == 'linux' }}
Expand Down
8 changes: 8 additions & 0 deletions mongodb/config/alternatives/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
{%- endfor %} {# component #}
{%- endif %} {# wanted #}
{%- endfor %} {# components #}
{%- else %}
{{ formula }}-config-alternatives-clean-notification:
test.show_notification:
- text: |
Note: The linux alternatives state is not applicable for {{ grains.os }}
{%- endif %} {# linux #}
8 changes: 8 additions & 0 deletions mongodb/config/alternatives/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ include:
{%- endfor %} {# component #}
{%- endif %} {# wanted #}
{%- endfor %} {# components #}
{%- else %}
{{ formula }}-config-alternatives-install-notification:
test.show_notification:
- text: |
Note: The linux alternatives state is not applicable for {{ grains.os }}
{%- endif %} {# linux #}
4 changes: 4 additions & 0 deletions mongodb/config/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ include:
- group: {{ formula }}-config-clean-{{ name }}-usergroup
- require:
- sls: {{ sls_service_clean }}
- sls: {{ sls_alternatives_clean }}
group.absent:
- name: {{ d.default.group if 'group' not in software else software['group'] }}
- require:
- user: {{ formula }}-config-clean-{{ name }}-usergroup
{%- endif %} {# users #}
{{ formula }}-config-clean-{{ name }}-files:
Expand All @@ -47,6 +50,7 @@ include:
{%- endif %}
- require:
- sls: {{ sls_service_clean }}
- sls: {{ sls_alternatives_clean }}
{%- endif %} {# wanted #}
{%- endfor %} {# component #}
Expand Down
1 change: 1 addition & 0 deletions mongodb/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include:
- makedirs: True
- require:
- sls: {{ sls_software_install }}
- sls: {{ sls_config_users }}
{%- for comp in d.components %}
{%- if comp in d.wanted and d.wanted is iterable and comp in d.pkg and d.pkg[comp] is mapping %}
Expand Down
6 changes: 6 additions & 0 deletions mongodb/config/users.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import data as d with context %}
{%- set formula = d.formula %}
{%- set sls_software_install = tplroot ~ '.install' %}
include:
- {{ sls_software_install }}
{%- for comp in d.components %}
{%- if comp in d.wanted and d.wanted is iterable and comp in d.pkg and d.pkg[comp] is mapping %}
Expand All @@ -19,6 +23,8 @@
- name: {{ d.default.group if 'group' not in software else software['group'] }}
- require_in:
- user: {{ formula }}-config-usergroup-{{ servicename }}-install-usergroup-present
- require_in:
- sls: {{ sls_software_install }}
user.present:
- name: {{ user }}
- shell: /bin/false
Expand Down
10 changes: 10 additions & 0 deletions mongodb/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ mongodb:
# http://docs.mongodb.org/manual/reference/configuration-options
storage:
dbPath: /var/lib/mongodb/mongod
systemLog:
quiet: true
traceAllExceptions: false
path: /var/log/mongodb/mongod.log
destination: file
logAppend: true
# replication:
# replSetName: "rs1"
# sharding:
Expand Down Expand Up @@ -109,6 +115,10 @@ mongodb:
config:
sharding:
configDB: 'rs1/127.0.0.1:27018'
systemLog:
quiet: true
traceAllExceptions: false
path: /var/log/mongodb/mongos.log
service:
name: mongos
firewall:
Expand Down
10 changes: 4 additions & 6 deletions mongodb/files/default/macos.plist.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
<string>org.mongo.mongodb.{{ svc }}</string>
<key>ProgramArguments</key>
<array>
<string>{{ binpath }}/bin/{{ svc }} </string>
<string>--config </string>
<string>{{ binpath }}/bin/{{ svc }}</string>
<string>{{ '--config' }}</string>
<string>{{ config }}</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>{{ user }}</string>
<key>StandardErrorPath</key>
<string>/dev/null</string>
<string>/var/log/mongodb/{{ svc }}.log</string>
<key>StandardOutPath</key>
<string>/dev/null</string>
<string>/var/log/mongodb/{{ svc }}.log</string>
</dict>
</plist>
7 changes: 7 additions & 0 deletions mongodb/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ include:
- group: {{ d.identity.rootgroup }}
- require:
- file: {{ formula }}-{{ comp }}-{{ name }}-{{ package }}-install
- unless:
- test -f {{ software['path'] }}/dummyFILENAME
{%- if 'commands' in software and software['commands'] is iterable %}
{%- for cmd in software['commands'] %}
- test -x {{ software['path'] }}/bin/{{ cmd }}
{%- endfor %}
{%- endif %}
{%- else %}
test.show_notification:
Expand Down
34 changes: 26 additions & 8 deletions mongodb/service/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,32 @@ include:
{%- set servicename = name if 'service' not in software else software.service.name %}
{{ formula }}-service-dead-{{ comp }}-{{ servicename }}-clean:
{%- if grains.kernel|lower == 'darwin' %} {# service.running is buggy #}
cmd.run:
- names:
- launchctl stop {{ servicename }} || true
- launchctl unload /Library/LaunchAgents/{{ servicename }}.plist || true
{%- else %}
service.dead:
- name: {{ servicename }}
{% if grains.kernel|lower == 'linux' %}
- onlyif: systemctl list-units |grep {{ servicename }} >/dev/null 2>&1
{%- endif %} {# linux #}
- enable: False
{%- endif %}
- require_in:
- sls: {{ sls_config_clean }}
file.absent:
- names:
- {{ d.dir.service }}/{{ servicename }}.service
- /etc/logrotate.d/{{ formula }}_{{ servicename }}
{%- if 'systemLog' in config and 'destination' in config['systemLog'] %}
{%- if config['systemLog']['destination'] == 'file' %}
- {{ config['systemLog']['path'] }}
{%- else %}
- {{ '/var/log/mongodb/' ~ servicename ~ '.log' }}
{%- endif %}
{%- endif %}
- require_in:
- sls: {{ sls_config_clean }}
{% if grains.kernel|lower == 'linux' %}
Expand All @@ -43,18 +59,20 @@ include:
file.absent:
- names:
- /tmp/MySiLydUmMyFiLE
{%- if 'processManagement' in config and config['processManagement']['pidFilePath'] %}
{%- if 'processManagement' in config and 'pidFilePath' in config['processManagement'] %}
- {{ config['processManagement']['pidFilePath'] }}
{%- endif %}
{%- if 'storage' in config and 'dbPath' in config['storage'] %}
{%- else %}
- {{ '/var/run/{{ name }}.pid' }}
{%- endif %}
{%- if 'storage' in config and 'dbPath' in config['storage'] %}
- {{ config['storage']['dbPath'] }}
{%- endif %}
{%- if 'schema' in config and 'path' in config['schema'] %}
{%- endif %}
{%- if 'schema' in config and 'path' in config['schema'] %}
- {{ config['schema']['path'] }}
{%- endif %}
{%- if 'systemLog' in config and 'path' in config['systemLog'] %}
{%- endif %}
{%- if 'systemLog' in config and 'path' in config['systemLog'] %}
- {{ config['systemLog']['path'] }}
{%- endif %}
{%- endif %}
- require_in:
- sls: {{ sls_config_clean }}
Expand Down
Loading

0 comments on commit 543d5c7

Please sign in to comment.