daemonz 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,15 +2,15 @@ source :rubygems
2
2
 
3
3
  gem 'posix-spawn', '>= 0.3.6'
4
4
  gem 'simple-daemon', '>= 0.1.2'
5
- gem 'rails', '>= 3.2.0'
5
+ gem 'rails', '>= 3.2.8'
6
6
  gem 'zerg_support', '>= 0.1.5'
7
7
 
8
8
  group :development do
9
- gem 'bundler', '>= 1.0.21'
10
- gem 'flexmock', '>= 0.9.0'
11
- gem 'jeweler', '>= 1.8.3'
9
+ gem 'bundler', '>= 1.2.0'
10
+ gem 'flexmock', '>= 1.0.2'
11
+ gem 'jeweler', '>= 1.8.4'
12
12
  gem 'rake', '>= 0.9.2.2'
13
13
  gem 'rcov', '>= 0', :platform => :mri_18
14
14
  gem 'simplecov', '>= 0', :platform => :mri_19
15
- gem 'sqlite3', '>= 1.3.5'
15
+ gem 'sqlite3', '>= 1.3.6'
16
16
  end
@@ -1,111 +1,111 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- actionmailer (3.2.1)
5
- actionpack (= 3.2.1)
6
- mail (~> 2.4.0)
7
- actionpack (3.2.1)
8
- activemodel (= 3.2.1)
9
- activesupport (= 3.2.1)
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
10
  builder (~> 3.0.0)
11
11
  erubis (~> 2.7.0)
12
- journey (~> 1.0.1)
12
+ journey (~> 1.0.4)
13
13
  rack (~> 1.4.0)
14
- rack-cache (~> 1.1)
14
+ rack-cache (~> 1.2)
15
15
  rack-test (~> 0.6.1)
16
- sprockets (~> 2.1.2)
17
- activemodel (3.2.1)
18
- activesupport (= 3.2.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.8)
18
+ activesupport (= 3.2.8)
19
19
  builder (~> 3.0.0)
20
- activerecord (3.2.1)
21
- activemodel (= 3.2.1)
22
- activesupport (= 3.2.1)
23
- arel (~> 3.0.0)
20
+ activerecord (3.2.8)
21
+ activemodel (= 3.2.8)
22
+ activesupport (= 3.2.8)
23
+ arel (~> 3.0.2)
24
24
  tzinfo (~> 0.3.29)
25
- activeresource (3.2.1)
26
- activemodel (= 3.2.1)
27
- activesupport (= 3.2.1)
28
- activesupport (3.2.1)
25
+ activeresource (3.2.8)
26
+ activemodel (= 3.2.8)
27
+ activesupport (= 3.2.8)
28
+ activesupport (3.2.8)
29
29
  i18n (~> 0.6)
30
30
  multi_json (~> 1.0)
31
- arel (3.0.0)
32
- builder (3.0.0)
31
+ arel (3.0.2)
32
+ builder (3.0.3)
33
33
  erubis (2.7.0)
34
- flexmock (0.9.0)
34
+ flexmock (1.0.2)
35
35
  git (1.2.5)
36
36
  hike (1.2.1)
37
- i18n (0.6.0)
38
- jeweler (1.8.3)
37
+ i18n (0.6.1)
38
+ jeweler (1.8.4)
39
39
  bundler (~> 1.0)
40
40
  git (>= 1.2.5)
41
41
  rake
42
42
  rdoc
43
- journey (1.0.1)
44
- json (1.6.5)
45
- mail (2.4.1)
43
+ journey (1.0.4)
44
+ json (1.7.5)
45
+ mail (2.4.4)
46
46
  i18n (>= 0.4.0)
47
47
  mime-types (~> 1.16)
48
48
  treetop (~> 1.4.8)
49
- mime-types (1.17.2)
50
- multi_json (1.0.4)
49
+ mime-types (1.19)
50
+ multi_json (1.3.6)
51
51
  polyglot (0.3.3)
52
52
  posix-spawn (0.3.6)
53
53
  rack (1.4.1)
54
- rack-cache (1.1)
54
+ rack-cache (1.2)
55
55
  rack (>= 0.4)
56
56
  rack-ssl (1.3.2)
57
57
  rack
58
58
  rack-test (0.6.1)
59
59
  rack (>= 1.0)
60
- rails (3.2.1)
61
- actionmailer (= 3.2.1)
62
- actionpack (= 3.2.1)
63
- activerecord (= 3.2.1)
64
- activeresource (= 3.2.1)
65
- activesupport (= 3.2.1)
60
+ rails (3.2.8)
61
+ actionmailer (= 3.2.8)
62
+ actionpack (= 3.2.8)
63
+ activerecord (= 3.2.8)
64
+ activeresource (= 3.2.8)
65
+ activesupport (= 3.2.8)
66
66
  bundler (~> 1.0)
