luban-monit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/luban-monit.rb +0 -0
- data/lib/luban/deployment/packages/monit.rb +8 -0
- data/lib/luban/deployment/packages/monit/base.rb +25 -0
- data/lib/luban/deployment/packages/monit/configurator.rb +43 -0
- data/lib/luban/deployment/packages/monit/controller.rb +42 -0
- data/lib/luban/deployment/packages/monit/installer.rb +32 -0
- data/lib/luban/deployment/packages/monit/templates/alert.monitrc +32 -0
- data/lib/luban/deployment/packages/monit/templates/httpd.monitrc +6 -0
- data/lib/luban/deployment/packages/monit/templates/monit.logrotate.erb +18 -0
- data/lib/luban/deployment/packages/monit/templates/monitrc.erb +14 -0
- data/lib/luban/deployment/packages/monit/templates/system.monitrc +11 -0
- data/lib/luban/deployment/packages/monit/version.rb +9 -0
- data/lib/luban/monit.rb +1 -0
- data/luban-monit.gemspec +28 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab8f23b75485141f8ab64f059b53193d3bdf79f4
|
4
|
+
data.tar.gz: 4d7d27fc456235898447137e31947a732108df44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8407d26e012fc1c8106208f4bf7f56075e7c05b2e985039b997c7acc77b2f3f6920dca33195aecab504edf46063fc083a421f32a2c475fb0f9b25e94720d6a3e
|
7
|
+
data.tar.gz: 3a38ee6b2a12cc0958e7344e420d09dc1e057460db822c885d42b6fdb343a721667bcabdcfcd6f20d904f5c3ff79fb6103f3a560be0a959dcfffb8ae8958bb84
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Chi Man Lei
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Luban::Monit
|
2
|
+
|
3
|
+
Luban deployment package to manage Monit installation, deployment and control
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'luban-monit'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install luban-monit
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/luban-monit.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "luban/monit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/luban-monit.rb
ADDED
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Monit < Luban::Deployment::Service::Base
|
5
|
+
apply_to :all do
|
6
|
+
before_install do
|
7
|
+
depend_on 'openssl', version: '1.0.2g'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_templates_path
|
12
|
+
@default_templates_path ||= Pathname.new(File.join(File.dirname(__FILE__), 'templates')).realpath
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def setup_control_tasks
|
18
|
+
super
|
19
|
+
undef_task :monitor
|
20
|
+
undef_task :unmonitor
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Monit
|
5
|
+
class Configurator < Luban::Deployment::Service::Configurator
|
6
|
+
module Paths
|
7
|
+
def control_file_name
|
8
|
+
@control_file_name ||= 'monitrc'
|
9
|
+
end
|
10
|
+
|
11
|
+
def state_file_path
|
12
|
+
@state_file_path ||= pids_path.join(state_file_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def state_file_name
|
16
|
+
@state_file_name ||= "#{service_name}.state"
|
17
|
+
end
|
18
|
+
|
19
|
+
def id_file_path
|
20
|
+
@id_file_path ||= pids_path.join(id_file_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def id_file_name
|
24
|
+
@id_file_name ||= "#{service_name}.id"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
include Paths
|
29
|
+
|
30
|
+
def services_path
|
31
|
+
@services_path ||= env_path.join("#{stage}.*").join("*").join("shared").
|
32
|
+
join('profile').join('*')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_profile
|
36
|
+
super
|
37
|
+
chmod('700', stage_profile_path.join('monitrc'))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Monit
|
5
|
+
class Controller < Luban::Deployment::Service::Controller
|
6
|
+
include Configurator::Paths
|
7
|
+
|
8
|
+
default_executable 'monit'
|
9
|
+
|
10
|
+
def monit_command
|
11
|
+
@monit_command ||= "#{monit_executable} -c #{control_file_path}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_stopped?
|
15
|
+
check_process! =~ /the monit daemon is not running$/
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_started?
|
19
|
+
check_process! =~ /^The Monit daemon #{package_major_version} uptime:/
|
20
|
+
end
|
21
|
+
|
22
|
+
undef_method :monitor_process
|
23
|
+
undef_method :unmonitor_process
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def start_process!
|
28
|
+
capture("#{monit_command} 2>&1")
|
29
|
+
end
|
30
|
+
|
31
|
+
def stop_process!
|
32
|
+
capture("#{monit_command} quit 2>&1")
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_process!
|
36
|
+
capture("#{monit_command} status 2>&1")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Packages
|
4
|
+
class Monit
|
5
|
+
class Installer < Luban::Deployment::Service::Installer
|
6
|
+
include Configurator::Paths
|
7
|
+
|
8
|
+
default_executable 'monit'
|
9
|
+
|
10
|
+
def source_repo
|
11
|
+
@source_repo ||= "http://mmonit.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
def source_url_root
|
15
|
+
@source_url_root ||= "monit/dist"
|
16
|
+
end
|
17
|
+
|
18
|
+
def installed?
|
19
|
+
return false unless file?(monit_executable)
|
20
|
+
pattern = "Monit version #{package_major_version}"
|
21
|
+
match?("#{monit_executable} -V", pattern)
|
22
|
+
end
|
23
|
+
|
24
|
+
def with_openssl_dir(dir)
|
25
|
+
@configure_opts << "--with-ssl-incl-dir=#{dir.join('include')}"
|
26
|
+
@configure_opts << "--with-ssl-lib-dir=#{dir.join('lib')}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# This section configures Monit's alert messages
|
2
|
+
|
3
|
+
# Configure mail server for alert delivery
|
4
|
+
# -------------------------------------------
|
5
|
+
# set mailserver smtp.company.com port 25
|
6
|
+
# username "username"
|
7
|
+
# password "password"
|
8
|
+
# using SSL with timeout 5 seconds
|
9
|
+
|
10
|
+
# Configure alert receipient(s)
|
11
|
+
# -------------------------------------------
|
12
|
+
# set alert recipient1@company.com with reminder on 20 cycles
|
13
|
+
# set alert recipient2@company.com with reminder on 20 cycles
|
14
|
+
|
15
|
+
# Configure alert message format
|
16
|
+
# -------------------------------------------
|
17
|
+
# set mail-format {
|
18
|
+
# from: Monit Support <monit@$HOST>
|
19
|
+
# subject: [$ACTION][$SERVICE] $DESCRIPTION at $DATE [$HOST]
|
20
|
+
# message: Alert Details:
|
21
|
+
#
|
22
|
+
# Date: $DATE
|
23
|
+
# Action: $ACTION
|
24
|
+
# Event: $EVENT
|
25
|
+
# Host: $HOST
|
26
|
+
# Service: $SERVICE
|
27
|
+
# Description: $DESCRIPTION
|
28
|
+
#
|
29
|
+
# Please refer to Monit Service Manager for more details:
|
30
|
+
#
|
31
|
+
# http://$HOST:2812/
|
32
|
+
# }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Monit logrotate configuration
|
2
|
+
|
3
|
+
# Environment: <%= env_name = "#{stage}.#{project}/#{application}" %>
|
4
|
+
# Revision: <%= revision %>
|
5
|
+
# Created at <%= Time.now().strftime("%d/%m/%Y %H:%M:%S") %>
|
6
|
+
|
7
|
+
<%= log_file_path %> {
|
8
|
+
daily
|
9
|
+
missingok
|
10
|
+
rotate 14
|
11
|
+
compress
|
12
|
+
dateext
|
13
|
+
notifempty
|
14
|
+
sharedscripts
|
15
|
+
postrotate
|
16
|
+
[ ! -f <%= pid_file_path %> ] || kill -HUP $(cat <%= pid_file_path %>) 2>/dev/null || true
|
17
|
+
endscript
|
18
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Monit control file
|
2
|
+
|
3
|
+
# Environment: <%= env_name = "#{stage}.#{project}/#{application}" %>
|
4
|
+
# Revision: <%= revision %>
|
5
|
+
# Created at <%= Time.now().strftime("%d/%m/%Y %H:%M:%S") %>
|
6
|
+
|
7
|
+
set daemon 15 # Poll cycle length in seconds
|
8
|
+
|
9
|
+
set pidfile <%= pid_file_path %>
|
10
|
+
set statefile <%= state_file_path %>
|
11
|
+
set idfile <%= id_file_path %>
|
12
|
+
set logfile <%= log_file_path %>
|
13
|
+
|
14
|
+
include <%= services_path.join('*.monitrc') %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This section configures Monit's system resource monitoring
|
2
|
+
|
3
|
+
# check system $HOST
|
4
|
+
# if loadavg(5min) > 4 for 40 cycles then alert
|
5
|
+
# if memory > 80% for 40 cycles then alert
|
6
|
+
# if cpu(user) > 80% for 40 cycles then alert
|
7
|
+
# if cpu(system) > 40% for 40 cycles then alert
|
8
|
+
# if cpu(wait) > 20% for 40 cycles then alert
|
9
|
+
|
10
|
+
# check filesystem optfs with path /opt
|
11
|
+
# if space usage > 90% for 60 cycles then alert
|
data/lib/luban/monit.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "deployment/packages/monit"
|
data/luban-monit.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'luban/deployment/packages/monit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "luban-monit"
|
8
|
+
spec.version = Luban::Deployment::Packages::Monit::VERSION
|
9
|
+
spec.authors = ["Rubyist Chi"]
|
10
|
+
spec.email = ["rubyist.chi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Monit support for Luban}
|
13
|
+
spec.description = %q{Luban::Monit is a Luban package to manage Monit installation, deployment and control}
|
14
|
+
spec.homepage = "https://github.com/lubanrb/monit"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = ">= 2.1.0"
|
23
|
+
spec.add_dependency 'luban'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luban-monit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rubyist Chi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: luban
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: Luban::Monit is a Luban package to manage Monit installation, deployment
|
70
|
+
and control
|
71
|
+
email:
|
72
|
+
- rubyist.chi@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/luban-monit.rb
|
86
|
+
- lib/luban/deployment/packages/monit.rb
|
87
|
+
- lib/luban/deployment/packages/monit/base.rb
|
88
|
+
- lib/luban/deployment/packages/monit/configurator.rb
|
89
|
+
- lib/luban/deployment/packages/monit/controller.rb
|
90
|
+
- lib/luban/deployment/packages/monit/installer.rb
|
91
|
+
- lib/luban/deployment/packages/monit/templates/alert.monitrc
|
92
|
+
- lib/luban/deployment/packages/monit/templates/httpd.monitrc
|
93
|
+
- lib/luban/deployment/packages/monit/templates/monit.logrotate.erb
|
94
|
+
- lib/luban/deployment/packages/monit/templates/monitrc.erb
|
95
|
+
- lib/luban/deployment/packages/monit/templates/system.monitrc
|
96
|
+
- lib/luban/deployment/packages/monit/version.rb
|
97
|
+
- lib/luban/monit.rb
|
98
|
+
- luban-monit.gemspec
|
99
|
+
homepage: https://github.com/lubanrb/monit
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 2.1.0
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Monit support for Luban
|
123
|
+
test_files: []
|