Adds maintenance rake tasks for logrotate and temp file deletion; Adds whenever gem + sample whenever file
This commit is contained in:
parent
139e2af6c8
commit
dc71396a4d
3 changed files with 65 additions and 0 deletions
1
Gemfile
1
Gemfile
|
|
@ -4,6 +4,7 @@ gem 'rails', '3.0.11'
|
||||||
|
|
||||||
gem 'bundler', '>= 1.0.0'
|
gem 'bundler', '>= 1.0.0'
|
||||||
gem 'foreman'
|
gem 'foreman'
|
||||||
|
gem 'whenever'
|
||||||
|
|
||||||
gem 'thin', '~> 1.3.1', :require => false
|
gem 'thin', '~> 1.3.1', :require => false
|
||||||
|
|
||||||
|
|
|
||||||
25
config/schedule.rb.example
Normal file
25
config/schedule.rb.example
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Use this file to easily define all of your cron jobs.
|
||||||
|
#
|
||||||
|
# It's helpful, but not entirely necessary to understand cron before proceeding.
|
||||||
|
# http://en.wikipedia.org/wiki/Cron
|
||||||
|
|
||||||
|
# set :environment, "production"
|
||||||
|
|
||||||
|
# Example:
|
||||||
|
set :output, File.join( File.dirname( __FILE__ ), '..', 'logs', 'scheduled_tasks.log' )
|
||||||
|
|
||||||
|
every 1.day, :at => '3:00 am' do
|
||||||
|
rake 'maintenance:clear_carrierwave_temp_uploads'
|
||||||
|
end
|
||||||
|
|
||||||
|
# every 2.hours do
|
||||||
|
# command "/usr/bin/some_great_command"
|
||||||
|
# runner "MyModel.some_method"
|
||||||
|
# rake "some:great:rake:task"
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# every 4.days do
|
||||||
|
# runner "AnotherModel.prune_old_records"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Learn more: http://github.com/javan/whenever
|
||||||
39
lib/tasks/maintenance.rake
Normal file
39
lib/tasks/maintenance.rake
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Copyright (c) 2011, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
namespace :maintenance do
|
||||||
|
APP_ROOT = File.expand_path( File.join( File.dirname( __FILE__ ), '..', '..') )
|
||||||
|
desc "Clear CarrierWave temp uploads"
|
||||||
|
task :clear_carrierwave_temp_uploads do
|
||||||
|
filename = File.join( APP_ROOT, 'tmp', 'uploads', '*')
|
||||||
|
today_string = Time.now.strftime( '%Y%m%d' )
|
||||||
|
Dir.glob( filename ) do |file|
|
||||||
|
unless file.include?( today_string )
|
||||||
|
FileUtils.rm_rf( file )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Rotate Diaspora logs"
|
||||||
|
task :install_logrotate_config do
|
||||||
|
logrotate_conf = <<-RUBY
|
||||||
|
#{APP_ROOT}/logs/production.log {
|
||||||
|
daily
|
||||||
|
missingok
|
||||||
|
rotate 8
|
||||||
|
compress
|
||||||
|
delaycompress
|
||||||
|
notifempty
|
||||||
|
copytruncate
|
||||||
|
}
|
||||||
|
RUBY
|
||||||
|
begin
|
||||||
|
File.open('/etc/logrotate.d/diaspora') do |fin|
|
||||||
|
fin.write logrotate_conf
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
puts "Could not install logrotate configs. Perhaps you should try running this task as root and ensuring logrotate is installed:\n#{logrotate_conf}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue