ghazel-daemons 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ * write the README (2005-02-07) *DONE*
2
+ * write some real tests (2005-02-08)
3
+ * document the new options (2005-03-14) *DONE*
4
+ * start/stop with --force options (2005-04-05)
5
+ * option to give some console output on start/stop commands (2005-04-05)
6
+
@@ -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,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!