From cb34ab55f7eb86da9f2c5d6a77af513aaadeee5d Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Thu, 26 Jan 2017 16:09:23 -0300 Subject: [PATCH 1/9] Remove extra white lines --- monit/files/modules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monit/files/modules b/monit/files/modules index ea0c0cd..e86d2b5 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -48,8 +48,8 @@ {%- if 'pidfile' in kind_v or 'path' in kind_v %} check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {%- endif -%} - {% endfor %} - {% endfor %} + {%- endfor -%} + {%- endfor -%} {%- for kind, kind_v in mod_name_v.iteritems() -%} {%- for element, element_v in kind_v.iteritems() -%} From 7fd2cf9e1f996f6533deaca2f5368f17c68e1c95 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Thu, 26 Jan 2017 17:16:29 -0300 Subject: [PATCH 2/9] Improve readability of modules file --- monit/files/modules | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/monit/files/modules b/monit/files/modules index e86d2b5..c87474f 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -46,7 +46,7 @@ {#- if it has 'pidfile' or 'path' then this is the 'check' line #} {%- if 'pidfile' in kind_v or 'path' in kind_v %} -check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} +check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {{ element|replace('\\n', '\n') }} {{ element_v|replace('\\n', '\n') }} {%- endif -%} {%- endfor -%} {%- endfor -%} @@ -58,9 +58,9 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {#- filter 'start' to add 'program =' into this line #} {%- if 'start' in element or 'stop' in element %} - {{ element }} program = "{{ element_v }}" + {{ element|replace('\\n', '\n') }} program = "{{ element_v|replace('\\n', '\n') }}" {%- else %} - {{ element }} {{ element_v }} + {{ element|replace('\\n', '\n') }} {{ element_v|replace('\\n', '\n') }} {%- endif %} {%- endif -%} @@ -69,7 +69,9 @@ check {{ mod_name }} {{ name }} with {{ element }} {{ element_v }} {#- 'action' is appended to the 'if failed' line #} {%- if 'action' not in element %} - if {{ element }} {{ element_v }} then {{ kind_v.action }} + if {{ element|replace('\\n', '\n') }} + {{ element_v|replace('\\n', '\n')| indent(4) }} + then {{ kind_v.action|replace('\\n', '\n') }} {%- endif %} {%- endif %} {%- endfor %} From 8627edc9a79a38ad00ef1820a715450feb10269c Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Thu, 26 Jan 2017 17:20:10 -0300 Subject: [PATCH 3/9] Fix Vagrantfile --- Vagrantfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index efe6e7a..3ebbaae 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,20 +5,23 @@ test -d /srv/pillar || mkdir /srv/pillar test -f /tmp/travis/top.sls && cp /{tmp/travis,srv/salt}/top.sls cp {/tmp/travis,/srv/salt}/top.sls cp /tmp/travis/top_pillar.sls /srv/pillar/top.sls -cp /srv/{salt/pillar.example,pillar/monit.sls} +ln -s /srv/salt/pillar.example /srv/pillar/monit.sls SCRIPT Vagrant.configure(2) do |config| - config.vm.define "xenial" do |xenial| - xenial.vm.box = "xenial" + config.vm.provider 'virtualbox' do |v| + v.linked_clone = true if Vagrant::VERSION =~ /^1.8/ + end + + config.vm.define "monit" do |monit| + monit.vm.box = "ubuntu/xenial64" - xenial.vm.synced_folder ".", "/vagrant", disabled: true - xenial.vm.synced_folder ".", "/srv/salt" - xenial.vm.synced_folder ".travis", "/tmp/travis" + monit.vm.synced_folder ".", "/vagrant", disabled: true + monit.vm.synced_folder ".", "/srv/salt" + monit.vm.synced_folder ".travis", "/tmp/travis" - xenial.vm.provision "shell", inline: $script - xenial.vm.provision :salt do |salt| - salt.bootstrap_script = "../salt-bootstrap/bootstrap-salt.sh" + monit.vm.provision "shell", inline: $script + monit.vm.provision :salt do |salt| salt.masterless = true salt.minion_config = ".travis/minion" salt.run_highstate = false From 53f7121f5ff8052f954de4bb445914cd96ffe9c6 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Thu, 26 Jan 2017 17:30:32 -0300 Subject: [PATCH 4/9] Fix monit service watch to config files --- monit/config.sls | 6 ++++++ monit/service.sls | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 0d6b6d0..9799225 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -7,6 +7,8 @@ - template: jinja - makedirs: True - mode: '0700' + - watch_in: + - service: {{ monit.service.name }} - context: config_includes: {{ monit.config_includes }} http_access: {{ monit.http_access }} @@ -18,6 +20,8 @@ - source: salt://monit/files/mail - template: jinja - makedirs: True + - watch_in: + - service: {{ monit.service.name }} - context: mail_alert: {{ monit.mail_alert }} {% endif %} @@ -28,5 +32,7 @@ file.managed: - source: salt://monit/files/modules - template: jinja + - watch_in: + - service: {{ monit.service.name }} - context: modules: {{ monit.modules }} diff --git a/monit/service.sls b/monit/service.sls index 0737955..f280f73 100644 --- a/monit/service.sls +++ b/monit/service.sls @@ -7,7 +7,3 @@ service.running: - enable: True - restart: True - - watch: - - file: {{ monit.config }} - - file: {{ monit.config_includes }}/mail - - file: {{ monit.config_includes }}/modules From ad600115d4cd42f652c335217d33e6f56883c30c Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Thu, 26 Jan 2017 18:29:39 -0300 Subject: [PATCH 5/9] Create parent folders even when mail is not set --- monit/config.sls | 1 + 1 file changed, 1 insertion(+) diff --git a/monit/config.sls b/monit/config.sls index 9799225..486e52c 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -32,6 +32,7 @@ file.managed: - source: salt://monit/files/modules - template: jinja + - makedirs: True - watch_in: - service: {{ monit.service.name }} - context: From c61a754e59f54479af7304d8def4c3c888c741f1 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Fri, 27 Jan 2017 15:11:28 -0300 Subject: [PATCH 6/9] Add support for FreeBSD --- monit/map.jinja | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monit/map.jinja b/monit/map.jinja index 85c18b3..f963887 100644 --- a/monit/map.jinja +++ b/monit/map.jinja @@ -11,6 +11,10 @@ that differ from whats in defaults.yaml {% set os_family_map = salt['grains.filter_by']({ 'Debian': {}, 'Kali': {}, + 'FreeBSD': { + 'config': '/usr/local/etc/monitrc', + 'config_includes': '/usr/local/etc/monit/conf.d' + }, 'Gentoo': { 'pkg': 'app-admin/monit', 'config': '/etc/monitrc', From 3cadbf1d04b982704017b6b2b8ba6f6f99d3b0d1 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Fri, 27 Jan 2017 15:12:48 -0300 Subject: [PATCH 7/9] Allow to set other settings and import map inside templates --- monit/config.sls | 7 ------- monit/defaults.yaml | 2 ++ monit/files/mail | 17 +++++++++-------- monit/files/modules | 7 +++++-- monit/files/monitrc | 14 ++++++++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 486e52c..4590b19 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -9,9 +9,6 @@ - mode: '0700' - watch_in: - service: {{ monit.service.name }} - - context: - config_includes: {{ monit.config_includes }} - http_access: {{ monit.http_access }} {#- This is the mail alert configuration #} {% if monit.mail_alert is defined %} @@ -22,8 +19,6 @@ - makedirs: True - watch_in: - service: {{ monit.service.name }} - - context: - mail_alert: {{ monit.mail_alert }} {% endif %} {#- This is populated by modules configuration @@ -35,5 +30,3 @@ - makedirs: True - watch_in: - service: {{ monit.service.name }} - - context: - modules: {{ monit.modules }} diff --git a/monit/defaults.yaml b/monit/defaults.yaml index 85172c5..a7b4f6d 100644 --- a/monit/defaults.yaml +++ b/monit/defaults.yaml @@ -6,6 +6,8 @@ monit: config_includes: '/etc/monit/conf.d' service: name: monit + daemon_interval: 10 + logfile: syslog http_access: port: 2812 bind: 127.0.0.1 diff --git a/monit/files/mail b/monit/files/mail index ae53046..77ecd02 100644 --- a/monit/files/mail +++ b/monit/files/mail @@ -1,15 +1,16 @@ -{%- for email in mail_alert.users -%} -set alert {{email}} ON { invalid, timeout, resource, size, timestamp } +{%- from "monit/map.jinja" import monit with context -%} +{%- for email in monit.mail_alert.users -%} +set alert {{ email }} ON { invalid, timeout, resource, size, timestamp } {% endfor %} -{%- if mail_alert.account.email -%} -set mail-format { from: {{mail_alert.account.email}} } +{%- if monit.mail_alert.account.email -%} +set mail-format { from: {{ monit.mail_alert.account.email }} } {%- endif -%} -{%- if mail_alert.account.server and mail_alert.account.port %} -set mailserver {{mail_alert.account.server}} port {{mail_alert.account.port}} - {%- if mail_alert.account.email and 'password' in mail_alert.account and mail_alert.account.password %} - username "{{mail_alert.account.email}}" password "{{mail_alert.account.password}}" +{%- if monit.mail_alert.account.server and monit.mail_alert.account.port %} +set mailserver {{ monit.mail_alert.account.server }} port {{ monit.mail_alert.account.port }} + {%- if monit.mail_alert.account.email and 'password' in monit.mail_alert.account and monit.mail_alert.account.password %} + username "{{ monit.mail_alert.account.email }}" password "{{ monit.mail_alert.account.password }}" using tlsv1 {%- endif %} with timeout 30 seconds diff --git a/monit/files/modules b/monit/files/modules index c87474f..c6fefe5 100644 --- a/monit/files/modules +++ b/monit/files/modules @@ -1,3 +1,4 @@ +{%- from "monit/map.jinja" import monit with context -%} # -*- coding: utf-8 -*- # vim: ft=jinja @@ -22,7 +23,7 @@ -#} {#- module = nginx_init, module_v = {'process': {'with': {'pidfile':... #} -{%- for module, module_v in modules.iteritems() -%} +{%- for module, module_v in monit.modules.iteritems() -%} {#- mod_name = process mod_name_v = {'custom': {'name': 'nginx'}, 'with': {'pidfile':... #} @@ -46,7 +47,7 @@ {#- if it has 'pidfile' or 'path' then this is the 'check' line #} {%- if 'pidfile' in kind_v or 'path' in kind_v %} -check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {{ element|replace('\\n', '\n') }} {{ element_v|replace('\\n', '\n') }} +check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with {{ element|replace('\\n', '\n') }} "{{ element_v|replace('\\n', '\n') }}" {%- endif -%} {%- endfor -%} {%- endfor -%} @@ -70,7 +71,9 @@ check {{ mod_name|replace('\\n', '\n') }} {{ name|replace('\\n', '\n') }} with { {#- 'action' is appended to the 'if failed' line #} {%- if 'action' not in element %} if {{ element|replace('\\n', '\n') }} + {%- if element_v is not none %} {{ element_v|replace('\\n', '\n')| indent(4) }} + {%- endif %} then {{ kind_v.action|replace('\\n', '\n') }} {%- endif %} {%- endif %} diff --git a/monit/files/monitrc b/monit/files/monitrc index 0440002..29b2b12 100644 --- a/monit/files/monitrc +++ b/monit/files/monitrc @@ -1,12 +1,14 @@ -set daemon 10 +{%- from "monit/map.jinja" import monit with context -%} +set daemon {{ monit.daemon_interval }} +set logfile {{ monit.logfile }} -set httpd port {{ http_access.port }} and - use address {{ http_access.bind }} -{%- for host in http_access.allowed.hosts %} +set httpd port {{ monit.http_access.port }} and + use address {{ monit.http_access.bind }} +{%- for host in monit.http_access.allowed.hosts %} allow {{ host }} {%- endfor %} -{%- for userdata in http_access.allowed.users %} +{%- for userdata in monit.http_access.allowed.users %} allow {{ userdata[0] }}:{{ userdata[1] }} {%- endfor %} -include {{ config_includes }}/* +include {{ monit.config_includes }}/* From 0ba3dcde04521ecd1d8f1065639e462b10e3d500 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Wed, 1 Feb 2017 14:55:59 -0300 Subject: [PATCH 8/9] Allow to configure service status --- monit/config.sls | 6 ++++++ monit/defaults.yaml | 2 ++ monit/service.sls | 4 ++-- pillar.example | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/monit/config.sls b/monit/config.sls index 4590b19..1da97c7 100644 --- a/monit/config.sls +++ b/monit/config.sls @@ -7,8 +7,10 @@ - template: jinja - makedirs: True - mode: '0700' +{%- if monit.service.status == 'running' %} - watch_in: - service: {{ monit.service.name }} +{%- endif %} {#- This is the mail alert configuration #} {% if monit.mail_alert is defined %} @@ -17,8 +19,10 @@ - source: salt://monit/files/mail - template: jinja - makedirs: True +{%- if monit.service.status == 'running' %} - watch_in: - service: {{ monit.service.name }} +{%- endif %} {% endif %} {#- This is populated by modules configuration @@ -28,5 +32,7 @@ - source: salt://monit/files/modules - template: jinja - makedirs: True +{%- if monit.service.status == 'running' %} - watch_in: - service: {{ monit.service.name }} +{%- endif %} \ No newline at end of file diff --git a/monit/defaults.yaml b/monit/defaults.yaml index a7b4f6d..fb1e0fe 100644 --- a/monit/defaults.yaml +++ b/monit/defaults.yaml @@ -6,6 +6,8 @@ monit: config_includes: '/etc/monit/conf.d' service: name: monit + enable: True + status: running daemon_interval: 10 logfile: syslog http_access: diff --git a/monit/service.sls b/monit/service.sls index f280f73..e8e5cb1 100644 --- a/monit/service.sls +++ b/monit/service.sls @@ -4,6 +4,6 @@ {% from "monit/map.jinja" import monit with context %} {{ monit.service.name }}: - service.running: - - enable: True + service.{{ monit.service.status }}: + - enable: {{ monit.service.enable }} - restart: True diff --git a/pillar.example b/pillar.example index 33c51b4..f673a98 100644 --- a/pillar.example +++ b/pillar.example @@ -1,4 +1,7 @@ monit: + service: + enable: True + status: running mail_alert: account: server: smtp.gmail.com From ed742bc28aa8eadd3c9301192d6be687cb708092 Mon Sep 17 00:00:00 2001 From: Andres Montalban Date: Wed, 22 Feb 2017 09:29:29 -0300 Subject: [PATCH 9/9] Add the "start delay" option to delay the start of Monit --- monit/files/monitrc | 3 +++ pillar.example | 2 ++ 2 files changed, 5 insertions(+) diff --git a/monit/files/monitrc b/monit/files/monitrc index 29b2b12..4e07508 100644 --- a/monit/files/monitrc +++ b/monit/files/monitrc @@ -1,5 +1,8 @@ {%- from "monit/map.jinja" import monit with context -%} set daemon {{ monit.daemon_interval }} +{%- if monit.daemon_start_delay %} + with start delay {{ monit.daemon_start_delay }} +{%- endif %} set logfile {{ monit.logfile }} set httpd port {{ monit.http_access.port }} and diff --git a/pillar.example b/pillar.example index f673a98..eba9702 100644 --- a/pillar.example +++ b/pillar.example @@ -2,6 +2,8 @@ monit: service: enable: True status: running + daemon_interval: 30 + daemon_start_delay: 60 mail_alert: account: server: smtp.gmail.com