Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# install monit
package 'monit'

use_systemd = node['platform_version'].to_f >= 15.10

# update the main monit configuration file
template "/etc/monit/monitrc" do
owner "root"
Expand All @@ -19,15 +21,6 @@
# /etc/init.d/monit stop
end

# Use upstart to manage monit
template '/etc/init/monit.conf' do
owner "root"
group "root"
mode "0644"
source "monit-upstart.conf.erb"
notifies :run, "execute[restart-monit]", :immediately
end

# allow monit to startup
template '/etc/default/monit' do
owner "root"
Expand All @@ -37,8 +30,38 @@
notifies :run, "execute[restart-monit]", :immediately
end

execute "restart-monit" do
command "initctl reload-configuration"
command "monit reload"
action :nothing
if use_systemd
# Use upstart to manage monit
template '/lib/systemd/system/monit.service' do
owner "root"
group "root"
mode "0644"
source "monit-systemd.conf.erb"
notifies :run, "execute[enable-monit]", :immediately
notifies :run, "execute[restart-monit]", :immediately
end
execute "enable-monit" do
command "systemctl enable monit.service"
action :nothing
end
execute "restart-monit" do
command "systemctl reload monit.service"
action :nothing
end
else
# Use upstart to manage monit
template '/etc/init/monit.conf' do
owner "root"
group "root"
mode "0644"
source "monit-upstart.conf.erb"
notifies :run, "execute[restart-monit]", :immediately
end

execute "restart-monit" do
command "initctl reload-configuration"
command "monit reload"
action :nothing
end

end
31 changes: 31 additions & 0 deletions templates/default/monit-systemd.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is systemd template for monit service. To
# register monit with systemd, place the monit.service file
# to the /lib/systemd/system/ directory and then start it
# using systemctl (see bellow).
#
# Enable monit to start on boot:
# systemctl enable monit.service
#
# Start monit immediately:
# systemctl start monit.service
#
# Stop monit:
# systemctl stop monit.service
#
# Status:
# systemctl status monit.service

[Unit]
Description=Pro-active monitoring utility for unix systems
After=network.target

[Service]
Type=simple
KillMode=process
ExecStart=/usr/bin/monit -I
ExecStop=/usr/bin/monit quit
ExecReload=/usr/bin/monit reload
Restart = on-abnormal

[Install]
WantedBy=multi-user.target