daemons 1.1.9 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +207 -0
  4. data/Releases +85 -24
  5. data/examples/call/call.rb +13 -16
  6. data/examples/call/call_monitor.rb +13 -17
  7. data/examples/daemonize/daemonize.rb +4 -8
  8. data/examples/run/ctrl_crash.rb +0 -1
  9. data/examples/run/ctrl_custom_logfiles.rb +18 -0
  10. data/examples/run/ctrl_exec.rb +0 -1
  11. data/examples/run/ctrl_exit.rb +0 -1
  12. data/examples/run/ctrl_keep_pid_files.rb +1 -3
  13. data/examples/run/ctrl_monitor.rb +0 -1
  14. data/examples/run/ctrl_monitor_multiple.rb +17 -0
  15. data/examples/run/ctrl_monitor_nocrash.rb +15 -0
  16. data/examples/run/ctrl_multiple.rb +0 -1
  17. data/examples/run/ctrl_ontop.rb +0 -1
  18. data/examples/run/ctrl_optionparser.rb +5 -7
  19. data/examples/run/ctrl_proc.rb +8 -9
  20. data/examples/run/ctrl_proc_multiple.rb +4 -6
  21. data/examples/run/ctrl_proc_rand.rb +2 -4
  22. data/examples/run/ctrl_proc_simple.rb +0 -1
  23. data/examples/run/myserver.rb +0 -1
  24. data/examples/run/myserver_crashing.rb +5 -5
  25. data/examples/run/myserver_exiting.rb +2 -2
  26. data/examples/run/myserver_hanging.rb +4 -5
  27. data/examples/run/myserver_slowstop.rb +5 -6
  28. data/lib/daemons/application.rb +235 -229
  29. data/lib/daemons/application_group.rb +115 -100
  30. data/lib/daemons/change_privilege.rb +2 -4
  31. data/lib/daemons/cmdline.rb +75 -62
  32. data/lib/daemons/controller.rb +36 -54
  33. data/lib/daemons/daemonize.rb +74 -75
  34. data/lib/daemons/etc_extension.rb +3 -4
  35. data/lib/daemons/exceptions.rb +11 -13
  36. data/lib/daemons/monitor.rb +57 -77
  37. data/lib/daemons/pid.rb +26 -56
  38. data/lib/daemons/pidfile.rb +49 -44
  39. data/lib/daemons/pidmem.rb +5 -9
  40. data/lib/daemons/reporter.rb +54 -0
  41. data/lib/daemons/syslogio.rb +240 -0
  42. data/lib/daemons/version.rb +3 -0
  43. data/lib/daemons.rb +87 -77
  44. metadata +111 -46
  45. data/README +0 -214
  46. data/Rakefile +0 -90
  47. data/TODO +0 -2
  48. data/setup.rb +0 -1360
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :multiple => true
14
13
  }
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
12
  :ontop => true
14
13
  }
@@ -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',{:ARGV => @args, :ontop => !@options.daemonize}) do
29
+ Daemons.run_proc('myapp', :ARGV => @args, :ontop => !@options.daemonize) do
31
30
  puts "@options.daemonize: #{@options.daemonize}"
32
- STDOUT.sync = true
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
@@ -8,18 +8,17 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  options = {
13
- :multiple => false,
14
- :ontop => false,
15
- :backtrace => true,
16
- :log_output => true,
17
- :monitor => true
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 "hello"
17
+ puts 'hello'
20
18
  sleep(5)
21
- puts "done"
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
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  require 'daemons'
10
10
 
11
-
12
11
  Daemons.run_proc('ctrl_proc_simple.rb') do
13
12
  loop do
14
13
  puts 'ping from proc!'
@@ -1,6 +1,5 @@
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
  #
@@ -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 3 seconds...'
9
-
10
- sleep(3)
11
-
8
+ puts 'this example server will crash in 10 seconds...'
9
+
10
+ sleep(10)
11
+
12
12
  puts 'CRASH!'
13
- raise 'CRASH!'
13
+ fail 'CRASH!'
14
14
  end
@@ -1,8 +1,8 @@
1
1
  loop do
2
2
  puts 'ping from myserver.rb!'
3
3
  puts 'this example server will exit in 3 seconds...'
4
-
4
+
5
5
  sleep(3)
6
-
6
+
7
7
  Process.exit
8
8
  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 "received TERM"
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 "received TERM"
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!'