basic_daemon 0.9.0 → 0.9.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/History.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ = 0.9.0 - 20100216
2
+
3
+ * Bumped the version to 0.9.0 because it's just about ready for a 1.0 release.
4
+ * cleaned up tests and added a restart test to oo and function
5
+ * Still need to work on documentation and fix the Rakefile
6
+
7
+ = 0.1.5 - 20100118
8
+
9
+ Doing some refactoring and broke out code which determines the PID into its
10
+ own method "pid".
11
+
12
+ Added LICENSE and updated TODO
13
+
14
+ Updated Rakefile and tests
15
+
16
+ = 0.1.4 - 20100115
17
+
18
+ Provided basic documentation for the methods.
19
+
20
+ = 0.1.3 - 20091230
21
+
22
+ Breaking out tests
23
+
24
+ * Broke out tests to organize by functionality
25
+
26
+ = 0.1.2 - 20091230
27
+
28
+ Switched back to Test::Unit
29
+
30
+ * Migrated all RSpec tests to Test::Unit
31
+ * Expanded tests to handle calling blocks
32
+
33
+ = 0.1.1 - 20090925
34
+
35
+ RSpec testing expansion.
36
+
37
+ * continuing to add tests to the spec.
38
+ * added a method to the library to determine if a PID is alive
39
+
40
+ = 0.1.0 - 20090923
41
+
42
+ Major bug fixes
43
+
44
+ * The daemon now correctly forks off from the calling process.
45
+ * The procedural means of executing a daemon have been eliminated.
46
+
47
+ = 0.0.5 - 20090921
48
+
49
+ Began moving tests to RSpec.
50
+
51
+ = 0.0.5 - 20090812
52
+
53
+ Started recording changes to the repository in to line up with git commit
54
+ messages.
55
+
56
+ * addition of License.txt and History.txt, though mostly empty
57
+ * Initial gemspec was created. The daemon is now gemable
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Samuel Mullen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -5,6 +5,10 @@ A basic library for creating daemonized processes
5
5
 
6
6
  This library works with Ruby 1.8, Ruby 1.9, and JRuby and is licensed under the MIT License.
7
7
 
8
+ Installation
9
+
10
+ sudo gem install basic_daemon
11
+
8
12
  Gettings Started
9
13
 
10
14
  There are currently two ways of using the basic_daemon library: 1) Objected Oriented; 2) Functional.
@@ -88,7 +92,3 @@ Example:
88
92
  Most Linux users will want to instantiate thusly:
89
93
 
90
94
  BasicDaemon.new(:piddir => '/var/lock')
91
-
92
- Installation
93
-
94
- pending
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'lib/basic_daemon'
5
+ require 'rake/testtask'
6
+ require 'rake/gempackagetask'
7
+
8
+ lib_dir = File.expand_path('lib')
9
+ test_dir = File.expand_path('test')
10
+
11
+ gem_spec = Gem::Specification.new do |s|
12
+ s.name = "basic_daemon"
13
+ s.version = BasicDaemon::VERSION
14
+ s.authors = ["Samuel Mullen"]
15
+ s.email = "samullen@gmail.com"
16
+ s.homepage = "http://github.com/samullen/basic_daemon"
17
+ s.summary = "A simple ruby library for daemonizing processes"
18
+ s.authors = ["Samuel Mullen"]
19
+ s.email = "samullen@gmail.com"
20
+ s.test_files = Dir['test/**/*.rb']
21
+ s.description = false
22
+ s.files = [
23
+ "History.rdoc",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "examples/functional.rb",
28
+ "examples/objectoriented.rb",
29
+ "lib/basic_daemon.rb"
30
+ ] + s.test_files
31
+ end
32
+
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs = [lib_dir, test_dir]
35
+ test.pattern = 'test/**/*rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ Rake::GemPackageTask.new(gem_spec) do |pkg|
40
+ pkg.need_zip = false
41
+ pkg.need_tar = false
42
+ end
43
+
44
+ desc "Install the gem locally"
45
+ task :install => [:test, :gem] do
46
+ sh %{gem install pkg/#{gem_spec.name}-#{gem_spec.version}}
47
+ end
48
+
49
+ desc "Remove the pkg directory and all of its contents."
50
+ task :clean => :clobber_package
51
+
52
+ task :default => [:test, :gem]
@@ -1,8 +1,5 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- # STDERR.puts "this won't work until I get the block stuff working."
4
- # exit
5
-
6
3
  require File.join(File.dirname(__FILE__), '..', 'lib','basic_daemon')
7
4
 
8
5
  basedir = "/tmp" # change this to where you want to deal with things
@@ -10,29 +7,29 @@ pidfile = File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME))
10
7
 
