nines 1.0.0 → 1.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.
data/README.rdoc CHANGED
@@ -2,16 +2,49 @@
2
2
 
3
3
  Nines is a simple server monitoring tool written in Ruby. It reads in hand-coded YAML config files (see config.yml.sample). Rename to config.yml and edit as needed before first run.
4
4
 
5
- When run, it forks into the background and runs in a continuous loop. If there are bugs in the code (likely) it may die, so keep it running with monit, init, etc.
5
+ When run, it forks into the background and runs in a continuous loop. If there are bugs in the code (possible) it may die, so keep it running with monit, init, cron, whatever.
6
+
7
+ It's no substitute for paid services like Pingdom, but it's great for keeping tabs on less critical services.
6
8
 
7
9
  =Usage
8
10
 
9
- git clone git://github.com/anamba/nines.git && cd nines && bundle install && bundle exec ./nines
10
- To stop: bundle exec ./nines stop
11
+ % gem install nines
12
+ % nines -f <config file> start
13
+
14
+ The config file can be in YAML or ruby format. Refer to the included examples: {nines.yml.sample}[https://github.com/anamba/nines/blob/master/nines.yml.sample] | {nines.rb.sample}[https://github.com/anamba/nines/blob/master/nines.rb.sample]
15
+
16
+ What if you have only one server, and you want to monitor it? You do need to have a server to run nines on, and you don't want to have your one server monitoring itself. If you have a shared hosting account that allows shell access, you can run nines there. Many hosts offer an ancient version of ruby, but you can work around that with {rvm}[https://rvm.io/rvm/install/]. Here's how (tested on {Dreamhost}[http://dreamhost.com/]:
17
+
18
+ % \curl -L https://get.rvm.io | bash -s stable --ruby # installs rvm and stable version of ruby (currently 1.9.3p327)
19
+ % echo 'gem: --no-ri --no-rdoc' > ~/gemrc # gems install more quickly sans documentation
20
+ % gem install nines # grab the latest version of the nines gem
21
+ % cd ; mkdir nines && cd nines # put nines stuff in its own dir
22
+ % vi nines.yml # create a config file (start with a sample config)
23
+ % nines -d -f nines.yml # then test it in debug mode (remove -d once your config is working)
24
+
25
+ Add nines to your crontab to keep it running through errors and server reboots. When using cron+rvm, remember to grab the GEM_HOME and GEM_PATH environment variables from your shell and make sure the rvm version of ruby is in your path.
26
+
27
+ % echo $GEM_HOME
28
+ /home/[username]/.rvm/gems/ruby-1.9.3-p327
29
+ $ echo $GEM_PATH
30
+ /home/[username]/.rvm/gems/ruby-1.9.3-p327:/home/[username]/.rvm/gems/ruby-1.9.3-p327@global
31
+ % which ruby
32
+ /home/[username]/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
33
+
34
+ Example crontab (note the two different bin dirs for rvm):
35
+
36
+ MAILTO="aaron@biggerbird.com"
37
+ PATH=/home/[username]/.rvm/rubies/ruby-1.9.3-p327/bin:/home/[username]/.rvm/gems/ruby-1.9.3-p327/bin:/usr/bin:/bin
38
+ GEM_HOME=/home/[username]/.rvm/gems/ruby-1.9.3-p327
39
+ GEM_PATH=/home/[username]/.rvm/gems/ruby-1.9.3-p327:/home/[username]/.rvm/gems/ruby-1.9.3-p327@global
40
+
41
+ */15 * * * * nines -d -f /home/[username]/nines/nines.rb
42
+
43
+ This will try to (re)start nines every 15 minutes. (If it is running, the command will just exit.)
11
44
 
12
45
  =Dependencies
13
46
 
14
- Developed and tested with MRI ruby 1.9.3.
47
+ Developed and tested with MRI ruby 1.9.3. Regularly used on CentOS 5, Amazon Linux and OS X 10.8, but ought to work on any POSIX-compliant OS.
15
48
 
16
49
  Dependencies:
17
50
  * trollop (commandline options)
data/bin/nines CHANGED
@@ -44,10 +44,15 @@ end
44
44
  # process subcommands
45
45
  cmd = ARGV.shift
46
46
  case cmd
47
- when 'start'
47
+ when 'start', nil
48
48
  cmd_opts = Trollop.options do
49
49
  end
50
50
 
51
+ if app.running?
52
+ STDERR.puts "Nines appears to be running at pid #{File.open(app.pidfile).read}, exiting."
53
+ exit 1
54
+ end
55
+
51
56
  app.start(cmd_opts)
52
57
 
53
58
  when 'stop'
@@ -55,7 +60,4 @@ when 'stop'
55
60
  end
56
61
 
57
62
  app.stop(cmd_opts)
58
-
59
- else
60
- app.start
61
63
  end
data/lib/nines/app.rb CHANGED
@@ -38,6 +38,32 @@ module Nines
38
38
  def debug ; self.class.debug ; end
39
39
  def logger ; self.class.logger ; end
40
40
 
41
+ def running?
42
+ pid = nil
43
+
44
+ begin
45
+ pid = File.open(pidfile).read.to_i
46
+ return false if pid == 0
47
+ rescue
48
+ # puts "Pidfile doesn't exist"
49
+ return false
50
+ end
51
+
52
+ begin
53
+ Process.kill(0, pid)
54
+ # puts "#{pid} is running"
55
+ return true
56
+ rescue Errno::EPERM
57
+ # puts "No permission to query #{pid}!"
58
+ rescue Errno::ESRCH
59
+ # puts "#{pid} is NOT running."
60
+ rescue
61
+ # puts "Unable to determine status for #{pid} : #{$!}"
62
+ end
63
+
64
+ false
65
+ end
66
+
41
67
  def logfile_writable
42
68
  begin
43
69
  File.open(logfile, 'a') { }
@@ -170,20 +196,29 @@ module Nines
170
196
  logger.puts "[#{Time.now}] - nines finished"
171
197
  logger.close
172
198
 
199
+ File.unlink(pidfile)
200
+
173
201
  puts "Background process finished"
174
202
  end
175
203
 
176
204
  def stop(options = {})
177
205
  begin
178
- pid = File.read(self.class.pidfile).to_i
206
+ pid = File.read(pidfile).to_i
207
+ if pid == 0
208
+ STDERR.puts "nines does not appear to be running."
209
+ exit 1
210
+ end
179
211
  rescue Errno::ENOENT => e
180
- STDERR.puts "Couldn't open pid file #{self.class.pidfile}, please check your config."
212
+ STDERR.puts "Couldn't open pid file #{pidfile}, please check your config."
181
213
  exit 1
182
214
  end
183
215
 
184
216
  begin
185
217
  Process.kill "INT", pid
186
218
  exit 0
219
+ rescue Errno::EPERM => e
220
+ STDERR.puts "Couldn't kill process with pid #{pid}, appears to be owned by someone else."
221
+ exit 1
187
222
  rescue Errno::ESRCH => e
188
223
  STDERR.puts "Couldn't kill process with pid #{pid}. Are you sure it's running?"
189
224
  exit 1
data/lib/nines/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nines
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/nines.rb.sample CHANGED
@@ -2,8 +2,8 @@ Nines::App.config = {
2
2
  debug: false,
3
3
  verbose: false,
4
4
 
5
- logfile: 'log/nines.log',
6
- pidfile: 'tmp/nines.pid',
5
+ logfile: './nines.log',
6
+ pidfile: './nines.pid',
7
7
  email_from: 'Nines Notifier <no-reply@example.com>',
8
8
  email_subject_prefix: '[NINES] ',
9
9
 
@@ -53,4 +53,4 @@ Nines::App.config = {
53
53
  authentication: 'plain',
54
54
  enable_starttls_auto: true
55
55
  }
56
- }
56
+ }
data/nines.yml.sample CHANGED
@@ -2,8 +2,8 @@
2
2
  debug: false
3
3
  verbose: false
4
4
 
5
- logfile: log/nines.log
6
- pidfile: tmp/nines.pid
5
+ logfile: ./nines.log
6
+ pidfile: ./nines.pid
7
7
  email_from: 'Nines Notifier <no-reply@calchost.com>'
8
8
  email_subject_prefix: '[NINES] '
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nines
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ping