67
- railties (= 3.2.1)
68
- railties (3.2.1)
69
- actionpack (= 3.2.1)
70
- activesupport (= 3.2.1)
67
+ railties (= 3.2.8)
68
+ railties (3.2.8)
69
+ actionpack (= 3.2.8)
70
+ activesupport (= 3.2.8)
71
71
  rack-ssl (~> 1.3.2)
72
72
  rake (>= 0.8.7)
73
73
  rdoc (~> 3.4)
74
- thor (~> 0.14.6)
74
+ thor (>= 0.14.6, < 2.0)
75
75
  rake (0.9.2.2)
76
76
  rcov (1.0.0)
77
77
  rdoc (3.12)
78
78
  json (~> 1.4)
79
79
  simple-daemon (0.1.2)
80
- simplecov (0.5.4)
81
- multi_json (~> 1.0.3)
80
+ simplecov (0.6.4)
81
+ multi_json (~> 1.0)
82
82
  simplecov-html (~> 0.5.3)
83
83
  simplecov-html (0.5.3)
84
- sprockets (2.1.2)
84
+ sprockets (2.1.3)
85
85
  hike (~> 1.2)
86
86
  rack (~> 1.0)
87
87
  tilt (~> 1.1, != 1.3.0)
88
- sqlite3 (1.3.5)
89
- thor (0.14.6)
88
+ sqlite3 (1.3.6)
89
+ thor (0.16.0)
90
90
  tilt (1.3.3)
91
91
  treetop (1.4.10)
92
92
  polyglot
93
93
  polyglot (>= 0.3.1)
94
- tzinfo (0.3.31)
94
+ tzinfo (0.3.33)
95
95
  zerg_support (0.1.5)
96
96
 
97
97
  PLATFORMS
98
98
  ruby
99
99
 
100
100
  DEPENDENCIES
101
- bundler (>= 1.0.21)
102
- flexmock (>= 0.9.0)
103
- jeweler (>= 1.8.3)
101
+ bundler (>= 1.2.0)
102
+ flexmock (>= 1.0.2)
103
+ jeweler (>= 1.8.4)
104
104
  posix-spawn (>= 0.3.6)
105
- rails (>= 3.2.0)
105
+ rails (>= 3.2.8)
106
106
  rake (>= 0.9.2.2)
107
107
  rcov
108
108
  simple-daemon (>= 0.1.2)
109
109
  simplecov
110
- sqlite3 (>= 1.3.5)
110
+ sqlite3 (>= 1.3.6)
111
111
  zerg_support (>= 0.1.5)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "daemonz"
8
- s.version = "0.3.6"
8
+ s.version = "0.3.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Costan"]
12
- s.date = "2012-02-11"
12
+ s.date = "2012-09-14"
13
13
  s.description = "Works with Facebook."
14
14
  s.email = "victor@costan.us"