11
8
  d = BasicDaemon.new({:pidfile => pidfile, :piddir => basedir, :workingdir => basedir})
12
9
 
13
- if ARGV[0] == 'start'
14
- puts "should print 'got here' on the next line"
15
- d.start do
16
- i = 1
17
- foo = open(basedir + "/out", "w")
18
-
19
- while true do
20
- foo.puts "loop: #{i}"
21
- foo.flush
22
- sleep 5
23
-
24
- i += 1
25
- end
10
+ process = Proc.new do
11
+ i = 1
12
+ foo = open(basedir + "/out", "w")
13
+
14
+ while true do
15
+ foo.puts "loop: #{i}"
16
+ foo.flush
17
+ sleep 5
18
+
19
+ i += 1
26
20
  end
21
+ end
22
+
23
+ if ARGV[0] == 'start'
24
+ d.start &process
27
25
  elsif ARGV[0] == 'stop'
28
26
  d.stop
29
27
  exit!
30
28
  elsif ARGV[0] == 'restart'
31
- d.restart
29
+ d.restart &process
32
30
  else
33
- STDERR.puts "wrong! use start or stop."
31
+ STDERR.puts "wrong! Use start, stop, or restart."
34
32
  exit!
35
33
  end
36
34
 
37
- puts 'got here'
38
35
  exit
@@ -25,7 +25,6 @@ end
25
25
  d = MyDaemon.new(:pidfile => pidfile, :piddir => basedir, :workingdir => basedir)
26
26
 
27
27
  if ARGV[0] == 'start'
28
- puts "Should print 'got here' on the next line"
29
28
  d.start
30
29
  elsif ARGV[0] == 'stop'
31
30
  d.stop
@@ -37,5 +36,4 @@ else
37
36
  exit!
38
37
  end
39
38
 
40
- puts 'got here'
41
39
  exit
data/lib/basic_daemon.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class BasicDaemon
2
2
  attr_accessor :workingdir, :pidfile, :piddir, :process
3
3
 
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
 
6
6
  DEFAULT_OPTIONS = {
7
7
  :pidfile => File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)),
@@ -38,7 +38,6 @@ class BasicDaemon
38
38
  @pidfile = opts[:pidfile]
39
39
  @workingdir = opts[:workingdir]
40
40
  @pid = nil
41
- @process = nil
42
41
  end
43
42
 
44
43
  # Returns the fullpath to the file containing the process ID (PID)
@@ -71,10 +70,6 @@ class BasicDaemon
71
70
  exit!
72
71
  end
73
72
 
74
- if block_given?
75
- @process = block
76
- end
77
-
78
73
  #----- Fork off from the calling process -----#
79
74
  begin
80
75
  fork do
@@ -103,8 +98,8 @@ class BasicDaemon
103
98
  STDOUT.reopen("/dev/null", "w")
104
99
  STDERR.reopen("/dev/null", "w")
105
100
 
106
- unless @process.nil?
107
- @process.call
101
+ if block_given?
102
+ block.call
108
103
  else
109
104
  self.run
110
105
  end
@@ -139,14 +134,14 @@ class BasicDaemon
139
134
  # restarts the daemon by first killing it and then restarting.
140
135
  #
141
136
  # Warning: does not work if block is initially passed to start.
142
- def restart
137
+ def restart(&block)
143
138
  self.stop
144
139
  @pid = nil
145
140
 
146
- unless @process.nil?
141
+ unless block_given?
147
142
  self.start
148
143
  else
149
- self.start &@process
144
+ self.start &block
150
145
  end
151
146
  end
152
147
 
@@ -68,7 +68,7 @@ class TestFunctionalBasicDaemon < Test::Unit::TestCase
68
68
  assert @daemon.process_exists?
69
69
  previous_pid = @daemon.pid
70
70
 
71
- @daemon.restart
71
+ @daemon.restart &@process
72
72
  sleep 0.1
73
73
  assert @daemon.process_exists?
74
74
  assert previous_pid != @daemon.pid
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basic_daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Mullen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-18 00:00:00 -06:00
12
+ date: 2010-02-22 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,7 +22,10 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - README
25
+ - History.rdoc
26
+ - LICENSE
27
+ - README.rdoc
28
+ - Rakefile
26
29
  - examples/functional.rb
27
30
  - examples/objectoriented.rb
28
31
  - lib/basic_daemon.rb