daemons 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Daemons Version 1.0.5
1
+ = Daemons Version 1.0.6
2
2
 
3
3
  (See Releases for release-specific information)
4
4
 
data/Releases CHANGED
@@ -1,8 +1,13 @@
1
1
  = Daemons Release History
2
2
 
3
+ == Release 1.0.6: Mai 8, 2007
4
+
5
+ * New option to pass an ARGV-style array to run and run_proc (thanks to Marc Evans).
6
+ * Additional patches for '/var/log' (thanks to Marc Evans).
7
+
3
8
  == Release 1.0.5: February 24, 2007
4
9
 
5
- * Applied patch that causes daemons to use '/var/log' as logfile
10
+ * Applied patch that makes daemons to use '/var/log' as logfile
6
11
  directory if you use :dir_mode = :system (thanks to Han Holl).
7
12
  * Daemons should now work with Ruby 1.9 (at least the basic features).
8
13
 
@@ -13,7 +13,7 @@ testfile = File.expand_path(__FILE__) + '.log'
13
13
 
14
14
 
15
15
  # On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
16
- # will be created and the options will be kept within, so you only have to specify
16
+ # will be created an the options will be kept within, so you only have to specify
17
17
  # <tt>:multiple</tt> once.
18
18
  #
19
19
 
@@ -0,0 +1,43 @@
1
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
2
+
3
+ if File.exist?(File.join(lib_dir, 'daemons.rb'))
4
+ $LOAD_PATH.unshift lib_dir
5
+ else
6
+ begin; require 'rubygems'; rescue ::Exception; end
7
+ end
8
+
9
+ require 'daemons'
10
+ require 'optparse'
11
+ require 'logger'
12
+ require 'ostruct'
13
+
14
+
15
+ class MyApp < Logger::Application
16
+ def initialize(args)
17
+ super(self.class)
18
+ @options = OpenStruct.new(:daemonize => true)
19
+ opts = OptionParser.new do |opts|
20
+ opts.banner = 'Usage: myapp [options]'
21
+ opts.separator ''
22
+ opts.on('-N','--no-daemonize',"Don't run as a daemon") do
23
+ @options.daemonize = false
24
+ end
25
+ end
26
+ @args = opts.parse!(args)
27
+ end
28
+
29
+ def run
30
+ Daemons.run_proc('myapp',{:ARGV => @args, :ontop => !@options.daemonize}) do
31
+ puts "@options.daemonize: #{@options.daemonize}"
32
+ STDOUT.sync = true
33
+ loop do
34
+ print '.'
35
+ sleep(2)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ myapp = MyApp.new(ARGV)
43
+ myapp.run
@@ -65,7 +65,7 @@ require 'daemons/controller'
65
65
  #
66
66
  module Daemons
67
67
 
68
- VERSION = "1.0.5"
68
+ VERSION = "1.0.6"
69
69
 
70
70
  require 'daemons/daemonize'
71
71
 
@@ -89,6 +89,8 @@ module Daemons
89
89
  # used to contruct the name of the pid files
90
90
  # and log files. Defaults to the basename of
91
91
  # the script.
92
+ # <tt>:ARGV</tt>:: An array of strings containing parameters and switches for Daemons.
93
+ # If not given, ARGV (the parameters given to the Ruby process) will be used.
92
94
  # <tt>:dir_mode</tt>:: Either <tt>:script</tt> (the directory for writing the pid files to
93
95
  # given by <tt>:dir</tt> is interpreted relative
94
96
  # to the script location given by +script+) or <tt>:normal</tt> (the directory given by
@@ -113,6 +115,7 @@ module Daemons
113
115
  # === Example:
114
116
  # options = {
115
117
  # :app_name => "my_app",
118
+ # :ARGV => ['start', '-f']
116
119
  # :dir_mode => :script,
117
120
  # :dir => 'pids',
118
121
  # :multiple => true,
@@ -127,7 +130,7 @@ module Daemons
127
130
  #
128
131
  def run(script, options = {})
129
132
  options[:script] = script
130
- @controller = Controller.new(options, ARGV)
133
+ @controller = Controller.new(options, options[:ARGV] || ARGV)
131
134
 
