capistrano-mon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/capistrano-mon.gemspec +21 -0
- data/lib/capistrano-mon.rb +180 -0
- data/lib/capistrano-mon/templates/etc/default/mon.erb +31 -0
- data/lib/capistrano-mon/templates/mon.cf.erb +34 -0
- data/lib/capistrano-mon/version.rb +5 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yamashita Yuu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# capistrano-mon
|
2
|
+
|
3
|
+
a capistrano recipe to setup [Mon](https://mon.wiki.kernel.org/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capistrano-mon'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capistrano-mon
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
* `:mon_path` - "/etc/mon"
|
22
|
+
* `:mon_lib_path` - "/var/lib/mon"
|
23
|
+
* `:mon_log_path` - "/var/log/mon"
|
24
|
+
* `:mon_dependencies` - `%w(mon)`
|
25
|
+
* `:mon_plugins_path` - "/usr/local/lib/mon"
|
26
|
+
* `:mon_plugins` - `{}`
|
27
|
+
* `:mon_configure_files` - `%w(/etc/default/mon mon.cf))`
|
28
|
+
* `:mon_service_name` - `"mon"`
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
37
|
+
|
38
|
+
## Author
|
39
|
+
|
40
|
+
- YAMASHITA Yuu (https://github.com/yyuu)
|
41
|
+
- Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano-mon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capistrano-mon"
|
8
|
+
gem.version = Capistrano::Mon::VERSION
|
9
|
+
gem.authors = ["Yamashita Yuu"]
|
10
|
+
gem.email = ["yamashita@geishatokyo.com"]
|
11
|
+
gem.description = %q{a capistrano recipe to setup mon.}
|
12
|
+
gem.summary = %q{a capistrano recipe to setup mon.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency("capistrano")
|
21
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require "capistrano-mon/version"
|
2
|
+
require "erb"
|
3
|
+
require "tempfile"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
module Capistrano
|
7
|
+
module Mon
|
8
|
+
def self.extended(configuration)
|
9
|
+
configuration.load {
|
10
|
+
namespace(:mon) {
|
11
|
+
_cset(:mon_path, "/etc/mon")
|
12
|
+
_cset(:mon_lib_path, "/var/lib/mon")
|
13
|
+
_cset(:mon_log_path, "/var/log/mon")
|
14
|
+
desc("Setup mon.")
|
15
|
+
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
16
|
+
transaction {
|
17
|
+
install
|
18
|
+
_update
|
19
|
+
}
|
20
|
+
}
|
21
|
+
after 'deploy:setup', 'mon:setup'
|
22
|
+
|
23
|
+
desc("Update mon configuration.")
|
24
|
+
task(:update, :roles => :app, :except => { :no_release => true }) {
|
25
|
+
transaction {
|
26
|
+
_update
|
27
|
+
}
|
28
|
+
}
|
29
|
+
after 'deploy:update', 'mon:update'
|
30
|
+
|
31
|
+
task(:_update, :roles => :app, :except => { :no_release => true }) {
|
32
|
+
configure
|
33
|
+
restart
|
34
|
+
}
|
35
|
+
|
36
|
+
_cset(:mon_use_plugins, true)
|
37
|
+
task(:install, :roles => :app, :except => { :no_release => true }) {
|
38
|
+
install_dependencies
|
39
|
+
install_plugins if mon_use_plugins
|
40
|
+
install_service
|
41
|
+
}
|
42
|
+
|
43
|
+
_cset(:mon_platform) {
|
44
|
+
capture((<<-EOS).gsub(/\s+/, ' ')).strip
|
45
|
+
if test -f /etc/debian_version; then
|
46
|
+
if test -f /etc/lsb-release && grep -i -q DISTRIB_ID=Ubuntu /etc/lsb-release; then
|
47
|
+
echo ubuntu;
|
48
|
+
else
|
49
|
+
echo debian;
|
50
|
+
fi;
|
51
|
+
elif test -f /etc/redhat-release; then
|
52
|
+
echo redhat;
|
53
|
+
else
|
54
|
+
echo unknown;
|
55
|
+
fi;
|
56
|
+
EOS
|
57
|
+
}
|
58
|
+
_cset(:mon_dependencies, %w(mon))
|
59
|
+
task(:install_dependencies, :roles => :app, :except => { :no_release => true }) {
|
60
|
+
unless mon_dependencies.empty?
|
61
|
+
case mon_platform
|
62
|
+
when /(debian|ubuntu)/i
|
63
|
+
run("#{sudo} apt-get install -q -y #{mon_dependencies.join(' ')}")
|
64
|
+
when /redhat/i
|
65
|
+
run("#{sudo} yum install -q -y #{mon_dependencies.join(' ')}")
|
66
|
+
else
|
67
|
+
# nop
|
68
|
+
end
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
task(:install_plugins, :roles => :app, :except => { :no_release => true }) {
|
73
|
+
update_plugins
|
74
|
+
}
|
75
|
+
|
76
|
+
def tempfile(name)
|
77
|
+
f = Tempfile.new(name)
|
78
|
+
path = f.path
|
79
|
+
f.close(true) # close and remove tempfile immediately
|
80
|
+
path
|
81
|
+
end
|
82
|
+
|
83
|
+
_cset(:mon_plugins_path, "/usr/local/lib/mon")
|
84
|
+
_cset(:mon_plugins, [])
|
85
|
+
task(:update_plugins, :roles => :app, :except => { :no_release => true }) {
|
86
|
+
srcs = mon_plugins.map { |uri, name| uri }
|
87
|
+
tmps = mon_plugins.map { |uri, name| tempfile('capistrano-mon') }
|
88
|
+
dsts = mon_plugins.map { |uri, name|
|
89
|
+
basename = File.basename(name || URI.parse(uri).path)
|
90
|
+
case basename
|
91
|
+
when /\.alert$/
|
92
|
+
File.join(mon_plugins_path, 'alert.d', basename)
|
93
|
+
when /\.monitor$/
|
94
|
+
File.join(mon_plugins_path, 'mon.d', basename)
|
95
|
+
else
|
96
|
+
abort("Unknown plugin type: #{basename}")
|
97
|
+
end
|
98
|
+
}
|
99
|
+
begin
|
100
|
+
execute = []
|
101
|
+
dirs = dsts.map { |path| File.dirname(path) }.uniq
|
102
|
+
execute << "#{sudo} mkdir -p #{dirs.join(' ')}" unless dirs.empty?
|
103
|
+
srcs.zip(tmps, dsts) do |src, tmp, dst|
|
104
|
+
execute << "wget --no-verbose -O #{tmp.dump} #{src.dump}"
|
105
|
+
execute << "( diff -u #{dst.dump} #{tmp.dump} || #{sudo} mv -f #{tmp.dump} #{dst.dump} )"
|
106
|
+
execute << "( test -x #{dst.dump} || #{sudo} chmod a+rx #{dst.dump} )"
|
107
|
+
end
|
108
|
+
run(execute.join(' && ')) unless execute.empty?
|
109
|
+
ensure
|
110
|
+
run("rm -f #{tmps.map { |t| t.dump }.join(' ')}") unless tmps.empty?
|
111
|
+
end
|
112
|
+
}
|
113
|
+
|
114
|
+
task(:install_service, :roles => :app, :except => { :no_release => true }) {
|
115
|
+
# TODO: setup (sysvinit|daemontools|upstart|runit|systemd) service of mon
|
116
|
+
}
|
117
|
+
|
118
|
+
def template(file)
|
119
|
+
if File.file?(file)
|
120
|
+
File.read(file)
|
121
|
+
elsif File.file?("#{file}.erb")
|
122
|
+
ERB.new(File.read("#{file}.erb")).result(binding)
|
123
|
+
else
|
124
|
+
abort("No such template: #{file} or #{file}.erb")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
_cset(:mon_template_path, File.join(File.dirname(__FILE__), 'capistrano-mon', 'templates'))
|
129
|
+
_cset(:mon_configure_files, %w(/etc/default/mon mon.cf))
|
130
|
+
task(:configure, :roles => :app, :except => { :no_release => true }) {
|
131
|
+
srcs = mon_configure_files.map { |file| File.join(mon_template_path, file) }
|
132
|
+
tmps = mon_configure_files.map { |file| tempfile('capistrano-mon') }
|
133
|
+
dsts = mon_configure_files.map { |file| File.expand_path(file) == file ? file : File.join(mon_path, file) }
|
134
|
+
begin
|
135
|
+
srcs.zip(tmps) do |src, tmp|
|
136
|
+
put(template(src), tmp)
|
137
|
+
end
|
138
|
+
execute = []
|
139
|
+
dirs = dsts.map { |path| File.dirname(path) }.uniq
|
140
|
+
execute << "#{sudo} mkdir -p #{dirs.map { |dir| dir.dump }.join(' ')}" unless dirs.empty?
|
141
|
+
tmps.zip(dsts) do |tmp, dst|
|
142
|
+
execute << "( diff -u #{dst.dump} #{tmp.dump} || #{sudo} mv -f #{tmp.dump} #{dst.dump} )"
|
143
|
+
end
|
144
|
+
run(execute.join(' && ')) unless execute.empty?
|
145
|
+
ensure
|
146
|
+
run("rm -f #{tmps.map { |t| t.dump }.join(' ')}") unless tmps.empty?
|
147
|
+
end
|
148
|
+
}
|
149
|
+
|
150
|
+
_cset(:mon_service_name, 'mon')
|
151
|
+
desc("Start mon daemon.")
|
152
|
+
task(:start, :roles => :app, :except => { :no_release => true }) {
|
153
|
+
run("#{sudo} service #{mon_service_name} start")
|
154
|
+
}
|
155
|
+
|
156
|
+
desc("Stop mon daemon.")
|
157
|
+
task(:stop, :roles => :app, :except => { :no_release => true }) {
|
158
|
+
run("#{sudo} service #{mon_service_name} stop")
|
159
|
+
}
|
160
|
+
|
161
|
+
desc("Restart mon daemon.")
|
162
|
+
task(:restart, :roles => :app, :except => { :no_release => true }) {
|
163
|
+
run("#{sudo} service #{mon_service_name} restart || #{sudo} service #{mon_service_name} start")
|
164
|
+
}
|
165
|
+
|
166
|
+
desc("Show mon daemon status.")
|
167
|
+
task(:status, :roles => :app, :except => { :no_release => true }) {
|
168
|
+
run("#{sudo} service #{mon_service_name} status")
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if Capistrano::Configuration.instance
|
177
|
+
Capistrano::Configuration.instance.extend(Capistrano::Mon)
|
178
|
+
end
|
179
|
+
|
180
|
+
# vim:set ft=ruby ts=2 sw=2 :
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Defaults for mon initscript
|
2
|
+
# Created by Dario Minnucci <midget@debian.org>
|
3
|
+
|
4
|
+
# Master system-wide mon switch.
|
5
|
+
# The initscript will not run if ENABLED is set
|
6
|
+
# to values other than: "yes", "true" or "1".
|
7
|
+
ENABLED="yes"
|
8
|
+
|
9
|
+
# Configuration file
|
10
|
+
CONFIGFILE=<%= File.join(mon_path, "mon.cf").dump %>
|
11
|
+
# Auth file
|
12
|
+
#AUTHFILE=<%= File.join(mon_path, "auth.cf").dump %>
|
13
|
+
|
14
|
+
# Base configuration directory
|
15
|
+
CFBASEDIR=<%= mon_path.dump %>
|
16
|
+
# Alerts directory
|
17
|
+
ALERTSDIR=<%= [ File.join(mon_plugins_path, "alert.d"), "/usr/lib/mon/alert.d" ].uniq.join(":").dump %>
|
18
|
+
# Monitors directory
|
19
|
+
MONITORSDIR=<%= [ File.join(mon_plugins_path, "mon.d"), "/usr/lib/mon/mon.d" ].uniq.join(":").dump %>
|
20
|
+
# State directory
|
21
|
+
STATEDIR=<%= mon_lib_path.dump %>
|
22
|
+
# Logging directory
|
23
|
+
LOGDIR=<%= mon_log_path.dump %>
|
24
|
+
|
25
|
+
# Deamon options
|
26
|
+
DAEMON_OPTS="-B ${CFBASEDIR} -a ${ALERTSDIR} -s ${MONITORSDIR} -D ${STATEDIR} -L ${LOGDIR} -f -c ${CONFIGFILE}"
|
27
|
+
|
28
|
+
# Bootstrap script
|
29
|
+
<%= fetch(:mon_bootstrap_script, '').strip %>
|
30
|
+
|
31
|
+
# vim:set ft=eruby :
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Example mon.cf file
|
3
|
+
#
|
4
|
+
# Author: Dario Minnucci <midget@debian.org>
|
5
|
+
# Date: Mon, 07 Sep 2009 13:57:38 +0200
|
6
|
+
#
|
7
|
+
|
8
|
+
#
|
9
|
+
# Global options
|
10
|
+
#
|
11
|
+
alertdir = <%= [ File.join(mon_plugins_path, "alert.d"), "/usr/lib/mon/alert.d" ].uniq.join(":") %>
|
12
|
+
mondir = <%= [ File.join(mon_plugins_path, "mon.d"), "/usr/lib/mon/mon.d" ].uniq.join(":") %>
|
13
|
+
logdir = <%= mon_log_path %>
|
14
|
+
historicfile = <%= fetch(:mon_historicfile, File.join(mon_log_path, "history.log")) %>
|
15
|
+
maxprocs = <%= fetch(:mon_maxprocs, 20) %>
|
16
|
+
histlength = <%= fetch(:mon_histlength, 100) %>
|
17
|
+
randstart = <%= fetch(:mon_randstart, "60s") %>
|
18
|
+
dtlogging = <%= fetch(:mon_dtlogging, "yes") %>
|
19
|
+
dtlogfile = <%= fetch(:mon_dtlogfile, "dtlog") %>
|
20
|
+
|
21
|
+
#
|
22
|
+
# Define groups of hosts to monitor
|
23
|
+
#
|
24
|
+
hostgroup localhost <%= fetch(:mon_hostgroup, %w(localhost)).join(' ') %>
|
25
|
+
|
26
|
+
#
|
27
|
+
# Define watches
|
28
|
+
#
|
29
|
+
watch localhost<% fetch(:mon_services, {}).each { |service_name, service_defs| %>
|
30
|
+
service <%= service_name %><% service_defs.each { |monitor_name, monitor_def| %><% if Array === monitor_def %><% monitor_def.each { |d| %>
|
31
|
+
<%= monitor_name %> <%= d %><% } %><% else %>
|
32
|
+
<%= monitor_name %> <%= monitor_def %><% end %><% } %><% } %>
|
33
|
+
|
34
|
+
# vim:set ft=eruby :
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-mon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yamashita Yuu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capistrano
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: a capistrano recipe to setup mon.
|
31
|
+
email:
|
32
|
+
- yamashita@geishatokyo.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- capistrano-mon.gemspec
|
43
|
+
- lib/capistrano-mon.rb
|
44
|
+
- lib/capistrano-mon/templates/etc/default/mon.erb
|
45
|
+
- lib/capistrano-mon/templates/mon.cf.erb
|
46
|
+
- lib/capistrano-mon/version.rb
|
47
|
+
homepage: ''
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.23
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: a capistrano recipe to setup mon.
|
71
|
+
test_files: []
|