daemon-kit 0.1.8pre → 0.1.8rc1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  Daemon Kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.
11
11
 
12
- Using simple built-in generators it is easy to created evented and non-evented daemons that perform a multitude of different tasks.
12
+ Using simple built-in generators it is easy to create evented and non-evented daemons that perform a multitude of different tasks.
13
13
 
14
14
  Supported generators:
15
15
 
data/daemon-kit.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{daemon-kit}
8
- s.version = "0.1.8pre"
8
+ s.version = "0.1.8rc1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kenneth.kalmer@gmail.com"]
12
- s.date = %q{2010-02-05}
12
+ s.date = %q{2010-04-13}
13
13
  s.default_executable = %q{daemon-kit}
14
14
  s.description = %q{daemon-kit aims to simplify creating Ruby daemons by providing a sound application skeleton (through a generator), task specific generators (jabber bot, etc) and robust environment management code.}
15
15
  s.email = %q{kenneth.kalmer@gmail.com}
@@ -138,6 +138,7 @@ Gem::Specification.new do |s|
138
138
  "lib/generators/daemon_kit/capistrano/templates/Capfile",
139
139
  "lib/generators/daemon_kit/capistrano/templates/USAGE",
140
140
  "lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt",
141
+ "lib/generators/daemon_kit/capistrano/templates/config/deploy/logrotate.erb",
141
142
  "lib/generators/daemon_kit/capistrano/templates/config/deploy/production.rb.tt",
142
143
  "lib/generators/daemon_kit/capistrano/templates/config/deploy/staging.rb.tt",
143
144
  "lib/generators/daemon_kit/capistrano/templates/config/environments/staging.rb",
@@ -101,6 +101,49 @@ module DaemonKit
101
101
  def exit!( code = 0 )
102
102
  end
103
103
 
104
+ # http://gist.github.com/304739
105
+ #
106
+ # Stolen from Unicorn::Util
107
+ #
108
+ # This reopens ALL logfiles in the process that have been rotated
109
+ # using logrotate(8) (without copytruncate) or similar tools.
110
+ # A +File+ object is considered for reopening if it is:
111
+ # 1) opened with the O_APPEND and O_WRONLY flags
112
+ # 2) opened with an absolute path (starts with "/")
113
+ # 3) the current open file handle does not match its original open path
114
+ # 4) unbuffered (as far as userspace buffering goes, not O_SYNC)
115
+ # Returns the number of files reopened
116
+ def reopen_logs
117
+ nr = 0
118
+ append_flags = File::WRONLY | File::APPEND
119
+ DaemonKit.logger.info "Rotating logs" if DaemonKit.logger
120
+
121
+ #logs = [STDOUT, STDERR]
122
+ #logs.each do |fp|
123
+ ObjectSpace.each_object(File) do |fp|
124
+ next if fp.closed?
125
+ next unless (fp.sync && fp.path[0..0] == "/")
126
+ next unless (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
127
+
128
+ begin
129
+ a, b = fp.stat, File.stat(fp.path)
130
+ next if a.ino == b.ino && a.dev == b.dev
131
+ rescue Errno::ENOENT
132
+ end
133
+
134
+ open_arg = 'a'
135
+ if fp.respond_to?(:external_encoding) && enc = fp.external_encoding
136
+ open_arg << ":#{enc.to_s}"
137
+ enc = fp.internal_encoding and open_arg << ":#{enc.to_s}"
138
+ end
139
+ DaemonKit.logger.info "Rotating path: #{fp.path}" if DaemonKit.logger
140
+ fp.reopen(fp.path, open_arg)
141
+ fp.sync = true
142
+ nr += 1
143
+ end # each_object
144
+ nr
145
+ end
146
+
104
147
  protected
105
148
 
106
149
  def parse_arguments( args )
@@ -64,7 +64,7 @@ module DaemonKit
64
64
  #end
65
65
  if @data.respond_to?( method_name.to_s )
66
66
  return @data.send( method_name.to_s )
67
- elsif @date.respond_to?( method_name.to_s.gsub(/\-/, '_') )
67
+ elsif @data.respond_to?( method_name.to_s.gsub(/\-/, '_') )
68
68
  return @data.send( method_name.to_s.gsub(/\-/, '_') )
69
69
  end
70
70
  end
@@ -188,7 +188,7 @@ module DaemonKit
188
188
  DaemonKit.logger.info "Log level changed to DEBUG"
189
189
  }
190
190
  configuration.trap("HUP") {
191
- DaemonKit.logger.close
191
+ DaemonKit::Application.reopen_logs
192
192
  }
193
193
  end
194
194
 
@@ -13,16 +13,15 @@ namespace :daemon_kit do
13
13
  version ||= kit.version
14
14
 
15
15
  unless kit
16
- puts "No daemon_kit gem #{version} is installed. Do 'gem list daemon_kit' to see what you have available."
16
+ puts "No daemon_kit gem #{version} is installed. Do 'gem list daemon-kit' to see what you have available."
17
17
  exit
18
18
  end
19
19
 
20
20
  puts "Freezing the gem for DaemonKit #{kit.version}"
21
- rm_rf "vendor/daemon_kit"
22
- mkdir_p "vendor/daemon_kit"
21
+ mkdir_p "vendor"
23
22
 
24
23
  begin
25
- chdir("vendor/daemon_kit") do
24
+ chdir("vendor") do
26
25
  kit.dependencies.select { |g| deps.include? g.name }.each do |g|
27
26
  Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s])
28
27
  mv(Dir.glob("#{g.name}*").first, g.name)
@@ -32,7 +31,7 @@ namespace :daemon_kit do
32
31
  FileUtils.mv(Dir.glob("daemon-kit*").first, "daemon-kit")
33
32
  end
34
33
  rescue Exception