132
135
  @controller.catch_exceptions {
133
136
  @controller.run
@@ -176,7 +179,7 @@ module Daemons
176
179
  options[:dir] = File.expand_path('.')
177
180
  end
178
181
 
179
- @controller = Controller.new(options, ARGV)
182
+ @controller = Controller.new(options, options[:ARGV] || ARGV)
180
183
 
181
184
  @controller.catch_exceptions {
182
185
  @controller.run
@@ -24,6 +24,8 @@ module Daemons
24
24
  @options = group.options.dup
25
25
  @options.update(add_options)
26
26
 
27
+ @dir_mode = @dir = @script = nil
28
+
27
29
  unless @pid = pid
28
30
  if dir = pidfile_dir
29
31
  @pid = PidFile.new(dir, @group.app_name, @group.multiple)
@@ -41,11 +43,15 @@ module Daemons
41
43
  Pid.dir(@dir_mode || @group.dir_mode, @dir || @group.dir, @script || @group.script)
42
44
  end
43
45
 
44
- def logfile
46
+ def output_logfile
45
47
  logdir = options[:dir_mode] == :system ? '/var/log' : pidfile_dir
46
48
  (options[:log_output] && logdir) ? File.join(logdir, @group.app_name + '.output') : nil
47
49
  end
48
50
 
51
+ def logfile
52
+ logdir = options[:dir_mode] == :system ? '/var/log' : pidfile_dir
53
+ logdir ? File.join(logdir, @group.app_name + '.log') : nil
54
+ end
49
55
 
50
56
  # this function is only used to daemonize the currently running process (Daemons.daemonize)
51
57
  def start_none
@@ -89,9 +95,9 @@ module Daemons
89
95
 
90
96
  def start_exec
91
97
  unless options[:ontop]
92
- Daemonize.daemonize(logfile, @group.app_name)
98
+ Daemonize.daemonize(output_logfile, @group.app_name)
93
99
  else
94
- Daemonize.simulate(logfile)
100
+ Daemonize.simulate(output_logfile)
95
101
  end
96
102
 
97
103
  # note that we cannot remove the pid file if we run in :ontop mode (i.e. 'ruby ctrl_exec.rb run')
@@ -105,9 +111,9 @@ module Daemons
105
111
 
106
112
  def start_load
107
113
  unless options[:ontop]
108
- Daemonize.daemonize(logfile, @group.app_name)
114
+ Daemonize.daemonize(output_logfile, @group.app_name)
109
115
  else
110
- Daemonize.simulate(logfile)
116
+ Daemonize.simulate(output_logfile)
111
117
  end
112
118
 
113
119
  @pid.pid = Process.pid
@@ -188,9 +194,9 @@ module Daemons
188
194
  end
189
195
 
190
196
  unless options[:ontop]
191
- @pid.pid = Daemonize.call_as_daemon(myproc, logfile, @group.app_name)
197
+ @pid.pid = Daemonize.call_as_daemon(myproc, output_logfile, @group.app_name)
192
198
  else
193
- Daemonize.simulate(logfile)
199
+ Daemonize.simulate(output_logfile)
194
200
 
195
201
  @pid.pid = Process.pid
196
202
 
@@ -257,10 +263,11 @@ module Daemons
257
263
  # (if it is connected) and to a log file in the pid-file directory.
258
264
  #
259
265
  def exception_log
260
- require 'logger'
266
+ return unless logfile
261
267
 
262
- l_file = Logger.new(File.join(pidfile_dir(), @group.app_name + '.log'))
268
+ require 'logger'
263
269
 
270
+ l_file = Logger.new(logfile)
264
271
 
265
272
  # the code below only logs the last exception
266
273
  # e = nil
@@ -338,4 +345,4 @@ module Daemons
338
345
  end
339
346
  end
340
347
 
341
- end
348
+ end
@@ -28,13 +28,14 @@ module Daemons
28
28
 
29
29
 
30
30
  def initialize(an_app)
31
+ @app = an_app
32
+ @app_name = an_app.group.app_name + '_monitor'
33
+
31
34
  if an_app.pidfile_dir
32
- @pid = PidFile.new(an_app.pidfile_dir, an_app.group.app_name + '_monitor', false)
35
+ @pid = PidFile.new(an_app.pidfile_dir, @app_name, false)
33
36
  else
34
37
  @pid = PidMem.new
35
38
  end
36
-
37
- @app_name = an_app.group.app_name + '_monitor'
38
39
  end
39
40
 
40
41
  def watch(applications)
@@ -67,7 +68,7 @@ module Daemons
67
68
  @pid.pid = Process.pid
68
69
 
69
70
  # at_exit {
70
- # begin; @pid.cleanup; rescue ::Exception; end
71
+ # begin; @pid.cleanup; rescue ::Exception; end
71
72
  # }
72
73
 
73
74
  # This part is needed to remove the pid-file if the application is killed by
@@ -76,14 +77,14 @@ module Daemons
76
77
  # 'TERM'.
77
78
  #
78
79
  # trap('TERM') {
79
- # begin; @pid.cleanup; rescue ::Exception; end
80
+ # begin; @pid.cleanup; rescue ::Exception; end
80
81
  # exit
81
82
  # }
82
83
 
83
84
  watch(applications)
84
85
  rescue ::Exception => e
85
86
  begin
86
- File.open(File.join(@pid.dir, @pid.progname + '.log'), 'a') {|f|
87
+ File.open(@app.logfile, 'a') {|f|
87
88
  f.puts Time.now
88
89
  f.puts e
89
90
  f.puts e.backtrace.inspect
@@ -103,7 +104,6 @@ module Daemons
103
104
  private :start_without_pidfile
104
105
 
105
106
 
106
-
107
107
  def start(applications)
108
108
  return if applications.empty?
109
109
 
@@ -123,6 +123,5 @@ module Daemons
123
123
  begin; @pid.cleanup; rescue ::Exception; end
124
124
  end
125
125
 
126
- end
127
-
126
+ end
128
127
  end
@@ -22,9 +22,7 @@ module Daemons
22
22
  break
23
23
  }
24
24
  ensure
25
- begin; ps_in.close; rescue ::Exception; end
26
- begin; ps_out.close; rescue ::Exception; end
27
- begin; ps_err.close; rescue ::Exception; end
25
+ begin; begin; ps_in.close; rescue ::Exception; end; ps_out.close rescue nil; ps_err.close; rescue ::Exception; end
28
26
  end
29
27
 
30
28
  # an alternative would be to use the code below, but I don't know whether this is portable
@@ -57,6 +57,7 @@ module Daemons
57
57
  @dir = File.expand_path(dir)
58
58
  @progname = progname
59
59
  @multiple = multiple
60
+ @number = nil
60
61
  @number = 0 if multiple
61
62
  end
62
63
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.1
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: daemons
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.5
7
- date: 2007-02-24 00:00:00 +01:00
6
+ version: 1.0.6
7
+ date: 2007-05-08 00:00:00 +02:00
8
8
  summary: A toolkit to create and control daemons in different ways
9
9
  require_paths:
10
10
  - lib
@@ -35,7 +35,6 @@ files:
35
35
  - README
36
36
  - LICENSE
37
37
  - setup.rb
38
- - lib/daemons.rb
39
38
  - lib/daemons/application.rb
40
39
  - lib/daemons/application_group.rb
41
40
  - lib/daemons/cmdline.rb
@@ -46,17 +45,18 @@ files:
46
45
  - lib/daemons/pid.rb
47
46
  - lib/daemons/pidfile.rb
48
47
  - lib/daemons/pidmem.rb
48
+ - lib/daemons.rb
49
49
  - test/call_as_daemon.rb
50
50
  - test/tc_main.rb
51
51
  - test/test1.rb
52
52
  - test/testapp.rb
53
53
  - test/tmp
54
54
  - examples/call
55
- - examples/daemonize
56
- - examples/run
57
55
  - examples/call/call.rb
58
56
  - examples/call/call_monitor.rb
57
+ - examples/daemonize
59
58
  - examples/daemonize/daemonize.rb
59
+ - examples/run
60
60
  - examples/run/ctrl_crash.rb
61
61
  - examples/run/ctrl_exec.rb
62
62
  - examples/run/ctrl_exit.rb
@@ -64,12 +64,11 @@ files:
64
64
  - examples/run/ctrl_multiple.rb
65
65
  - examples/run/ctrl_normal.rb
66
66
  - examples/run/ctrl_ontop.rb
67
+ - examples/run/ctrl_optionparser.rb
67
68
  - examples/run/ctrl_proc.rb
68
- - examples/run/ctrl_proc.rb.output
69
69
  - examples/run/ctrl_proc_simple.rb
70
70
  - examples/run/myserver.rb
71
71
  - examples/run/myserver_crashing.rb
72
- - examples/run/myserver_crashing.rb.output
73
72
  - examples/run/myserver_exiting.rb
74
73
  test_files:
75
74
  - test/tc_main.rb
@@ -1,101 +0,0 @@
1
- ping from proc!
2
- ping from proc!
3
- ping from proc!
4
- ping from proc!
5
- ping from proc!
6
- ping from proc!
7
- ping from proc!
8
- ping from proc!
9
- ping from proc!
10
- ping from proc!
11
- ping from proc!
12
- ping from proc!
13
- ping from proc!
14
- ping from proc!
15
- ping from proc!
16
- ping from proc!
17
- ping from proc!
18
- ping from proc!
19
- ping from proc!
20
- ping from proc!
21
- ping from proc!
22
- ping from proc!
23
- ping from proc!
24
- ping from proc!
25
- ping from proc!
26
- ping from proc!
27
- ping from proc!
28
- ping from proc!
29
- ping from proc!
30
- ping from proc!
31
- ping from proc!
32
- ping from proc!
33
- ping from proc!
34
- ping from proc!
35
- ping from proc!
36
- ping from proc!
37
- ping from proc!
38
- ping from proc!
39
- ping from proc!
40
- ping from proc!
41
- ping from proc!
42
- ping from proc!
43
- ping from proc!
44
- ping from proc!
45
- ping from proc!
46
- ping from proc!
47
- ping from proc!
48
- ping from proc!
49
- ping from proc!
50
- ping from proc!
51
- ping from proc!
52
- ping from proc!
53
- ping from proc!
54
- ping from proc!
55
- ping from proc!
56
- ping from proc!
57
- ping from proc!
58
- ping from proc!
59
- ping from proc!
60
- ping from proc!
61
- ping from proc!
62
- ping from proc!
63
- ping from proc!
64
- ping from proc!
65
- ping from proc!
66
- ping from proc!
67
- ping from proc!
68
- ping from proc!
69
- ping from proc!
70
- ping from proc!
71
- ping from proc!
72
- ping from proc!
73
- ping from proc!
74
- ping from proc!
75
- ping from proc!
76
- ping from proc!
77
- ping from proc!
78
- ping from proc!
79
- ping from proc!
80
- ping from proc!
81
- ping from proc!
82
- ping from proc!
83
- ping from proc!
84
- ping from proc!
85
- ping from proc!
86
- ping from proc!
87
- ping from proc!
88
- ping from proc!
89
- ping from proc!
90
- ping from proc!
91
- ping from proc!
92
- ping from proc!
93
- ping from proc!
94
- ping from proc!
95
- ping from proc!
96
- ping from proc!
97
- ping from proc!
98
- ping from proc!
99
- ping from proc!
100
- ping from proc!
101
- ping from proc!
@@ -1,15 +0,0 @@
1
- /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:13: CRASH! (RuntimeError)
2
- from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6:in `loop'
3
- from /home/uehli/Desktop/daemons-current/examples/myserver_crashing.rb:6
4
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `load'
5
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:116:in `run_via_load'
6
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:90:in `start'
7
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:359:in `run'
8
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:469:in `run'
9
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `call'
10
- from /home/uehli/Desktop/daemons-current/lib/daemons/cmdline.rb:94:in `catch_exceptions'
11
- from /home/uehli/Desktop/daemons-current/lib/daemons.rb:468:in `run'
12
- from ctrl_crash.rb:17
13
- ping from myserver.rb!
14
- this example server will crash in 3 seconds...
15
- CRASH!