mlanett-daemons 1.0.13

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.
Files changed (85) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +17 -0
  4. data/LICENSE +29 -0
  5. data/README +223 -0
  6. data/Rakefile +15 -0
  7. data/Releases +126 -0
  8. data/TODO +6 -0
  9. data/daemons.gemspec +27 -0
  10. data/daemons.tmproj +56 -0
  11. data/examples/call/call.rb +56 -0
  12. data/examples/call/call.rb.log +1 -0
  13. data/examples/call/call_monitor.rb +55 -0
  14. data/examples/daemonize/daemonize.rb +20 -0
  15. data/examples/run/ctrl_crash.rb +17 -0
  16. data/examples/run/ctrl_exec.rb +16 -0
  17. data/examples/run/ctrl_exit.rb +15 -0
  18. data/examples/run/ctrl_keep_pid_files.rb +17 -0
  19. data/examples/run/ctrl_monitor.rb +16 -0
  20. data/examples/run/ctrl_multiple.rb +16 -0
  21. data/examples/run/ctrl_normal.rb +12 -0
  22. data/examples/run/ctrl_ontop.rb +16 -0
  23. data/examples/run/ctrl_optionparser.rb +43 -0
  24. data/examples/run/ctrl_proc.rb +25 -0
  25. data/examples/run/ctrl_proc.rb.output +101 -0
  26. data/examples/run/ctrl_proc_multiple.rb +22 -0
  27. data/examples/run/ctrl_proc_multiple.rb.output +2 -0
  28. data/examples/run/ctrl_proc_simple.rb +17 -0
  29. data/examples/run/myserver.rb +12 -0
  30. data/examples/run/myserver_crashing.rb +14 -0
  31. data/examples/run/myserver_crashing.rb.output +30 -0
  32. data/examples/run/myserver_exiting.rb +8 -0
  33. data/html/classes/Daemonize.html +497 -0
  34. data/html/classes/Daemons.html +683 -0
  35. data/html/classes/Daemons/Application.html +836 -0
  36. data/html/classes/Daemons/ApplicationGroup.html +508 -0
  37. data/html/classes/Daemons/CmdException.html +113 -0
  38. data/html/classes/Daemons/Controller.html +429 -0
  39. data/html/classes/Daemons/Error.html +113 -0
  40. data/html/classes/Daemons/Exception.html +111 -0
  41. data/html/classes/Daemons/Monitor.html +263 -0
  42. data/html/classes/Daemons/Optparse.html +244 -0
  43. data/html/classes/Daemons/Pid.html +339 -0
  44. data/html/classes/Daemons/PidFile.html +441 -0
  45. data/html/classes/Daemons/PidMem.html +126 -0
  46. data/html/classes/Daemons/RuntimeException.html +113 -0
  47. data/html/classes/Daemons/SystemError.html +163 -0
  48. data/html/created.rid +1 -0
  49. data/html/files/README.html +377 -0
  50. data/html/files/Releases.html +342 -0
  51. data/html/files/TODO.html +121 -0
  52. data/html/files/lib/daemons/application_group_rb.html +101 -0
  53. data/html/files/lib/daemons/application_rb.html +110 -0
  54. data/html/files/lib/daemons/cmdline_rb.html +101 -0
  55. data/html/files/lib/daemons/controller_rb.html +101 -0
  56. data/html/files/lib/daemons/daemonize_rb.html +207 -0
  57. data/html/files/lib/daemons/exceptions_rb.html +101 -0
  58. data/html/files/lib/daemons/monitor_rb.html +108 -0
  59. data/html/files/lib/daemons/pid_rb.html +108 -0
  60. data/html/files/lib/daemons/pidfile_rb.html +108 -0
  61. data/html/files/lib/daemons/pidmem_rb.html +108 -0
  62. data/html/files/lib/daemons_rb.html +117 -0
  63. data/html/fr_class_index.html +41 -0
  64. data/html/fr_file_index.html +40 -0
  65. data/html/fr_method_index.html +91 -0
  66. data/html/index.html +24 -0
  67. data/html/rdoc-style.css +208 -0
  68. data/lib/daemons.rb +284 -0
  69. data/lib/daemons/application.rb +376 -0
  70. data/lib/daemons/application_group.rb +152 -0
  71. data/lib/daemons/cmdline.rb +117 -0
  72. data/lib/daemons/controller.rb +137 -0
  73. data/lib/daemons/daemonize.rb +263 -0
  74. data/lib/daemons/exceptions.rb +28 -0
  75. data/lib/daemons/monitor.rb +136 -0
  76. data/lib/daemons/pid.rb +115 -0
  77. data/lib/daemons/pidfile.rb +111 -0
  78. data/lib/daemons/pidmem.rb +10 -0
  79. data/lib/daemons/version.rb +3 -0
  80. data/setup.rb +1360 -0
  81. data/test/call_as_daemon.rb +12 -0
  82. data/test/tc_main.rb +24 -0
  83. data/test/test1.rb +19 -0
  84. data/test/testapp.rb +11 -0
  85. metadata +170 -0