35
- rm_rf "vendor/daemon_kit"
34
+ rm_rf "vendor/daemon-kit"
36
35
  raise
37
36
  end
38
37
  end
@@ -44,10 +43,9 @@ namespace :daemon_kit do
44
43
  commits = "http://github.com/api/v1/yaml/kennethkalmer/daemon-kit/commits/master"
45
44
  url = "http://github.com/kennethkalmer/daemon-kit/zipball/master"
46
45
 
47
- rm_rf "vendor/daemon_kit"
48
- mkdir_p "vendor/daemon_kit"
46
+ rm_rf "vendor/daemon-kit"
49
47
 
50
- chdir 'vendor/daemon_kit' do
48
+ chdir 'vendor' do
51
49
  latest_revision = YAML.load(open(commits))["commits"].first["id"]
52
50
 
53
51
  puts "Downloading DaemonKit from #{url}"
@@ -120,6 +118,6 @@ namespace :daemon_kit do
120
118
  end
121
119
 
122
120
  def copy_framework_template( *args )
123
- src_dir = File.join(DaemonKit.framework_root, 'app_generators', 'daemon_kit', 'templates')
121
+ src_dir = File.join(DaemonKit.framework_root, 'lib', 'generators', 'daemon_kit', 'app', 'templates')
124
122
  cp File.join( src_dir, *args ), File.join( DaemonKit.root, *args )
125
123
  end
data/lib/daemon_kit.rb CHANGED
@@ -13,7 +13,7 @@ $:.unshift( File.dirname(__FILE__).to_absolute_path ) unless
13
13
  $:.include?( File.dirname(__FILE__).to_absolute_path )
14
14
 
15
15
  module DaemonKit
16
- VERSION = '0.1.8pre'
16
+ VERSION = '0.1.8rc1'
17
17
 
18
18
  autoload :Initializer, 'daemon_kit/initializer'
19
19
  autoload :Application, 'daemon_kit/application'
@@ -5,4 +5,4 @@
5
5
  # daemon-kit
6
6
  gem 'daemon-kit'
7
7
 
8
- # For more information on bundler, please visit http://github.com/wycats/bundler
8
+ # For more information on bundler, please visit http://github.com/carlhuda/bundler
@@ -25,7 +25,7 @@ module DaemonKit
25
25
  end
26
26
 
27
27
  def vendor_kit?
28
- File.exists?( "#{DAEMON_ROOT}/vendor/daemon_kit" )
28
+ File.exists?( "#{DAEMON_ROOT}/vendor/daemon-kit" )
29
29
  end
30
30
  end
31
31
 
@@ -38,7 +38,7 @@ module DaemonKit
38
38
 
39
39
  class VendorBoot < Boot
40
40
  def load_initializer
41
- require "#{DAEMON_ROOT}/vendor/daemon_kit/lib/daemon_kit/initializer"
41
+ require "#{DAEMON_ROOT}/vendor/daemon-kit/lib/daemon_kit/initializer"
42
42
  end
43
43
  end
44
44
 
@@ -1,2 +1,3 @@
1
+ #!/usr/bin/env ruby
1
2
  require File.expand_path( '../../config/environment', __FILE__ )
2
3
  require 'daemon_kit/commands/generate'
@@ -1,2 +1,3 @@
1
+ #!/usr/bin/env ruby
1
2
  require File.expand_path( '../../config/environment', __FILE__ )
2
3
  require 'daemon_kit/commands/generate'
@@ -0,0 +1,13 @@
1
+ <%= shared_path %>/log/*.log {
2
+ daily
3
+ missingok
4
+ compress
5
+ rotate 7
6
+ sharedscripts
7
+
8
+ postrotate
9
+ for i in <%= shared_path %>/pids/*.pid; do
10
+ kill -HUP `cat $i`
11
+ done
12
+ endscript
13
+ }
@@ -41,6 +41,9 @@ end
41
41
  # Hook into capistrano's events
42
42
  before "deploy:update_code", "deploy:check"
43
43
 
44
+ # Setup log rotation support with every deploy (safe)
45
+ #after 'deploy:symlink', 'deploy:logrotate'
46
+
44
47
  # Create some tasks related to deployment
45
48
  namespace :deploy do
46
49
 
@@ -50,4 +53,15 @@ namespace :deploy do
50
53
  puts "Current revision: " + out.chomp
51
54
  end
52
55
  end
56
+
57
+ desc "Install log rotation script on server"
58
+ task :logrotate do
59
+ require 'erb'
60
+ upload_path = "#{shared_path}/system/logrotate"
61
+ template = File.read("config/deploy/logrotate.erb")
62
+ file = ERB.new(template).result(binding)
63
+ put file, upload_path, :mode => 0644
64
+ run "if [ -e /etc/logrotate.d ]; then sudo cp #{shared_path}/system/logrotate /etc/logrotate.d/#{name}; fi"
65
+ end
66
+
53
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daemon-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8pre
4
+ version: 0.1.8rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenneth.kalmer@gmail.com
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-05 00:00:00 +02:00
12
+ date: 2010-04-13 00:00:00 +02:00
13
13
  default_executable: daemon-kit
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -171,6 +171,7 @@ files:
171
171
  - lib/generators/daemon_kit/capistrano/templates/Capfile
172
172
  - lib/generators/daemon_kit/capistrano/templates/USAGE
173
173
  - lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt
174
+ - lib/generators/daemon_kit/capistrano/templates/config/deploy/logrotate.erb
174
175
  - lib/generators/daemon_kit/capistrano/templates/config/deploy/production.rb.tt
175
176
  - lib/generators/daemon_kit/capistrano/templates/config/deploy/staging.rb.tt
176
177
  - lib/generators/daemon_kit/capistrano/templates/config/environments/staging.rb