15
15
  s.extra_rdoc_files = [
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.homepage = "http://github.com/costan/daemonz"
50
50
  s.licenses = ["MIT"]
51
51
  s.require_paths = ["lib"]
52
- s.rubygems_version = "1.8.15"
52
+ s.rubygems_version = "1.8.24"
53
53
  s.summary = "User authentication for Rails 3 applications."
54
54
 
55
55
  if s.respond_to? :specification_version then
@@ -58,40 +58,40 @@ Gem::Specification.new do |s|
58
58
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
59
  s.add_runtime_dependency(%q<posix-spawn>, [">= 0.3.6"])
60
60
  s.add_runtime_dependency(%q<simple-daemon>, [">= 0.1.2"])
61
- s.add_runtime_dependency(%q<rails>, [">= 3.2.0"])
61
+ s.add_runtime_dependency(%q<rails>, [">= 3.2.8"])
62
62
  s.add_runtime_dependency(%q<zerg_support>, [">= 0.1.5"])
63
- s.add_development_dependency(%q<bundler>, [">= 1.0.21"])
64
- s.add_development_dependency(%q<flexmock>, [">= 0.9.0"])
65
- s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
63
+ s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
64
+ s.add_development_dependency(%q<flexmock>, [">= 1.0.2"])
65
+ s.add_development_dependency(%q<jeweler>, [">= 1.8.4"])
66
66
  s.add_development_dependency(%q<rake>, [">= 0.9.2.2"])
67
67
  s.add_development_dependency(%q<rcov>, [">= 0"])
68
68
  s.add_development_dependency(%q<simplecov>, [">= 0"])
69
- s.add_development_dependency(%q<sqlite3>, [">= 1.3.5"])
69
+ s.add_development_dependency(%q<sqlite3>, [">= 1.3.6"])
70
70
  else
71
71
  s.add_dependency(%q<posix-spawn>, [">= 0.3.6"])
72
72
  s.add_dependency(%q<simple-daemon>, [">= 0.1.2"])
73
- s.add_dependency(%q<rails>, [">= 3.2.0"])
73
+ s.add_dependency(%q<rails>, [">= 3.2.8"])
74
74
  s.add_dependency(%q<zerg_support>, [">= 0.1.5"])
75
- s.add_dependency(%q<bundler>, [">= 1.0.21"])
76
- s.add_dependency(%q<flexmock>, [">= 0.9.0"])
77
- s.add_dependency(%q<jeweler>, [">= 1.8.3"])
75
+ s.add_dependency(%q<bundler>, [">= 1.2.0"])
76
+ s.add_dependency(%q<flexmock>, [">= 1.0.2"])
77
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
78
78
  s.add_dependency(%q<rake>, [">= 0.9.2.2"])
79
79
  s.add_dependency(%q<rcov>, [">= 0"])
80
80
  s.add_dependency(%q<simplecov>, [">= 0"])
81
- s.add_dependency(%q<sqlite3>, [">= 1.3.5"])
81
+ s.add_dependency(%q<sqlite3>, [">= 1.3.6"])
82
82
  end
83
83
  else
84
84
  s.add_dependency(%q<posix-spawn>, [">= 0.3.6"])
85
85
  s.add_dependency(%q<simple-daemon>, [">= 0.1.2"])
86
- s.add_dependency(%q<rails>, [">= 3.2.0"])
86
+ s.add_dependency(%q<rails>, [">= 3.2.8"])
87
87
  s.add_dependency(%q<zerg_support>, [">= 0.1.5"])
88
- s.add_dependency(%q<bundler>, [">= 1.0.21"])
89
- s.add_dependency(%q<flexmock>, [">= 0.9.0"])
90
- s.add_dependency(%q<jeweler>, [">= 1.8.3"])
88
+ s.add_dependency(%q<bundler>, [">= 1.2.0"])
89
+ s.add_dependency(%q<flexmock>, [">= 1.0.2"])
90
+ s.add_dependency(%q<jeweler>, [">= 1.8.4"])
91
91
  s.add_dependency(%q<rake>, [">= 0.9.2.2"])
92
92
  s.add_dependency(%q<rcov>, [">= 0"])
93
93
  s.add_dependency(%q<simplecov>, [">= 0"])
94
- s.add_dependency(%q<sqlite3>, [">= 1.3.5"])
94
+ s.add_dependency(%q<sqlite3>, [">= 1.3.6"])
95
95
  end
96
96
  end
97
97
 
@@ -1,5 +1,5 @@
1
1
  module Daemonz
2
-
2
+
3
3
  end
4
4
 
5
5
  require 'daemonz/config.rb'
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  module Daemonz
5
5
  class << self
6
6
  attr_reader :config
7
-
7
+
8
8
  # Set by the rake tasks.
9
9
  attr_accessor :keep_daemons_at_exit
10
10
  end
@@ -14,7 +14,7 @@ module Daemonz
14
14
  return config[:cached_disabled] if config.has_key? :cached_disabled
15
15
  config[:cached_disabled] = disabled_without_cache!
16
16
  end
17
-
17
+
18
18
  def self.disabled_without_cache!
19
19
  return true if config[:disabled]
20
20
  return true if config[:disabled_in].include? Rails.env.to_s
@@ -22,11 +22,11 @@ module Daemonz
22
22
  suffix == $0[-suffix.length, suffix.length]
23
23
  end
24
24
  end
25
-
26
- # figure out the plugin's configuration
25
+
26
+ # figure out the plugin's configuration
27
27
  def self.configure(config_file, options = {})
28
28
  load_configuration config_file
29
-
29
+
30
30
  config[:root_path] ||= Rails.root
31
31
  if options[:force_enabled]
32
32
  config[:disabled] = false
@@ -39,7 +39,7 @@ module Daemonz
39
39
  end
40
40
  config[:disabled] = false if config[:disabled] == 'false'
41
41
  config[:master_file] ||= Rails.root.join "tmp", "pids", "daemonz.master.pid"
42
-
42
+
43
43
  config[:logger] &&= options[:override_logger]
44
44
  self.configure_logger
45
45
 
@@ -49,7 +49,7 @@ module Daemonz
49
49
  config[:is_master] = Daemonz.claim_master
50
50
  end
51
51
  end
52
-
52
+
53
53
  # load and parse the config file
54
54
  def self.load_configuration(config_file)
55
55
  if File.exist? config_file
@@ -57,15 +57,16 @@ module Daemonz
57
57
  erb_result = ERB.new(file_contents).result
58
58
  @config = YAML.load erb_result
59
59
  @config[:daemons] ||= {}
60
-
60
+
61
61
  config_dir = File.join(File.dirname(config_file), 'daemonz')
62
62
  if File.exist? config_dir
63
63
  Dir.entries(config_dir).each do |entry|
64
- daemons_file = File.join(config_dir, entry)
64
+ next unless entry =~ /^\w/ # Avoid temporary files.
65
+ daemons_file = File.join(config_dir, entry)
65
66
  next unless File.file? daemons_file
66
-
67
+
67
68
  file_contents = File.read daemons_file
68
- erb_result = ERB.new(file_contents).result
69
+ erb_result = ERB.new(file_contents).result
69
70
  daemons = YAML.load erb_result
70
71
  daemons.keys.each do |daemon|
71
72
  if @config[:daemons].has_key? daemon
@@ -80,19 +81,19 @@ module Daemonz
80
81
  @config = { :disabled => true }
81
82
  end
82
83
  end
83
-
84
+
84
85
  class << self
85
86
  attr_reader :daemons
86
87
  end
87
-
88
+
88
89
  # process the daemon configuration
89
- def self.configure_daemons
90
+ def self.configure_daemons
90
91
  @daemons = []
91
92
  config[:daemons].each do |name, daemon_config|
92
93
  next if daemon_config[:disabled]
93
94
  daemon = { :name => name }
94
-
95
- # compute the daemon startup / stop commands
95
+
96
+ # compute the daemon startup / stop commands
96
97
  ['start', 'stop'].each do |command|
97
98
  daemon_binary = daemon_config[:binary] || daemon_config["#{command}_binary".to_sym]
98
99
  if daemon_config[:absolute_binary]
@@ -108,7 +109,7 @@ module Daemonz
108
109
  logger.error "Daemonz ignoring #{name}; the #{command} file is missing"
109
110
  break
110
111
  end
111
-
112
+
112
113
  unless daemon_config[:absolute_binary]
113
114
  begin
114
115
  binary_perms = File.stat(daemon_path).mode
@@ -121,16 +122,16 @@ module Daemonz
121
122
  logger.info e.backtrace.join("\n") + "\n"
122
123
  end
123
124
  end
124
-
125
+
125
126
  daemon_args = daemon_config[:args] || daemon_config["#{command}_args".to_sym]
126
127
  daemon_cmdline = "#{daemon_path} #{daemon_args}"
127
128
  daemon[command.to_sym] = {:path => daemon_path, :cmdline => daemon_cmdline}
128
129
  end
129
130
  next unless daemon[:stop]
130
-
131
+
131
132
  # kill patterns
132
133
  daemon[:kill_patterns] = daemon_config[:kill_patterns] || [daemon[:start][:path]]
133
-
134
+
134
135
  # pass-through params
135
136
  daemon[:pids] = daemon_config[:pids]
136
137
  unless daemon[:pids]
@@ -139,10 +140,10 @@ module Daemonz
139
140
  end
140
141
  daemon[:delay_before_kill] = daemon_config[:delay_before_kill] || 0.2
141
142
  daemon[:start_order] = daemon_config[:start_order]
142
-
143
+
143
144
  @daemons << daemon
144
145
  end
145
-
146
+
146
147
  # sort by start_order, then by name
147
148
  @daemons.sort! do |a, b|
148
149
  if a[:start_order]
@@ -2,19 +2,19 @@
2
2
  module Daemonz
3
3
  # :nodoc: namespace
4
4
  module Generators
5
-
5
+
6
6
  class ConfigGenerator < Rails::Generators::Base
7
7
  def self.source_root
8
8
  @source_root ||= File.expand_path 'templates', File.dirname(__FILE__)
9
9
  end
10
-
10
+
11
11
  def create_configuration
12
12
  copy_file 'config.yml', 'config/daemonz.yml'
13
-
13
+
14
14
  empty_directory 'config/daemonz'
15
15
  copy_file 'prepackaged/ferret.yml', 'config/daemonz/ferret.yml'
16
16
  copy_file 'prepackaged/starling.yml', 'config/daemonz/starling.yml'
17
- end
17
+ end
18
18
  end # class Daemonz::Generators::ConfigGenerator
19
19
 
20
20
  end # namespace Daemonz::Generators
@@ -1,7 +1,7 @@
1
1
  # Configuration file for the daemonz plugin.
2
2
 
3
3
  ---
4
- :daemons:
4
+ :daemons:
5
5
  # Daemon configurations placed here will be read as if they were in a file in
6
6
  # config/daemonz. This is more maintainable if you only have one daemon.
7
7
 
@@ -21,7 +21,7 @@
21
21
 
22
22
  # Daemons will not be started / stopped when the name of the binary that's
23
23
  # loading Rails ($0) is one of the following.
24
- :disabled_for:
24
+ :disabled_for:
25
25
  - 'rake'
26
26
  - 'script/generate'
27
27
  - 'script/destroy'
@@ -31,6 +31,6 @@
31
31
  # rake daemons:start / rake daemons:stop, or you can remove the line below.
32
32
  - 'irb'
33
33
 
34
- # Daemons will not be started for the following environments.
34
+ # Daemons will not be started for the following environments.
35
35
  :disabled_in:
36
36
  - 'test'
@@ -1,6 +1,6 @@
1
1
  # Daemonz example: configuration for ferret.
2
2
  #
3
- # daemonz starts the daemons according to the alphabetic order of their
3
+ # daemonz starts the daemons according to the alphabetic order of their
4
4
  # configuration file names. start_order can be used to override this order.
5
5
  # Daemons will be stopped in the reverse order of their starting order.
6
6
  #
@@ -12,7 +12,7 @@
12
12
  # configuration
13
13
  # * PID files: if the daemon has .pid files, daemonz tries to read the file
14
14
  # and find the corresponding processes, then tree-kills them
15
- # * Process table: if possible, daemonz dumps the process table, looks for the
15
+ # * Process table: if possible, daemonz dumps the process table, looks for the
16
16
  # processes that look like the daemon, and tree-kills them
17
17
  # * Pattern matching: processes whose command lines have the same arguments as
18
18
  # those given to daemon "look like" that daemon
@@ -23,7 +23,7 @@
23
23
 
24
24
  ---
25
25
  ferret:
26
- # Ferret uses different binaries to be started and stopped.
26
+ # Ferret uses different binaries to be started and stopped.
27
27
  :start_binary: script/ferret_server
28
28
  :stop_binary: script/ferret_server
29
29
  # The arguments to be given to the start and stop commands.
@@ -1,6 +1,6 @@
1
1
  # Daemonz example: configuration for running starling.
2
2
  #
3
- # daemonz starts the daemons according to the alphabetic order of their
3
+ # daemonz starts the daemons according to the alphabetic order of their
4
4
  # configuration file names. start_order can be used to override this order.
5
5
  # Daemons will be stopped in the reverse order of their starting order.
6
6
  #
@@ -12,7 +12,7 @@
12
12
  # configuration
13
13
  # * PID files: if the daemon has .pid files, daemonz tries to read the file
14
14
  # and find the corresponding processes, then tree-kills them
15
- # * Process table: if possible, daemonz dumps the process table, looks for the
15
+ # * Process table: if possible, daemonz dumps the process table, looks for the
16
16
  # processes that look like the daemon, and tree-kills them
17
17
  # * Pattern matching: processes whose command lines have the same arguments as
18
18
  # those given to daemon "look like" that daemon
@@ -2,19 +2,19 @@
2
2
  module Daemonz
3
3
  # :nodoc: namespace
4
4
  module Generators
5
-
5
+
6
6
  class DaemonGenerator < Rails::Generators::NamedBase
7
7
  def self.source_root
8
8
  @source_root ||= File.expand_path 'templates', File.dirname(__FILE__)
9
9
  end
10
-
10
+
11
11
  def create_harness
12
12
  empty_directory 'config/daemonz'
13
13
  template "config.yml", "config/daemonz/#{file_name}.yml"
14
-
14
+
15
15
  empty_directory 'script/background'
16
16
  template 'daemon.rb.erb', "script/background/#{file_name}.rb"
17
-
17
+
18
18
  empty_directory 'test/integration'
19
19
  template 'integration_test.rb.erb', "test/integration/#{file_name}_test.rb"
20
20
  end
@@ -1,6 +1,6 @@
1
1
  # Automatically generated daemon configuration for <%= file_name %>.
2
2
  #
3
- # daemonz starts the daemons according to the alphabetic order of their
3
+ # daemonz starts the daemons according to the alphabetic order of their
4
4
  # configuration file names. start_order can be used to override this order.
5
5
  # Daemons will be stopped in the reverse order of their starting order.
6
6
  #
@@ -12,7 +12,7 @@
12
12
  # configuration
13
13
  # * PID files: if the daemon has .pid files, daemonz tries to read the file
14
14
  # and find the corresponding processes, then tree-kills them
15
- # * Process table: if possible, daemonz dumps the process table, looks for the
15
+ # * Process table: if possible, daemonz dumps the process table, looks for the
16
16
  # processes that look like the daemon, and tree-kills them
17
17
  # * Pattern matching: processes whose command lines have the same arguments as
18
18
  # those given to daemon "look like" that daemon
@@ -25,15 +25,15 @@
25
25
  <%= file_name %>:
26
26
  # Pattern for the PID file(s) used by the daemon.
27
27
  :pids: tmp/<%= class_name %>.pid
28
- # The same binary is used to start and stop <% file_name %>.
29
- :binary: script/background/<%= file_name %>.rb
28
+ # The same binary is used to start and stop <% file_name %>.
29
+ :binary: script/background/<%= file_name %>.rb
30
30
  # The arguments to be given to the start and stop commands.
31
31
  :start_args: start <%= '<%= Rails.env %' + '>' %>
32
32
  :stop_args: stop
33
- # Time to wait after sending the stop command, before killing the daemon.
33
+ # Time to wait after sending the stop command, before killing the daemon.
34
34
  :delay_before_kill: 1.0
35
35
  # If this is a consumer of another daemon (like starling), make sure the start
36
- # order index is bigger than the other daemons' start order index.
36
+ # order index is bigger than the other daemons' start order index.
37
37
  :start_order: 1
38
- # daemonz will ignore this daemon configuration when this flag is true
38
+ # daemonz will ignore this daemon configuration when this flag is true
39
39
  :disabled: false
@@ -18,8 +18,8 @@ end
18
18
  require 'simple-daemon'
19
19
  class <%= class_name %> < SimpleDaemon::Base
20
20
  SimpleDaemon::WORKING_DIRECTORY = Rails.root.join 'log'
21
-
22
- def self.start
21
+
22
+ def self.start
23
23
  STDOUT.sync = true
24
24
  @logger = Logger.new(STDOUT)
25
25
  @logger.level = Rails.env.production?
@@ -28,31 +28,31 @@ class <%= class_name %> < SimpleDaemon::Base
28
28
  # This is handy if your daemon queries the database often.
29
29
  ActiveRecord::Base.logger.level = Logger::INFO
30
30
  end
31
-
32
- @logger.info "Starting daemon #{self.name}"
33
-
34
- loop do
31
+
32
+ @logger.info "Starting daemon #{self.name}"
33
+
34
+ loop do
35
35
  begin
36
36
  # TODO: execute some tasks in the background repeatedly
37
-
37
+
38
38
  # YOUR CODE HERE
39
-
39
+
40
40
  # Optional. Sleep between tasks.
41
41
  Kernel.sleep 1
42
42
  rescue Exception => e
43
43
  # This gets thrown when we need to get out.
44
44
  raise if e.kind_of? SystemExit
45
-
45
+
46
46
  @logger.error "Error in daemon #{self.name} - #{e.class.name}: #{e}"
47
47
  @logger.info e.backtrace.join("\n")
48
-
48
+
49
49
  # If something bad happened, it usually makes sense to wait for some
50
50
  # time, so any external issues can settle.
51
51
  Kernel.sleep 5
52
52
  end
53
53
  end
54
54
  end
55
-
55
+
56
56
  def self.stop
57
57
  @logger.info "Stopping daemon #{self.name}"
58
58
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class <%= class_name %>Test < ActionController::IntegrationTest
4
4
  fixtures :all
5
-
5
+
6
6
  # Normally, Rails runs the entire test in a transaction, so the database
7
7
  # changes done in test are isolated from the database changes made by daemons.
8
8
  # The line can be removed if the test and the daemon don't communicate via the
@@ -11,7 +11,7 @@ class <%= class_name %>Test < ActionController::IntegrationTest
11
11
 
12
12
  test "daemon interactions" do
13
13
  # stuff that should be done before the daemon runs (e.g. database setup)
14
-
14
+
15
15
  Daemonz.with_daemons do
16
16
  # test interactions with the daemon
17
17
  end
@@ -2,7 +2,7 @@ module Daemonz
2
2
  # Complex procedure for killing a process or a bunch of process replicas
3
3
  # kill_command is the script that's supposed to kill the process / processes (tried first)
4
4
  # pid_patters are globs identifying PID files (a file can match any of the patterns)
5
- # process_patterns are strings that should show on a command line (a process must match all)
5
+ # process_patterns are strings that should show on a command line (a process must match all)
6
6
  # options:
7
7
  # :verbose - log what gets killed
8
8
  # :script_delay - the amount of seconds to sleep after launching the kill script
@@ -30,7 +30,7 @@ module Daemonz
30
30
  sleep 0.05
31
31
  end
32
32
  end
33
-
33
+
34
34
  # Phase 2: look through PID files and issue kill orders
35
35
  pinfo = process_info()
36
36
  pid_files = pid_patterns.map { |pattern| Dir.glob(pattern) }.flatten
@@ -39,7 +39,7 @@ module Daemonz
39
39
  pid = File.open(fname, 'r') { |f| f.read.strip! }
40
40
  process_cmdline = pinfo[pid][:cmdline]
41
41
  # avoid killing innocent victims
42
- if pinfo[pid].nil? or process_patterns.all? { |pattern| process_cmdline.index pattern }
42
+ if pinfo[pid].nil? or process_patterns.all? { |pattern| process_cmdline.index pattern }
43
43
  logger.warn "Killing #{pid}: #{process_cmdline}" if options[:verbose]
44
44
  Process.kill 'TERM', pid.to_i
45
45
  end
@@ -53,7 +53,7 @@ module Daemonz
53
53
  # prevents crashing if the file is wiped after we call exists?
54
54
  end
55
55
  end
56
-
56
+
57
57
  # Phase 3: look through the process table and kill anything that looks good
58
58
  pinfo = process_info()
59
59
  pinfo.each do |pid, info|
@@ -1,10 +1,10 @@
1
1
  module Daemonz
2
2
  @logger = Rails.logger
3
-
3
+
4
4
  def self.logger
5
5
  @logger || Rails.logger
6
6
  end
7
-
7
+
8
8
  def self.configure_logger
9
9
  case config[:logger]
10
10
  when 'stdout'
@@ -16,7 +16,7 @@ module Daemonz
16
16
  when 'rails'
17
17
  @logger = Rails.logger
18
18
  else
19
- @logger = Rails.logger
19
+ @logger = Rails.logger
20
20
  end
21
21
  end
22
22
  end
@@ -10,18 +10,18 @@ module Daemonz
10
10
  safe_stop :force_enabled => true
11
11
  end
12
12
  end
13
-
13
+
14
14
  # Complete startup used by rake:start and at Rails plug-in startup.
15
15
  def self.safe_start(options = {})
16
16
  daemonz_config = Rails.root.join 'config', 'daemonz.yml'
17
17
  Daemonz.configure daemonz_config, options
18
-
18
+
19
19
  if Daemonz.config[:is_master]
20
20
  Daemonz.configure_daemons
21
21
  Daemonz.start_daemons!
22
22
  end
23
23
  end
24
-
24
+
25
25
  # Complete shutdown used by rake:start and at Rails application exit.
26
26
  def self.safe_stop(options = {})
27
27
  if options[:configure]
@@ -36,36 +36,36 @@ module Daemonz
36
36
  Daemonz.release_master_lock
37
37
  end
38
38
  end
39
-
39
+
40
40
  def self.start_daemons!
41
41
  @daemons.each { |daemon| start_daemon! daemon }
42
42
  end
43
-
43
+
44
44
  def self.stop_daemons!
45
45
  @daemons.reverse.each { |daemon| stop_daemon! daemon }
46
46
  end
47
-
47
+
48
48
  def self.start_daemon!(daemon)
49
49
  # cleanup before we start
50
50
  kill_process_set daemon[:stop][:cmdline], daemon[:pids],
51
51
  daemon[:kill_patterns],
52
52
  :script_delay => daemon[:delay_before_kill],
53
53
  :verbose => true, :force_script => false
54
-
54
+
55
55
  logger.info "Daemonz starting #{daemon[:name]}: #{daemon[:start][:cmdline]}"
56
56
  child = POSIX::Spawn::Child.new daemon[:start][:cmdline]
57
-
57
+
58
58
  unless child.success?
59
59
  exit_code = child.status.exitstatus
60
60
  logger.warn "Daemonz start script for #{daemon[:name]} failed " +
61
61
  "with code #{exit_code}"
62
62
  end
63
63
  end
64
-
64
+
65
65
  def self.stop_daemon!(daemon)
66
66
  kill_process_set daemon[:stop][:cmdline], daemon[:pids],
67
67
  daemon[:kill_patterns],
68
68
  :script_delay => daemon[:delay_before_kill],
69
69
  :verbose => true, :force_script => true
70
- end
70
+ end
71
71
  end
@@ -8,26 +8,26 @@ module Daemonz
8
8
  logger.warn "Master lock removed by someone else"
9
9
  end
10
10
  end
11
-
11
+
12
12
  def self.grab_master_lock
13
13
  loop do
14
14
  File.open(config[:master_file], File::CREAT | File::RDWR) do |f|
15
15
  if f.flock File::LOCK_EX
16
16
  lock_data = f.read
17
- lock_data = lock_data[lock_data.index(/\d/), lock_data.length] if lock_data.index /\d/
17
+ lock_data = lock_data[lock_data.index(/\d/), lock_data.length] if lock_data.index /\d/
18
18
  master = lock_data.split("\n", 2)
19
-
19
+
20
20
  if master.length == 2
21
- master_pid = master[0].to_i
21
+ master_pid = master[0].to_i
22
22
  master_cmdline = master[1]
23
23
  if master_pid != 0
24
24
  master_pinfo = process_info(master_pid)
25
25
  return master_pid if master_pinfo and master_pinfo[:cmdline] == master_cmdline
26
-
27
- logger.info "Old master (PID #{master_pid}) died; breaking master lock"
28
- end
26
+
27
+ logger.info "Old master (PID #{master_pid}) died; breaking master lock"
28
+ end
29
29
  end
30
-
30
+
31
31
  f.truncate 0
32
32
  f.write "#{$PID}\n#{process_info($PID)[:cmdline]}"
33
33
  f.flush
@@ -36,7 +36,7 @@ module Daemonz
36
36
  end
37
37
  end
38
38
  end
39
-
39
+
40
40
  # attempts to claim the master lock
41
41
  def self.claim_master
42
42
  begin
@@ -28,7 +28,7 @@ begin
28
28
  if Sys::ProcTable::VERSION == '0.7.6'
29
29
  raise LoadError, 'Buggy sys/proctable, emulate'
30
30
  end
31
-
31
+
32
32
  module Daemonz::ProcTable
33
33
  def self.ps
34
34
  # We don't use ps_emulation all the time because sys-proctable is
@@ -42,7 +42,7 @@ begin
42
42
  end
43
43
  rescue LoadError
44
44
  # The accelerated version is not available, use the slow version all the time.
45
-
45
+
46
46
  module Daemonz::ProcTable
47
47
  def self.ps
48
48
  self.ps_emulation
@@ -50,11 +50,11 @@ rescue LoadError
50
50
  end
51
51
  end
52
52
 
53
- module Daemonz
53
+ module Daemonz
54
54
  # returns information about a process or all the running processes
55
55
  def self.process_info(pid = nil)
56
56
  info = Hash.new
57
-
57
+
58
58
  Daemonz::ProcTable.ps.each do |process|
59
59
  item = { :cmdline => process.cmdline, :pid => process.pid.to_s }
60
60
 
@@ -64,7 +64,7 @@ module Daemonz
64
64
  return item if item[:pid].to_s == pid.to_s
65
65
  end
66
66
  end
67
-
67
+
68
68
  if pid.nil?
69
69
  return info
70
70
  else
@@ -17,9 +17,9 @@ class Railtie < Rails::Railtie
17
17
  end
18
18
 
19
19
  rake_tasks do
20
- load 'daemonz/tasks/daemonz_tasks.rake'
20
+ load 'daemonz/tasks/daemonz_tasks.rake'
21
21
  end
22
-
22
+
23
23
  generators do
24
24
  require 'daemonz/generators/config/config_generator.rb'
25
25
  require 'daemonz/generators/daemon/daemon_generator.rb'
@@ -2,13 +2,13 @@ namespace :daemons do
2
2
  desc "(testing only) Starts the daemons in config/daemonz.yml"
3
3
  task :start => :environment do
4
4
  Daemonz.safe_start :force_enabled => true, :override_logger => 'stdout'
5
- Daemonz.keep_daemons_at_exit = true
5
+ Daemonz.keep_daemons_at_exit = true
6
6
  end
7
7
 
8
8
  desc "(testing only) Stops the daemons in config/daemonz.yml"
9
9
  task :stop => :environment do
10
10
  Daemonz.safe_stop :force_enabled => true, :configure => true,
11
11
  :override_logger => 'stdout'
12
- Daemonz.keep_daemons_at_exit = true
13
- end
12
+ Daemonz.keep_daemons_at_exit = true
13
+ end
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemonz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-11 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: posix-spawn
16
- requirement: &12292480 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.3.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12292480
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.6
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: simple-daemon
27
- requirement: &12291500 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: 0.1.2
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *12291500
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.2
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rails
38
- requirement: &12307720 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
42
52
  - !ruby/object:Gem::Version
43
- version: 3.2.0
53
+ version: 3.2.8
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *12307720
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.8
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: zerg_support
49
- requirement: &12306520 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,43 +69,63 @@ dependencies:
54
69
  version: 0.1.5
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *12306520
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.1.5
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: bundler
60
- requirement: &12305380 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
64
84
  - !ruby/object:Gem::Version
65
- version: 1.0.21
85
+ version: 1.2.0
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *12305380
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.0
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: flexmock
71
- requirement: &12303700 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
75
100
  - !ruby/object:Gem::Version
76
- version: 0.9.0
101
+ version: 1.0.2
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *12303700
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.2
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: jeweler
82
- requirement: &13456480 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
86
116
  - !ruby/object:Gem::Version
87
- version: 1.8.3
117
+ version: 1.8.4
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *13456480
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 1.8.4
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: rake
93
- requirement: &13455300 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: 0.9.2.2
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *13455300
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 0.9.2.2
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: rcov
104
- requirement: &13453860 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *13453860
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: simplecov
115
- requirement: &13452680 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,18 +165,28 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *13452680
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: sqlite3
126
- requirement: &13451240 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ! '>='
130
180
  - !ruby/object:Gem::Version
131
- version: 1.3.5
181
+ version: 1.3.6
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *13451240
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: 1.3.6
135
190
  description: Works with Facebook.
136
191
  email: victor@costan.us
137
192
  executables: []
@@ -183,7 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
238
  version: '0'
184
239
  segments:
185
240
  - 0
186
- hash: -1622779978803712396
241
+ hash: 4130437893997824476
187
242
  required_rubygems_version: !ruby/object:Gem::Requirement
188
243
  none: false
189
244
  requirements:
@@ -192,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
247
  version: '0'
193
248
  requirements: []
194
249
  rubyforge_project:
195
- rubygems_version: 1.8.15
250
+ rubygems_version: 1.8.24
196
251
  signing_key:
197
252
  specification_version: 3
198
253
  summary: User authentication for Rails 3 applications.