stupid-simple-monit 0.0.1
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 +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/stupid_simple_monit.rb +13 -0
- data/features/step_definitions/process_steps.rb +13 -0
- data/features/stupid_simple_monit.feature +88 -0
- data/features/support/env.rb +1 -0
- data/lib/.keep +0 -0
- data/stupid-simple-monit.gemspec +20 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 93546d0b5dbe120d2e244ad5b2200cb548bbbc98
|
4
|
+
data.tar.gz: 4075d5a5845b7d4733011fa590625a2bfd000976
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2723bc8c1093d7ec895188da4db3dea8c33105ed6dd5228f5c6b30c27ad0bc419d0d91da70b24c292317ac2f18eb4f0f0f66a28910fbc3a9e60a78388c6fa583
|
7
|
+
data.tar.gz: b36186369f0d4af4b3375fff194f53acdcd4a4416c2a5b79e8186d978b2f260ac63a962bd03d3070feea41e444b108ae71ca9e0f6f8b8f41b48379542fdfd0bc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tamara Temple
|
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,51 @@
|
|
1
|
+
# stupid_simple_monit.rb
|
2
|
+
|
3
|
+
A really stupidly simple process monitoring script.
|
4
|
+
|
5
|
+
**Don't use this if you have real process monitoring needs, such as [god][god] or [monit][monit]!**
|
6
|
+
|
7
|
+
The genesis of this was a project that included [sidekiq][sidekiq] where the `sidekiq` process was stopping for some reason, and `monit` was not catching the shutdown and respawning it, and offering no indication why. As a stop-gap, we hacked this little ditty up. One of us had a bit of free time, so we played Keith Richards and took the original hack and minimized it to it's essence.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'simple-stupid-monit'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install stupid-simple-monit
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
Create a configuration file that contains the info needed to find the PID of your running process,
|
28
|
+
and a shell command to respawn the process:
|
29
|
+
|
30
|
+
``` yaml
|
31
|
+
pidfile: path/to/pidfile
|
32
|
+
start_script: "shell command to respawn your process"
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
The command is pretty simple:
|
38
|
+
|
39
|
+
$ stupid_simple_monit.rb [CONFIG_FILE]
|
40
|
+
|
41
|
+
If you omit `CONFIG_FILE` it defaults to `./config.yml`.
|
42
|
+
|
43
|
+
Ideally, put this into a `crontab` to run, say, every 5 or 10 minutes. (Again that caveat if you need something real, use `god` or `monit`.)
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/tamouse/stupid-simple-monit/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
def config
|
5
|
+
@_config ||= YAML.load_file(ARGV[0] || 'config.yml').tap{|t| fail "config file empty" unless t.is_a?(Hash)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def process_exists?
|
9
|
+
!!Process.kill(0, Integer(File.read(config.fetch('pidfile')))) rescue false
|
10
|
+
end
|
11
|
+
|
12
|
+
exit if process_exists?
|
13
|
+
fail 'respawn failed' unless system(config.fetch('start_script'))
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Given(/^a running process with a valid PID$/) do
|
2
|
+
@pid = Process.spawn("sleep 10000000")
|
3
|
+
end
|
4
|
+
|
5
|
+
Given(/^a valid pid file$/) do
|
6
|
+
step(%Q{a file named "pidfile" with:},"#{@pid}\n")
|
7
|
+
end
|
8
|
+
|
9
|
+
Then(/^the running process should be shut down$/) do
|
10
|
+
Process.kill "TERM", @pid
|
11
|
+
Process.wait @pid
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
Feature: Stupid, simple process monitor
|
2
|
+
In order to keep a process alive
|
3
|
+
As a system monitor
|
4
|
+
I want check that a process is running and respawn it if it isn't
|
5
|
+
|
6
|
+
|
7
|
+
Scenario: no config file exists
|
8
|
+
# Given a file "config.yml" does not exist
|
9
|
+
When I run `stupid_simple_monit.rb`
|
10
|
+
Then the output should match /No such file or directory.*config.yml/
|
11
|
+
And the exit status should be 1
|
12
|
+
|
13
|
+
Scenario: empty config file exists
|
14
|
+
Given an empty file named "config.yml"
|
15
|
+
When I run `stupid_simple_monit.rb`
|
16
|
+
Then the exit status should be 1
|
17
|
+
And the stderr should contain "config file empty"
|
18
|
+
|
19
|
+
Scenario: a config file that isn't yaml
|
20
|
+
Given a file named "config.yml" with:
|
21
|
+
"""
|
22
|
+
this is not YAML
|
23
|
+
"""
|
24
|
+
When I run `stupid_simple_monit.rb`
|
25
|
+
Then the exit status should be 1
|
26
|
+
And the stderr should contain "config file empty"
|
27
|
+
|
28
|
+
Scenario: a config file with missing PID file
|
29
|
+
Given a file named "config.yml" with:
|
30
|
+
"""
|
31
|
+
pidfile: bogus
|
32
|
+
start_script: echo I ran
|
33
|
+
"""
|
34
|
+
When I run `stupid_simple_monit.rb`
|
35
|
+
Then the exit status should be 0
|
36
|
+
And the output should contain "I ran"
|
37
|
+
|
38
|
+
Scenario: a config file with a bogus start_script
|
39
|
+
Given a file named "config.yml" with:
|
40
|
+
"""
|
41
|
+
pidfile: bogus
|
42
|
+
start_script: this_is_a_bogus_shell_command
|
43
|
+
"""
|
44
|
+
When I run `stupid_simple_monit.rb`
|
45
|
+
Then the exit status should be 1
|
46
|
+
And the output should contain "respawn failed"
|
47
|
+
|
48
|
+
Scenario: a config file with valid PID file and a running process
|
49
|
+
Given a running process with a valid PID
|
50
|
+
And a valid pid file
|
51
|
+
And a file named "config.yml" with:
|
52
|
+
"""
|
53
|
+
pidfile: pidfile
|
54
|
+
start_script: echo I ran
|
55
|
+
"""
|
56
|
+
When I run `stupid_simple_monit.rb`
|
57
|
+
Then the exit status should be 0
|
58
|
+
And the output should not contain "I ran"
|
59
|
+
And the running process should be shut down
|
60
|
+
|
61
|
+
Scenario: a config file with valid PID file and a stopped process
|
62
|
+
Given a running process with a valid PID
|
63
|
+
And a valid pid file
|
64
|
+
And a file named "config.yml" with:
|
65
|
+
"""
|
66
|
+
pidfile: pidfile
|
67
|
+
start_script: echo I ran
|
68
|
+
"""
|
69
|
+
And the running process should be shut down
|
70
|
+
When I run `stupid_simple_monit.rb`
|
71
|
+
Then the exit status should be 0
|
72
|
+
And the output should contain "I ran"
|
73
|
+
|
74
|
+
Scenario: pass a config file on the command line
|
75
|
+
Given a file named "my_ssm_config.yml" with:
|
76
|
+
"""
|
77
|
+
pidfile: bogus
|
78
|
+
start_script: echo I ran
|
79
|
+
"""
|
80
|
+
When I run `stupid_simple_monit.rb my_ssm_config.yml`
|
81
|
+
Then the exit status should be 0
|
82
|
+
And the output should contain "I ran"
|
83
|
+
|
84
|
+
Scenario: pass a non-existing config file on the command line
|
85
|
+
When I run `stupid_simple_monit.rb no_config_file`
|
86
|
+
Then the exit status should be 1
|
87
|
+
And the output should match /No such file or directory.*no_config_file/
|
88
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
data/lib/.keep
ADDED
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "stupid-simple-monit"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["Tamara Temple", "Kyle Kestell"]
|
7
|
+
spec.email = ["tamouse@gmail.com", "kyle@kestell.org"]
|
8
|
+
spec.summary = "A stupid, dead-simple, process monitor."
|
9
|
+
spec.homepage = "http://github.com/tamouse/stupid-simple-monit"
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.files = `git ls-files -z`.split("\x0")
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
18
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
19
|
+
spec.add_development_dependency "aruba"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stupid-simple-monit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tamara Temple
|
8
|
+
- Kyle Kestell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.6'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.6'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: aruba
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- tamouse@gmail.com
|
59
|
+
- kyle@kestell.org
|
60
|
+
executables:
|
61
|
+
- stupid_simple_monit.rb
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/stupid_simple_monit.rb
|
71
|
+
- features/step_definitions/process_steps.rb
|
72
|
+
- features/stupid_simple_monit.feature
|
73
|
+
- features/support/env.rb
|
74
|
+
- lib/.keep
|
75
|
+
- stupid-simple-monit.gemspec
|
76
|
+
homepage: http://github.com/tamouse/stupid-simple-monit
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A stupid, dead-simple, process monitor.
|
100
|
+
test_files:
|
101
|
+
- features/step_definitions/process_steps.rb
|
102
|
+
- features/stupid_simple_monit.feature
|
103
|
+
- features/support/env.rb
|
104
|
+
has_rdoc:
|