diff options
| author | mo khan <mo@mokhan.ca> | 2014-08-22 22:42:11 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-08-22 22:42:11 -0600 |
| commit | 59ea3fa51f834c13f67e9593b7c0da92c63d58f4 (patch) | |
| tree | a06e20b5011b90dcb985e03b31fa5cbd8b6df9b3 /lib/capistrano | |
| parent | 862f2cb16a498bd284d0ab8feea320adef7b0c2e (diff) | |
start migration to capistrano 3.
Diffstat (limited to 'lib/capistrano')
| -rw-r--r-- | lib/capistrano/tasks/delayed_job.rake | 19 | ||||
| -rw-r--r-- | lib/capistrano/tasks/nginx.rake | 10 | ||||
| -rw-r--r-- | lib/capistrano/tasks/postgresql.rake | 19 | ||||
| -rw-r--r-- | lib/capistrano/tasks/rails.rake | 20 | ||||
| -rw-r--r-- | lib/capistrano/tasks/unicorn.rake | 18 | ||||
| -rw-r--r-- | lib/capistrano/tasks/utility.rake | 17 |
6 files changed, 103 insertions, 0 deletions
diff --git a/lib/capistrano/tasks/delayed_job.rake b/lib/capistrano/tasks/delayed_job.rake new file mode 100644 index 00000000..d6460037 --- /dev/null +++ b/lib/capistrano/tasks/delayed_job.rake @@ -0,0 +1,19 @@ +namespace :delayed_job do + %w[start stop restart status].each do |command| + desc "#{command} delayed_job" + task command do + on roles(:app) do + run "#{sudo} service delayed_job_#{fetch(:application)} #{command}" + end + end + #after "deploy:#{command}", "delayed_job:#{command}" + #after "deploy:finish", "delayed_job:restart" + end + + desc "tail the delayed jobs logs on an app server (cap staging delayed_job:logs)" + task :logs do + on roles(:app) do + stream "tail -f #{fetch(:shared_path)}/log/delayed_job.log" + end + end +end diff --git a/lib/capistrano/tasks/nginx.rake b/lib/capistrano/tasks/nginx.rake new file mode 100644 index 00000000..64eed1d6 --- /dev/null +++ b/lib/capistrano/tasks/nginx.rake @@ -0,0 +1,10 @@ +namespace :nginx do + %w[start stop restart].each do |command| + desc "#{command} nginx" + task command do + on roles(:web) do + run "#{sudo} service nginx #{command}" + end + end + end +end diff --git a/lib/capistrano/tasks/postgresql.rake b/lib/capistrano/tasks/postgresql.rake new file mode 100644 index 00000000..f80d4487 --- /dev/null +++ b/lib/capistrano/tasks/postgresql.rake @@ -0,0 +1,19 @@ +set(:postgresql_host, "localhost") +#set(:postgresql_user) { fetch(:application) } +#set(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " } +#set(:postgresql_database) { "#{fetch(:application)}_#{fetch(:rails_env)}" } + +namespace :postgresql do + desc "Backup the database and copy it locally" + task :backup do + on roles(:db) do + filename = "#{fetch(:rails_env)}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump" + backup_path = "#{fetch(:shared_path)}/backups" + run "mkdir -p #{fetch(:shared_path)}/backups" + + ask(:postgresql_password, "default", echo: false) + run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{fetch(:postgresql_host)} -U deployer cakeside > #{backup_path}/#{filename}" + download("#{backup_path}/#{filename}", "db/backups/", :via => :scp) + end + end +end diff --git a/lib/capistrano/tasks/rails.rake b/lib/capistrano/tasks/rails.rake new file mode 100644 index 00000000..f969ca9f --- /dev/null +++ b/lib/capistrano/tasks/rails.rake @@ -0,0 +1,20 @@ +namespace :rails do + desc "Remote console" + task :console do + on roles(:app) do + run_interactively "bundle exec rails console #{fetch(:rails_env)}" + end + end + + desc "Remote dbconsole" + task :dbconsole do + on roles(:app) do + run_interactively "bundle exec rails dbconsole #{fetch(:rails_env)}" + end + end + + def run_interactively(command, server=nil) + server ||= find_servers_for_task(current_task).first + exec %Q(ssh #{user}@#{server.host} -t 'cd #{current_path} && #{command}') + end +end diff --git a/lib/capistrano/tasks/unicorn.rake b/lib/capistrano/tasks/unicorn.rake new file mode 100644 index 00000000..3b0835ec --- /dev/null +++ b/lib/capistrano/tasks/unicorn.rake @@ -0,0 +1,18 @@ +namespace :unicorn do + %w[start stop restart].each do |command| + desc "#{command} unicorn" + task command do + on roles(:app) do + run "service unicorn_#{fetch(:application)} #{command}" + end + end + #after "deploy:#{command}", "unicorn:#{command}" + end + + desc "tail the logs on an app server (cap staging unicorn:logs)" + task :logs do + on roles(:app) do + stream "tail -f #{fetch(:shared_path)}/log/unicorn.log" + end + end +end diff --git a/lib/capistrano/tasks/utility.rake b/lib/capistrano/tasks/utility.rake new file mode 100644 index 00000000..5d7d0652 --- /dev/null +++ b/lib/capistrano/tasks/utility.rake @@ -0,0 +1,17 @@ +desc "tail the logs on an app server (cap staging logs)" +task :logs do + on roles(:app) do + #stream "tail -f #{fetch(:shared_path)}/log/#{fetch(:rails_env)}.log" + execute "tail -F #{shared_path}/log/#{fetch(:rails_env)}.log" + end +end + +task :sync_logs do + on roles(:app) do + execute "s3cmd sync #{shared_path}/log/#{fetch(:rails_env)}.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/rails/" + execute "s3cmd sync #{shared_path}/log/delayed_job.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/delayed_job/" + execute "s3cmd sync #{shared_path}/log/unicorn.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/unicorn/" + #execute "chown deployer /var/log/nginx/cakeside.*.log-*.gz" + #execute "s3cmd sync /var/log/nginx/cakeside.*.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/nginx/" + end +end |