data/daemons.tmproj ADDED
@@ -0,0 +1,56 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>documents</key>
6
+ <array>
7
+ <dict>
8
+ <key>expanded</key>
9
+ <true/>
10
+ <key>name</key>
11
+ <string>daemons</string>
12
+ <key>regexFolderFilter</key>
13
+ <string>!.*/(\.[^/]*|CVS|_darcs|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
14
+ <key>sourceDirectory</key>
15
+ <string></string>
16
+ </dict>
17
+ </array>
18
+ <key>fileHierarchyDrawerWidth</key>
19
+ <integer>200</integer>
20
+ <key>metaData</key>
21
+ <dict>
22
+ <key>html/classes/Daemons.html</key>
23
+ <dict>
24
+ <key>caret</key>
25
+ <dict>
26
+ <key>column</key>
27
+ <integer>28</integer>
28
+ <key>line</key>
29
+ <integer>553</integer>
30
+ </dict>
31
+ <key>firstVisibleColumn</key>
32
+ <integer>0</integer>
33
+ <key>firstVisibleLine</key>
34
+ <integer>533</integer>
35
+ </dict>
36
+ <key>lib/daemons/application_group.rb</key>
37
+ <dict>
38
+ <key>caret</key>
39
+ <dict>
40
+ <key>column</key>
41
+ <integer>0</integer>
42
+ <key>line</key>
43
+ <integer>0</integer>
44
+ </dict>
45
+ <key>firstVisibleColumn</key>
46
+ <integer>0</integer>
47
+ <key>firstVisibleLine</key>
48
+ <integer>61</integer>
49
+ </dict>
50
+ </dict>
51
+ <key>showFileHierarchyDrawer</key>
52
+ <true/>
53
+ <key>windowFrame</key>
54
+ <string>{{419, 58}, {733, 788}}</string>
55
+ </dict>
56
+ </plist>
@@ -0,0 +1,56 @@
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
+
10
+ require 'daemons'
11
+
12
+ testfile = File.expand_path(__FILE__) + '.log'
13
+
14
+
15
+ # On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
16
+ # will be created an the options will be kept within, so you only have to specify
17
+ # <tt>:multiple</tt> once.
18
+ #
19
+
20
+ options = {
21
+ # :ontop => true,
22
+ :multiple => true
23
+ }
24
+
25
+
26
+ Daemons.call(options) do
27
+ File.open(testfile, 'w') {|f|
28
+ f.puts "test"
29
+ }
30
+
31
+ loop { puts "1"; sleep 5 }
32
+ end
33
+ puts "first task started"
34
+
35
+ Daemons.call do
36
+ loop { puts "2"; sleep 4 }
37
+ end
38
+ puts "second task started"
39
+
40
+ # NOTE: this process will exit after 5 seconds
41
+ Daemons.call do
42
+ puts "3"
43
+ sleep 5
44
+ end
45
+ puts "third task started"
46
+
47
+ puts "waiting 20 seconds..."
48
+ sleep(20)
49
+
50
+ # This call would result in an exception as it will try to kill the third process
51
+ # which has already terminated by that time; but using the 'true' parameter forces the
52
+ # stop_all procedure.
53
+ puts "trying to stop all tasks..."
54
+ Daemons.group.stop_all(true)
55
+
56
+ puts "done"
@@ -0,0 +1 @@
1
+ test
@@ -0,0 +1,55 @@
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
+
10
+ require 'daemons'
11
+
12
+ testfile = File.expand_path(__FILE__) + '.log'
13
+
14
+
15
+ # On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
16
+ # will be created an the options will be kept within, so you only have to specify
17
+ # <tt>:multiple</tt> once.
18
+ #
19
+
20
+ options = {
21
+ # :ontop => true,
22
+ :multiple => true,
23
+ :monitor => true
24
+ }
25
+
26
+
27
+ Daemons.call(options) do
28
+ loop { puts "1"; sleep 20 }
29
+ end
30
+ puts "first task started"
31
+
32
+
33
+ # NOTE: this process will exit after 5 seconds
34
+ Daemons.call do
35
+ File.open(testfile, 'a') {|f|
36
+ f.puts "started..."
37
+ puts "2"
38
+
39
+ sleep 5
40
+
41
+ f.puts "...exit"
42
+ }
43
+ end
44
+ puts "second task started"
45
+
46
+ puts "waiting 100 seconds..."
47
+ sleep(100)
48
+
49
+ # This call would result in an exception as it will try to kill the third process
50
+ # which has already terminated by that time; but using the 'true' parameter forces the
51
+ # stop_all procedure.
52
+ puts "trying to stop all tasks..."
53
+ Daemons.group.stop_all(true)
54
+
55
+ puts "done"
@@ -0,0 +1,20 @@
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
+
10
+
11
+ require 'daemons'
12
+
13
+
14
+ testfile = File.expand_path(__FILE__) + '.log'
15
+
16
+ Daemons.daemonize
17
+
18
+ File.open(testfile, 'w') {|f|
19
+ f.write("test")
20
+ }
@@ -0,0 +1,17 @@
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
+
11
+
12
+ options = {
13
+ :log_output => true,
14
+ :backtrace => true
15
+ }
16
+
17
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
@@ -0,0 +1,16 @@
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
+
11
+
12
+ options = {
13
+ :mode => :exec
14
+ }
15
+
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
@@ -0,0 +1,15 @@
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
+
11
+
12
+ options = {
13
+ }
14
+
15
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver_exiting.rb'), options)
@@ -0,0 +1,17 @@
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
+
11
+
12
+ options = {
13
+ :keep_pid_files => true
14
+ }
15
+
16
+
17
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
@@ -0,0 +1,16 @@
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
+
11
+
12
+ options = {
13
+ :monitor => true
14
+ }
15
+
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
@@ -0,0 +1,16 @@
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
+
11
+
12
+ options = {
13
+ :multiple => true
14
+ }
15
+
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
@@ -0,0 +1,12 @@
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
+
11
+
12
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'))
@@ -0,0 +1,16 @@
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
+
11
+
12
+ options = {
13
+ :ontop => true
14
+ }
15
+
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
@@ -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
@@ -0,0 +1,25 @@
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
+
11
+
12
+ options = {
13
+ :multiple => false,
14
+ :ontop => false,
15
+ :backtrace => true,
16
+ :log_output => true,
17
+ :monitor => true
18
+ }
19
+
20
+ Daemons.run_proc('ctrl_proc.rb', options) do
21
+ loop do
22
+ puts 'ping from proc!'
23
+ sleep(3)
24
+ end
25
+ end
@@ -0,0 +1,101 @@
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!