Skip to content
Browse files

update readme with example - remove example.rb and added spec_helper

code
  • Loading branch information...
1 parent fa4db39 commit a68998c232f64bdb5366a3b2e7c56725bab8d760 @mephux committed Apr 6, 2011
Showing with 117 additions and 59 deletions.
  1. +48 −5 README.md
  2. +0 −49 example.rb
  3. +6 −4 gemspec.yml
  4. +5 −0 lib/pidly/control.rb
  5. +11 −0 spec/control_spec.rb
  6. +47 −1 spec/spec_helper.rb
View
53 README.md
@@ -5,15 +5,58 @@
## Description
-TODO: Description
-
-## Features
+Pidly is a very minimalistic daemon library that doesn't make assumptions. Pidly allows you to control the
+daemon without getting in the way with forced verbose output and usage messages.
## Examples
- require 'pidly'
+ require 'pidly'
+
+ class Test < Pidly::Control
+
+ before_start :test_before_daemon_starts
+
+ start :when_daemon_starts
+
+ stop :when_daemon_stops
+
+ after_stop :test_after_daemon_stops
+
+ error :on_daemon_error_send_email
+
+ def test_before_daemon_starts
+ puts "BEFORE START #{@pid}"
+ end
+
+ def when_daemon_starts
+ loop do
+ puts Time.now
+ sleep 2
+ end
+ end
+
+ def when_daemon_stops
+ puts "Attempting to kill process: #{@pid}"
+ end
+
+ def test_after_daemon_stops
+ puts "AFTER STOP #{@pid}"
+ end
+
+ def send_email
+ puts "SENDING EMAIL | Error Count: #{@error_count}"
+ end
+
+ end
+
+ @daemon = Test.spawn(
+ :name => 'Test Daemon',
+ :path => '/tmp',
+ :verbose => true
+ )
-## Requirements
+ # @daemon.send ARGV.first
+ @daemon.start # stop, status, restart, and kill.
## Install
View
49 example.rb
@@ -1,49 +0,0 @@
-$:.unshift File.join(File.dirname(__FILE__), "lib")
-
-require 'pidly'
-require 'pp'
-
-class Test < Pidly::Control
-
- before_start :test_before_daemon_starts
-
- start :when_daemon_starts
-
- stop :when_daemon_stops
-
- after_stop :test_after_daemon_stops
-
- error :on_daemon_error_send_email
-
- def test_before_daemon_starts
- puts "BEFORE START #{@pid}"
- end
-
- def when_daemon_starts
- loop do
- puts Time.now
- sleep 2
- end
- end
-
- def when_daemon_stops
- puts "Attempting to kill process: #{@pid}"
- end
-
- def test_after_daemon_stops
- puts "AFTER STOP #{@pid}"
- end
-
- def send_email
- puts "SENDING EMAIL | Error Count: #{@error_count}"
- end
-
-end
-
-@daemon = Test.spawn(
- :name => 'Test Daemon',
- :path => '/tmp',
- :verbose => true
-)
-
-@daemon.send ARGV.first
View
10 gemspec.yml
@@ -1,9 +1,11 @@
name: pidly
-summary: "TODO: Summary"
-description: "TODO: Description"
+summary: "A super simple daemon library."
+description:
+ "Pidly is a very minimalistic daemon library that doesnt make assumptions. Pidly allows you to control the
+ daemon without getting in the way with forced verbose output and usage messages."
license: MIT
-authors: dustinwebber
-homepage: http://rubygems.org/gems/pidly
+authors: Dustin Willis Webber
+homepage: https://github.com/mephux/pidly
has_yard: true
development_dependencies:
View
5 lib/pidly/control.rb
@@ -185,6 +185,11 @@ def status
def restart
stop; sleep 1 while running?; start
end
+
+ def kill
+ say :info, "Killing #{@name} (PID #{@pid})"
+ Process.kill 9, pid if running?
+ end
def running?
Process.kill 0, @pid
View
11 spec/control_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+require 'pidly'
+
+
+describe Control do
+
+ before(:all) do
+
+ end
+
+end
View
48 spec/spec_helper.rb
@@ -1,5 +1,51 @@
gem 'rspec', '~> 2.4'
require 'rspec'
-require 'pidly/version'
+require 'pidly'
include Pidly
+
+class Test < Pidly::Control
+
+ before_start :test_before_daemon_starts
+
+ start :when_daemon_starts
+
+ stop :when_daemon_stops
+
+ after_stop :test_after_daemon_stops
+
+ error :on_daemon_error_send_email
+
+ def test_before_daemon_starts
+ puts "BEFORE START #{@pid}"
+ end
+
+ def when_daemon_starts
+ loop do
+ puts Time.now
+ sleep 2
+ end
+ end
+
+ def when_daemon_stops
+ puts "Attempting to kill process: #{@pid}"
+ end
+
+ def test_after_daemon_stops
+ puts "AFTER STOP #{@pid}"
+ end
+
+ def send_email
+ puts "SENDING EMAIL | Error Count: #{@error_count}"
+ end
+
+end
+
+@daemon = Test.spawn(
+ :name => 'Test Daemon',
+ :path => '/tmp',
+ :verbose => true
+)
+
+# @daemon.send ARGV.first
+@daemon.start # stop, status, restart, and kill.

0 comments on commit a68998c

Please sign in to comment.
Something went wrong with that request. Please try again.