daemons 1.1.9 → 1.4.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.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +207 -0
- data/Releases +85 -24
- data/examples/call/call.rb +13 -16
- data/examples/call/call_monitor.rb +13 -17
- data/examples/daemonize/daemonize.rb +4 -8
- data/examples/run/ctrl_crash.rb +0 -1
- data/examples/run/ctrl_custom_logfiles.rb +18 -0
- data/examples/run/ctrl_exec.rb +0 -1
- data/examples/run/ctrl_exit.rb +0 -1
- data/examples/run/ctrl_keep_pid_files.rb +1 -3
- data/examples/run/ctrl_monitor.rb +0 -1
- data/examples/run/ctrl_monitor_multiple.rb +17 -0
- data/examples/run/ctrl_monitor_nocrash.rb +15 -0
- data/examples/run/ctrl_multiple.rb +0 -1
- data/examples/run/ctrl_ontop.rb +0 -1
- data/examples/run/ctrl_optionparser.rb +5 -7
- data/examples/run/ctrl_proc.rb +8 -9
- data/examples/run/ctrl_proc_multiple.rb +4 -6
- data/examples/run/ctrl_proc_rand.rb +2 -4
- data/examples/run/ctrl_proc_simple.rb +0 -1
- data/examples/run/myserver.rb +0 -1
- data/examples/run/myserver_crashing.rb +5 -5
- data/examples/run/myserver_exiting.rb +2 -2
- data/examples/run/myserver_hanging.rb +4 -5
- data/examples/run/myserver_slowstop.rb +5 -6
- data/lib/daemons/application.rb +235 -229
- data/lib/daemons/application_group.rb +115 -100
- data/lib/daemons/change_privilege.rb +2 -4
- data/lib/daemons/cmdline.rb +75 -62
- data/lib/daemons/controller.rb +36 -54
- data/lib/daemons/daemonize.rb +74 -75
- data/lib/daemons/etc_extension.rb +3 -4
- data/lib/daemons/exceptions.rb +11 -13
- data/lib/daemons/monitor.rb +57 -77
- data/lib/daemons/pid.rb +26 -56
- data/lib/daemons/pidfile.rb +49 -44
- data/lib/daemons/pidmem.rb +5 -9
- data/lib/daemons/reporter.rb +54 -0
- data/lib/daemons/syslogio.rb +240 -0
- data/lib/daemons/version.rb +3 -0
- data/lib/daemons.rb +87 -77
- metadata +111 -46
- data/README +0 -214
- data/Rakefile +0 -90
- data/TODO +0 -2
- data/setup.rb +0 -1360
data/examples/run/ctrl_ontop.rb
CHANGED
@@ -11,7 +11,6 @@ require 'optparse'
|
|
11
11
|
require 'logger'
|
12
12
|
require 'ostruct'
|
13
13
|
|
14
|
-
|
15
14
|
class MyApp < Logger::Application
|
16
15
|
def initialize(args)
|
17
16
|
super(self.class)
|
@@ -19,17 +18,17 @@ class MyApp < Logger::Application
|
|
19
18
|
opts = OptionParser.new do |opts|
|
20
19
|
opts.banner = 'Usage: myapp [options]'
|
21
20
|
opts.separator ''
|
22
|
-
opts.on('-N','--no-daemonize',"Don't run as a daemon") do
|
21
|
+
opts.on('-N', '--no-daemonize', "Don't run as a daemon") do
|
23
22
|
@options.daemonize = false
|
24
23
|
end
|
25
24
|
end
|
26
25
|
@args = opts.parse!(args)
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
def run
|
30
|
-
Daemons.run_proc('myapp',
|
29
|
+
Daemons.run_proc('myapp', :ARGV => @args, :ontop => !@options.daemonize) do
|
31
30
|
puts "@options.daemonize: #{@options.daemonize}"
|
32
|
-
|
31
|
+
$stdout.sync = true
|
33
32
|
loop do
|
34
33
|
print '.'
|
35
34
|
sleep(2)
|
@@ -38,6 +37,5 @@ class MyApp < Logger::Application
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
40
|
myapp = MyApp.new(ARGV)
|
43
|
-
myapp.run
|
41
|
+
myapp.run
|
data/examples/run/ctrl_proc.rb
CHANGED
@@ -8,18 +8,17 @@ end
|
|
8
8
|
|
9
9
|
require 'daemons'
|
10
10
|
|
11
|
-
|
12
11
|
options = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
:multiple => false,
|
13
|
+
:ontop => false,
|
14
|
+
:backtrace => true,
|
15
|
+
:log_output => true,
|
16
|
+
:monitor => true
|
17
|
+
}
|
18
|
+
|
20
19
|
Daemons.run_proc('ctrl_proc.rb', options) do
|
21
20
|
loop do
|
22
21
|
puts 'ping from proc!'
|
23
22
|
sleep(3)
|
24
23
|
end
|
25
|
-
end
|
24
|
+
end
|
@@ -8,15 +8,13 @@ end
|
|
8
8
|
|
9
9
|
require 'daemons'
|
10
10
|
|
11
|
-
|
12
11
|
options = {
|
13
12
|
:log_output => true,
|
14
|
-
:multiple => true,
|
13
|
+
:multiple => true,
|
15
14
|
}
|
16
15
|
|
17
|
-
|
18
16
|
Daemons.run_proc('ctrl_proc_multiple.rb', options) do
|
19
|
-
puts
|
17
|
+
puts 'hello'
|
20
18
|
sleep(5)
|
21
|
-
puts
|
22
|
-
end
|
19
|
+
puts 'done'
|
20
|
+
end
|
@@ -6,10 +6,8 @@ else
|
|
6
6
|
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
9
|
require 'daemons'
|
11
10
|
|
12
|
-
|
13
11
|
Daemons.run_proc('myscript') do
|
14
12
|
loop do
|
15
13
|
file = File.open('/tmp/myscript.log', 'a')
|
@@ -17,7 +15,7 @@ Daemons.run_proc('myscript') do
|
|
17
15
|
# file.write(Random.new.rand) # works without seeding
|
18
16
|
# file.write(rand) # also works, but this is Kernel.rand() so its different
|
19
17
|
file.write("\n")
|
20
|
-
file.close
|
18
|
+
file.close
|
21
19
|
sleep 2
|
22
20
|
end
|
23
|
-
end
|
21
|
+
end
|
data/examples/run/myserver.rb
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
loop do
|
7
7
|
puts 'ping from myserver.rb!'
|
8
|
-
puts 'this example server will crash in
|
9
|
-
|
10
|
-
sleep(
|
11
|
-
|
8
|
+
puts 'this example server will crash in 10 seconds...'
|
9
|
+
|
10
|
+
sleep(10)
|
11
|
+
|
12
12
|
puts 'CRASH!'
|
13
|
-
|
13
|
+
fail 'CRASH!'
|
14
14
|
end
|
@@ -1,19 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
3
|
# This is myserver.rb, an example server that is to be controlled by daemons
|
5
4
|
# and that does nothing really useful at the moment.
|
6
5
|
#
|
7
6
|
# Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts.
|
8
7
|
|
9
|
-
trap('TERM')
|
10
|
-
puts
|
11
|
-
|
8
|
+
trap('TERM') do
|
9
|
+
puts 'received TERM'
|
10
|
+
|
12
11
|
loop do
|
13
12
|
puts 'hanging!'
|
14
13
|
sleep(3)
|
15
14
|
end
|
16
|
-
|
15
|
+
end
|
17
16
|
|
18
17
|
loop do
|
19
18
|
puts 'ping from myserver.rb!'
|
@@ -1,19 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
3
|
# This is myserver_slowstop.rb, an example server that is to be controlled by daemons
|
5
4
|
# and that does nothing really useful at the moment.
|
6
5
|
#
|
7
6
|
# Don't run this script by yourself, it can be controlled by the ctrl*.rb scripts.
|
8
7
|
|
9
|
-
trap('TERM')
|
10
|
-
puts
|
11
|
-
|
8
|
+
trap('TERM') do
|
9
|
+
puts 'received TERM'
|
10
|
+
|
12
11
|
# simulate the slow stopping
|
13
12
|
sleep(10)
|
14
|
-
|
13
|
+
|
15
14
|
exit
|
16
|
-
|
15
|
+
end
|
17
16
|
|
18
17
|
loop do
|
19
18
|
puts 'ping from myserver.rb!'
|