Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.

Commit 49969b3

Browse files
rabidtestersethvargo
authored andcommitted
[COOK-3616] Use logrotate LWRP for symlinking in rails
Signed-off-by: Seth Vargo <sethvargo@gmail.com>
1 parent bb7d976 commit 49969b3

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
depends "application", "~> 3.0"
1414
depends "runit", "~> 1.0"
15+
depends "logrotate", "~> 1.0"

providers/rails.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
"database.yml" => "config/database.yml"
4646
})
4747

48+
49+
if new_resource.symlink_logs
50+
new_resource.purge_before_symlink.push("log")
51+
new_resource.symlinks.update({"log" => "log"})
52+
end
53+
4854
end
4955

5056
action :before_deploy do
@@ -59,6 +65,8 @@
5965

6066
action :before_migrate do
6167

68+
symlink_logs if new_resource.symlink_logs
69+
6270
if new_resource.bundler
6371
Chef::Log.info "Running bundle install"
6472
directory "#{new_resource.path}/shared/vendor_bundle" do
@@ -183,3 +191,20 @@ def create_database_yml
183191
)
184192
end
185193
end
194+
195+
def symlink_logs
196+
resource = new_resource
197+
198+
directory "#{resource.path}/shared/log" do
199+
owner resource.owner
200+
group resource.group
201+
end
202+
203+
logrotate_app resource.name do
204+
cookbook "logrotate"
205+
path "#{resource.path}/shared/#{resource.environment_name}.log"
206+
frequency "daily"
207+
rotate 30
208+
create "666 #{resource.owner} #{resource.group}"
209+
end
210+
end

resources/rails.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
attribute :bundle_command, :kind_of => [String, NilClass], :default => "bundle"
3131
attribute :precompile_assets, :kind_of => [NilClass, TrueClass, FalseClass], :default => nil
3232
attribute :use_omnibus_ruby, :kind_of => [TrueClass, FalseClass], :default => true
33+
attribute :symlink_logs, :kind_of => [TrueClass, FalseClass], :default => false
3334

3435
def database(*args, &block)
3536
@database ||= Mash.new

0 commit comments

Comments
 (0)