thinking-sphinx-monit 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 +19 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/lib/generators/thinking_sphinx_monit/template_generator.rb +16 -0
- data/lib/thinking-sphinx-monit.rb +1 -0
- data/lib/thinking_sphinx_monit/capistrano.rb +1 -0
- data/lib/thinking_sphinx_monit/railtie.rb +7 -0
- data/lib/thinking_sphinx_monit/tasks/capistrano.rb +79 -0
- data/lib/thinking_sphinx_monit/tasks/monit.rb +49 -0
- data/lib/thinking_sphinx_monit/templates/ts_monit.conf.erb +7 -0
- data/lib/thinking_sphinx_monit/version.rb +3 -0
- data/thinking-sphinx-monit.gemspec +21 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 884effdadddb405bce9d24ece788efc47531302a
|
4
|
+
data.tar.gz: d41ed4279a601cc0b8af51fcf13b5d661ea7b8e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed6641f639ed18da81a9ec034bad3b3812794d2111c80abfe0ca2a8f396955a2a2599c37d62a9fa0ff775cef49eb64d67a8339f3cd13c1e5c91df96ce0e62616
|
7
|
+
data.tar.gz: 6fbdaf8417067c0348b6f2fe789671aab2dce9fa6b344345fa5d90db372818f14d09e52534930dea792fc311576a989ffc2346d977e618af1f5c14ba5bf24e42
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Michał Mrozek
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# ThinkingSphinxMonit
|
2
|
+
|
3
|
+
Monit integration with Thinking Sphinx and CapistranoV3
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'thinking-sphinx-monit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
Add to your capfile following line:
|
17
|
+
```ruby
|
18
|
+
# Capfile
|
19
|
+
require 'thinking_sphinx_monit/capistrano'
|
20
|
+
```
|
21
|
+
It's also needed to specify thinking sphinx hooks in your deploy.rb, for example like this:
|
22
|
+
```ruby
|
23
|
+
before 'deploy:updating', 'thinking_sphinx:stop'
|
24
|
+
after 'deploy:published', 'thinking_sphinx:start'
|
25
|
+
after 'thinking_sphinx:start', 'thinking_sphinx:index'
|
26
|
+
```
|
27
|
+
|
28
|
+
That's because monit is started and stopped before and after thinking_sphinx stop/start:
|
29
|
+
```ruby
|
30
|
+
before 'thinking_sphinx:stop', 'thinking_sphinx_monit:unmonitor'
|
31
|
+
after 'thinking_sphinx:start', 'thinking_sphinx_monit:monitor'
|
32
|
+
```
|
33
|
+
|
34
|
+
Of course you can do everything manually, but remember to do ```cap <stage> deploy``` before any following tasks (just once per stage):
|
35
|
+
```ruby
|
36
|
+
cap thinking_sphinx_monit:config # Generates Thinking Sphinx monit-service
|
37
|
+
cap thinking_sphinx_monit:monitor # Monitor Thinking Sphinx monit-service
|
38
|
+
cap thinking_sphinx_monit:restart # Restart Thinking Sphinx monit-service
|
39
|
+
cap thinking_sphinx_monit:start # Start Thinking Sphinx monit-service
|
40
|
+
cap thinking_sphinx_monit:stop # Stop Thinking Sphinx monit-service
|
41
|
+
cap thinking_sphinx_monit:unmonitor # Unmonitor Thinking Sphinx monit-service
|
42
|
+
```
|
43
|
+
|
44
|
+
## Defaults
|
45
|
+
```ruby
|
46
|
+
set :thinking_sphinx_monit_conf_dir, -> { "/etc/monit/conf.d/#{ts_monit_service_name}.conf" }
|
47
|
+
set :thinking_sphinx_use_sudo, true
|
48
|
+
set :thinking_sphinx_monit_bin, '/usr/bin/monit'
|
49
|
+
```
|
50
|
+
|
51
|
+
## Dependencies
|
52
|
+
- 'capistrano', '~> 3.0', '>= 3.0.0'
|
53
|
+
- 'thinking-sphinx', '~> 3.3.0'
|
54
|
+
|
55
|
+
## Customizing Monit template
|
56
|
+
|
57
|
+
If you need change config for Monit, you can:
|
58
|
+
|
59
|
+
```
|
60
|
+
bundle exec rails generate thinking_sphinx_monit:template
|
61
|
+
```
|
62
|
+
and edit template in your config/deploy/templates folder.
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
Feel free to contribute.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ThinkingSphinxMonit
|
2
|
+
class TemplateGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
namespace 'thinking_sphinx_monit:template'
|
5
|
+
desc 'Create local monitrc.erb, and erb files for monitored processes for customization'
|
6
|
+
source_root File.expand_path('../../../thinking_sphinx_monit/templates', __FILE__)
|
7
|
+
argument :templates_path, type: :string,
|
8
|
+
default: 'config/deploy/templates',
|
9
|
+
banner: 'path to templates'
|
10
|
+
|
11
|
+
def copy_template
|
12
|
+
copy_file 'ts_monit.conf.erb', "#{templates_path}/ts_monit.erb"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'thinking_sphinx_monit/railtie' if defined?(Rails::Railtie)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../tasks/capistrano.rb', __FILE__)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :thinking_sphinx_monit_conf_dir, -> { "/etc/monit/conf.d/#{ts_monit_service_name}.conf" }
|
4
|
+
set :thinking_sphinx_use_sudo, true
|
5
|
+
set :thinking_sphinx_monit_bin, '/usr/bin/monit'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :thinking_sphinx_monit do
|
10
|
+
desc 'Generates Thinking Sphinx monit-service'
|
11
|
+
task :config do
|
12
|
+
on roles(fetch(:thinking_sphinx_roles)) do |role|
|
13
|
+
within current_path do
|
14
|
+
with rails_env: fetch(:thinking_sphinx_rails_env) do
|
15
|
+
execute :rake, "ts_monit:config[#{role.user},#{fetch(:thinking_sphinx_use_sudo)},#{fetch(:tmp_dir)},#{fetch(:thinking_sphinx_monit_conf_dir)},#{fetch(:thinking_sphinx_monit_bin)},#{ts_monit_service_name},#{fetch(:rails_env)}]"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Monitor Thinking Sphinx monit-service'
|
22
|
+
task :monitor do
|
23
|
+
on roles(fetch(:thinking_sphinx_roles)) do
|
24
|
+
begin
|
25
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} monitor #{ts_monit_service_name}"
|
26
|
+
rescue
|
27
|
+
invoke 'thinking_sphinx_monit:config'
|
28
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} monitor #{ts_monit_service_name}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Unmonitor Thinking Sphinx monit-service'
|
34
|
+
task :unmonitor do
|
35
|
+
on roles(fetch(:thinking_sphinx_roles)) do
|
36
|
+
begin
|
37
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} unmonitor #{ts_monit_service_name}"
|
38
|
+
rescue
|
39
|
+
# no worries here (still no monitoring)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Start Thinking Sphinx monit-service'
|
45
|
+
task :start do
|
46
|
+
on roles(fetch(:thinking_sphinx_roles)) do
|
47
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} start #{ts_monit_service_name}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Stop Thinking Sphinx monit-service'
|
52
|
+
task :stop do
|
53
|
+
on roles(fetch(:thinking_sphinx_roles)) do
|
54
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} stop #{ts_monit_service_name}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'Restart Thinking Sphinx monit-service'
|
59
|
+
task :restart do
|
60
|
+
on roles(fetch(:thinking_sphinx_roles)) do
|
61
|
+
sudo_if_needed "#{fetch(:thinking_sphinx_monit_bin)} restart #{ts_monit_service_name}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def ts_monit_service_name
|
66
|
+
fetch(:ts_monit_service_name, "thinking_sphinx_#{fetch(:application)}_#{fetch(:stage)}")
|
67
|
+
end
|
68
|
+
|
69
|
+
def sudo_if_needed(command)
|
70
|
+
if fetch(:thinking_sphinx_use_sudo)
|
71
|
+
sudo command
|
72
|
+
else
|
73
|
+
execute command
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
before 'thinking_sphinx:stop', 'thinking_sphinx_monit:unmonitor'
|
78
|
+
after 'thinking_sphinx:start', 'thinking_sphinx_monit:monitor'
|
79
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'thinking-sphinx'
|
2
|
+
|
3
|
+
namespace :ts_monit do
|
4
|
+
|
5
|
+
desc 'Generates Thinking Sphinx monit-service'
|
6
|
+
task :config, [:user, :sudo, :tmp_dir, :monit_conf_dir, :monit_bin, :service_name, :env] => [:environment] do |_, args|
|
7
|
+
@searchd = searchd
|
8
|
+
@config_path = config.configuration_file
|
9
|
+
@ts_pid_file = config.searchd.pid_file
|
10
|
+
@user = args.user
|
11
|
+
@service_name = args.service_name
|
12
|
+
@rails_env = args.env
|
13
|
+
template_sphinx 'ts_monit.conf', "#{args.tmp_dir}/ts_monit.conf"
|
14
|
+
sudo_if_needed args.sudo, "mv #{args.tmp_dir}/ts_monit.conf #{args.monit_conf_dir}"
|
15
|
+
sudo_if_needed args.sudo, "#{args.monit_bin} reload"
|
16
|
+
end
|
17
|
+
|
18
|
+
def sudo_if_needed(sudo, command)
|
19
|
+
if sudo
|
20
|
+
system "sudo #{command}"
|
21
|
+
else
|
22
|
+
exec "#{command}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def config
|
27
|
+
ThinkingSphinx::Configuration.instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def searchd
|
31
|
+
con = config.controller
|
32
|
+
"#{con.bin_path}#{con.searchd_binary_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def template_sphinx(from, to)
|
36
|
+
[
|
37
|
+
"lib/thinking_sphinx_monit/templates/#{from}.erb",
|
38
|
+
"config/deploy/templates/#{from}.erb",
|
39
|
+
File.expand_path("../../templates/#{from}.erb", __FILE__)
|
40
|
+
].each do |path|
|
41
|
+
if File.file?(path)
|
42
|
+
erb = File.read(path)
|
43
|
+
File.write(to, StringIO.new(ERB.new(erb, nil, '-').result(binding)).read)
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Monit configuration for Thinking Sphinx
|
2
|
+
# Service name: <%= @service_name %>
|
3
|
+
#
|
4
|
+
check process <%= @service_name %>
|
5
|
+
with pidfile "<%= @ts_pid_file %>"
|
6
|
+
start program = "/usr/bin/sudo -iu <%= @user %> /bin/bash -c '<%= @searchd %> --pidfile --config <%= @config_path %> --environment <%= @rails_env%>'"
|
7
|
+
stop program = "/usr/bin/sudo -iu <%= @user %> /bin/bash -c '<%= @searchd %> --pidfile --config <%= @config_path %> --stopwait --environment <%= @rails_env%>'"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thinking_sphinx_monit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'thinking-sphinx-monit'
|
8
|
+
spec.version = ThinkingSphinxMonit::VERSION
|
9
|
+
spec.authors = ['Michal Mrozek']
|
10
|
+
spec.email = ['michalmrozek@wp.pl']
|
11
|
+
spec.description = spec.summary = %q{Monit integration with Thinking Sphinx and Capistrano}
|
12
|
+
spec.homepage = 'https://github.com/Michsior14/thinking-sphinx-monit'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.add_runtime_dependency 'capistrano', '~> 3.0', '>= 3.0.0'
|
16
|
+
spec.add_runtime_dependency 'thinking-sphinx', '~> 3.3', '>= 3.3.0'
|
17
|
+
|
18
|
+
spec.required_ruby_version = '>= 1.9.3'
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thinking-sphinx-monit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michal Mrozek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: thinking-sphinx
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.3.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.3.0
|
53
|
+
description: Monit integration with Thinking Sphinx and Capistrano
|
54
|
+
email:
|
55
|
+
- michalmrozek@wp.pl
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".gitignore"
|
61
|
+
- Gemfile
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/generators/thinking_sphinx_monit/template_generator.rb
|
66
|
+
- lib/thinking-sphinx-monit.rb
|
67
|
+
- lib/thinking_sphinx_monit/capistrano.rb
|
68
|
+
- lib/thinking_sphinx_monit/railtie.rb
|
69
|
+
- lib/thinking_sphinx_monit/tasks/capistrano.rb
|
70
|
+
- lib/thinking_sphinx_monit/tasks/monit.rb
|
71
|
+
- lib/thinking_sphinx_monit/templates/ts_monit.conf.erb
|
72
|
+
- lib/thinking_sphinx_monit/version.rb
|
73
|
+
- thinking-sphinx-monit.gemspec
|
74
|
+
homepage: https://github.com/Michsior14/thinking-sphinx-monit
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.9.3
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.5.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Monit integration with Thinking Sphinx and Capistrano
|
98
|
+
test_files: []
|