diff --git a/mongodb/clean.sls b/mongodb/clean.sls index 63ddbcd..0fc4e13 100644 --- a/mongodb/clean.sls +++ b/mongodb/clean.sls @@ -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 %} @@ -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 %} @@ -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'] }} @@ -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' }} diff --git a/mongodb/config/alternatives/clean.sls b/mongodb/config/alternatives/clean.sls index fe2a2a3..38e21ed 100644 --- a/mongodb/config/alternatives/clean.sls +++ b/mongodb/config/alternatives/clean.sls @@ -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 #} diff --git a/mongodb/config/alternatives/install.sls b/mongodb/config/alternatives/install.sls index a287ad2..6eb8750 100644 --- a/mongodb/config/alternatives/install.sls +++ b/mongodb/config/alternatives/install.sls @@ -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 #} diff --git a/mongodb/config/clean.sls b/mongodb/config/clean.sls index 8b6564e..5ba0a73 100644 --- a/mongodb/config/clean.sls +++ b/mongodb/config/clean.sls @@ -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: @@ -47,6 +50,7 @@ include: {%- endif %} - require: - sls: {{ sls_service_clean }} + - sls: {{ sls_alternatives_clean }} {%- endif %} {# wanted #} {%- endfor %} {# component #} diff --git a/mongodb/config/file.sls b/mongodb/config/file.sls index 6019a61..bdfd7cc 100644 --- a/mongodb/config/file.sls +++ b/mongodb/config/file.sls @@ -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 %} diff --git a/mongodb/config/users.sls b/mongodb/config/users.sls index 950cbfa..f0f0177 100644 --- a/mongodb/config/users.sls +++ b/mongodb/config/users.sls @@ -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 %} @@ -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 diff --git a/mongodb/defaults.yaml b/mongodb/defaults.yaml index 60f2bd7..0d98c29 100644 --- a/mongodb/defaults.yaml +++ b/mongodb/defaults.yaml @@ -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: @@ -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: diff --git a/mongodb/files/default/macos.plist.jinja b/mongodb/files/default/macos.plist.jinja index a1707fe..3cc752f 100644 --- a/mongodb/files/default/macos.plist.jinja +++ b/mongodb/files/default/macos.plist.jinja @@ -6,17 +6,15 @@ org.mongo.mongodb.{{ svc }} ProgramArguments - {{ binpath }}/bin/{{ svc }} - --config + {{ binpath }}/bin/{{ svc }} + {{ '--config' }} {{ config }} RunAtLoad - UserName - {{ user }} StandardErrorPath - /dev/null + /var/log/mongodb/{{ svc }}.log StandardOutPath - /dev/null + /var/log/mongodb/{{ svc }}.log diff --git a/mongodb/install.sls b/mongodb/install.sls index 1aabc18..4cd48a1 100644 --- a/mongodb/install.sls +++ b/mongodb/install.sls @@ -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: diff --git a/mongodb/service/clean.sls b/mongodb/service/clean.sls index 5b9a845..6746b5f 100644 --- a/mongodb/service/clean.sls +++ b/mongodb/service/clean.sls @@ -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' %} @@ -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 }} diff --git a/mongodb/service/running.sls b/mongodb/service/running.sls index 499fca4..100778b 100644 --- a/mongodb/service/running.sls +++ b/mongodb/service/running.sls @@ -11,23 +11,24 @@ include: - {{ sls_config_users }} - {{ sls_software_install }} + {%- if grains.kernel|lower == 'linux' %} {{ formula }}-service-running-prerequisites: file.managed: - name: /etc/init.d/disable-transparent-hugepages - source: salt://{{ formula }}/files/disable-transparent-hugepages.init - unless: test -f /etc/init.d/disable-transparent-hugepages 2>/dev/null - - onlyif: {{ grains.kernel|lower == 'linux' and d.wanted.disable_transparent_hugepages }} + - onlyif: {{ d.wanted.disable_transparent_hugepages }} - mode: '0755' - makedirs: True - require: - sls: {{ sls_software_install }} + - sls: {{ sls_config_users }} cmd.run: - name: echo never >/sys/kernel/mm/transparent_hugepage/enabled - - unless: test -f /etc/init.d/disable-transparent-hugepages 2>/dev/null - - onlyif: {{ grains.kernel|lower == 'linux' and d.wanted.disable_transparent_hugepages }} + - onlyif: {{ d.wanted.disable_transparent_hugepages }} - require: - file: {{ formula }}-service-running-prerequisites - {%- if d.wanted.firewall and grains.kernel|lower == 'linux' %} + {%- if d.wanted.firewall %} pkg.installed: - name: firewalld - reload_modules: true @@ -36,6 +37,7 @@ include: - onlyif: systemctl list-units | grep firewalld >/dev/null 2>&1 - enable: True {%- endif %} + {%- endif %} {%- 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 %} @@ -49,7 +51,7 @@ include: {%- set config = software['config'] %} {%- set service_files = [] %} - {%- if 'processManagement' in config and config['processManagement']['pidFilePath'] %} + {%- if 'processManagement' in config and 'pidFilePath' in config['processManagement'] %} {%- do service_files.append(config['processManagement']['pidFilePath']) %} {{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-pidpath: @@ -91,13 +93,14 @@ include: - group - require: - sls: {{ sls_config_users }} + - unless: test -d {{ config['storage']['dbPath'] }} - require_in: - service: {{ formula }}-service-running-{{ comp }}-{{ servicename }} {%- if 'selinux' in d.wanted and d.wanted.selinux %} selinux.fcontext_policy_present: - name: '{{ config['storage']['dbPath'] }}(/.*)?' - sel_type: {{ name }}_var_lib_t - - require: + - onchanges: - file: {{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-datapath - require_in: - selinux: {{ formula }}-service-running-{{ comp }}-{{ servicename }}-selinux-applied @@ -132,13 +135,19 @@ include: {%- endif %} {%- endif %} - {%- if 'systemLog' in config and 'path' in config['systemLog'] %} - {%- do service_files.append(config['systemLog']['path']) %} - {%- do service_files.append('/etc/logrotate.d/{{ formula }}_' ~ name ) %} + {%- set path = '/var/log/mongodb/' ~ servicename ~ '.log' %} + {%- if 'systemLog' in config and 'destination' in config['systemLog'] %} + {%- if config['systemLog']['destination'] == 'file' %} + {%- if 'path' in config['systemLog'] %} + {%- set path = config['systemLog']['path'] %} + {%- endif %} + {%- endif %} + {%- endif %} + {%- do service_files.append(path) %} {{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-syslogpath: file.directory: - - name: {{ config['systemLog']['path'] }} + - name: {{ salt['cmd.run']( 'dirname ' ~ path ) }} - user: {{ d.default.user if 'user' not in software else software['user'] }} - group: {{ d.default.group if 'group' not in software else software['group'] }} - dir_mode: '0775' @@ -148,15 +157,26 @@ include: - recurse: - user - group + +{{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-syslogfile: + file.managed: + - name: {{ path }} + - user: {{ d.default.user if 'user' not in software else software['user'] }} + - group: {{ d.default.group if 'group' not in software else software['group'] }} + - mode: '0775' + - create: true + - replace: false + - require: + - file: {{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-syslogpath - require_in: - service: {{ formula }}-service-running-{{ comp }}-{{ servicename }} - {%- if 'selinux' in d.wanted and d.wanted.selinux %} + {%- if 'selinux' in d.wanted and d.wanted.selinux %} selinux.fcontext_policy_present: - - name: '{{ logpath }}(/.*)?' + - name: {{ salt['cmd.run']( 'dirname ' ~ path ) }}'(/.*)?' - sel_type: {{ name }}_var_log_t - require_in: - selinux: {{ formula }}-service-running-{{ comp }}-{{ servicename }}-selinux-applied - {%- endif %} + {%- endif %} {{ formula }}-service-running-{{ comp }}-{{ servicename }}-install-logrotate: file.managed: @@ -169,19 +189,22 @@ include: - source: salt://{{ formula }}/files/default/logrotate.jinja - context: svc: {{ name }} - pattern: {{ config['systemLog']['path'] }} + pattern: {{ salt['cmd.run']( 'dirname ' ~ path ) }} + {%- if 'processManagement' in config and 'pidFilePath' in config['processManagement'] %} pidpath: {{ config['processManagement']['pidFilePath'] }} + {%- else %} + pidpath: {{ '/var/run/{{ name }}.pid' }} + {%- endif %} days: 7 - require_in: - service: {{ formula }}-service-running-{{ comp }}-{{ servicename }} - {%- if 'selinux' in d.wanted and d.wanted.selinux %} + {%- if 'selinux' in d.wanted and d.wanted.selinux %} selinux.fcontext_policy_present: - name: '/etc/logrotate.d/{{ formula }}_{{ svc }}(/.*)?' - sel_type: etc_t - require_in: - selinux: {{ formula }}-service-running-{{ comp }}-{{ servicename }}-selinux-applied - recursive: True - {%- endif %} {%- endif %} {%- if 'selinux' in d.wanted and d.wanted.selinux %} @@ -199,9 +222,11 @@ include: firewalld.present: - name: public - ports: {{ software['firewall']['ports']|json }} + {%- if grains.kernel|lower == 'linux' %} - require: - pkg: {{ formula }}-service-running-prerequisites - service: {{ formula }}-service-running-prerequisites + {%- endif %} - require_in: - service: {{ formula }}-service-running-{{ comp }}-{{ servicename }} {%- endif %} {# firewall #} @@ -219,14 +244,20 @@ include: - service: {{ formula }}-service-running-{{ comp }}-{{ servicename }} {{ formula }}-service-running-{{ comp }}-{{ servicename }}: + {%- if grains.kernel|lower == 'darwin' %} {# service.running is buggy #} + cmd.run: + - names: + - launchctl load /Library/LaunchAgents/{{ servicename }}.plist || true + - launchctl start {{ servicename }} + {%- else %} service.running: - name: {{ servicename }} - enable: True + - onlyif: systemctl list-units | grep {{ servicename }} >/dev/null 2>&1 + {%- endif %} - require: - sls: {{ sls_software_install }} - {%- if grains.kernel|lower == 'linux' %} - - onlyif: systemctl list-units | grep {{ servicename }} >/dev/null 2>&1 - {%- endif %} {# linux #} + - sls: {{ sls_config_users }} {%- if 'config' in software and software['config'] is mapping %} - watch: - file: {{ formula }}-config-file-{{ servicename }}-file-managed