-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorporate danman01's work into donnoman:master #3
base: master
Are you sure you want to change the base?
Changes from all commits
47fb37e
088ebb8
4d899f9
99b4814
79a655f
2dc7d87
2aea39f
ed4d252
7014a04
68ec3aa
5301fbf
67ba75a
f9df481
d032775
cb4ef6d
a3a22a4
91ef792
eee7f52
9517319
174bb8d
13ccfa9
cc6ea8e
ec486cc
7c27909
cbd1164
0f2aa5b
e0cf30b
9d1f5ec
f754f64
910b75b
46a8445
7d37e51
0498f4f
4d2b068
e457cb6
4127a7a
bc7dbcd
1084117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Capistrano::Configuration.instance(true).load do | ||
after "deploy:provision", "monit:install" | ||
after "deploy:restart", "monit:enable", "monit:restart" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# @author Donovan Bray <[email protected]> | ||
require File.expand_path(File.dirname(__FILE__) + '/utilities') | ||
|
||
# This Nginx is targeted for the :app role meant to be acting as a front end | ||
# to a unicorn based application | ||
|
||
# Additions | ||
# https://github.com/newobj/nginx-x-rid-header | ||
# https://github.com/yaoweibin/nginx_syslog_patch | ||
|
||
# Possible Future Additions | ||
# https://support.newrelic.com/kb/features/tracking-front-end-time | ||
|
||
|
||
Capistrano::Configuration.instance(true).load do | ||
|
||
|
||
set :postgresql_host, "localhost" | ||
set :postgresql_user, application | ||
set(:postgresql_password) {Capistrano::CLI.password_prompt "PostgreSQL Password: "} | ||
set(:postgresql_database) {"#{application}_production"} | ||
set(:postgresql_dump_path) {"#{current_path}/tmp"} | ||
set(:postgresql_dump_file) {"#{application}_dump.sql"} | ||
set(:postgresql_local_dump_path) {File.expand_path("../../../tmp", __FILE__) } | ||
set(:postgresql_pid) {"/var/run/postgresql/9.2-main.pid"} | ||
|
||
namespace :postgresql do | ||
desc "Install the latest stable release of PostgreSQL." | ||
task :install, roles: :db, only: {primary: true} do | ||
run "#{sudo} add-apt-repository -y ppa:pitti/postgresql" | ||
run "#{sudo} apt-get -y update" | ||
run "#{sudo} apt-get -y install postgresql libpq-dev" | ||
end | ||
after "postgresql:install", "postgresql:create_database" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. callbacks belong in the hooks, so others requiring the recipe can choose to use your hooks or not. This becomes important in some orchestration because once a hook is defined it can't be removed. |
||
|
||
desc "Create a database for this application." | ||
task :create_database, roles: :db, only: {primary: true} do | ||
run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"} | ||
run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"} | ||
end | ||
after "deploy:provision", "postgresql:install" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same move all callback definitions to hooks.rb |
||
|
||
desc "Generate the database.yml configuration file." | ||
task :setup, roles: :app do | ||
run "mkdir -p #{shared_path}/config" | ||
template "postgresql.yml.erb", "#{shared_path}/config/database.yml" | ||
end | ||
after "postgresql:create_database", "postgresql:setup" | ||
|
||
desc "Symlink the database.yml file into latest release" | ||
task :symlink, roles: :app do | ||
puts "Symlinking database yml file" | ||
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | ||
end | ||
after "deploy:finalize_update", "postgresql:symlink" | ||
|
||
desc "database console" | ||
task :console do | ||
auth = capture "cat #{shared_path}/config/database.yml" | ||
puts "PASSWORD::: #{auth.match(/password: (.*$)/).captures.first}" | ||
hostname = find_servers_for_task(current_task).first | ||
exec "ssh #{hostname} -t 'source ~/.zshrc && psql -U #{application} #{postgresql_database}'" | ||
end | ||
|
||
|
||
namespace :local do | ||
desc "Download remote database to tmp/" | ||
task :download do | ||
dumpfile = "#{postgresql_local_dump_path}/#{postgresql_dump_file}.gz" | ||
get "#{postgresql_dump_path}/#{postgresql_dump_file}.gz", dumpfile | ||
end | ||
|
||
desc "Restores local database from temp file" | ||
task :restore do | ||
auth = YAML.load_file(File.expand_path('../../database.yml', __FILE__)) | ||
dev = auth['development'] | ||
user, pass, database, host = dev['username'], dev['password'], dev['database'], dev['host'] | ||
dumpfile = "#{postgresql_local_dump_path}/#{postgresql_dump_file}" | ||
system "gzip -cd #{dumpfile}.gz > #{dumpfile} && cat #{dumpfile} | psql -U #{user} -h #{host} #{database}" | ||
end | ||
|
||
desc "Dump remote database and download it locally" | ||
task :localize do | ||
remote.dump | ||
download | ||
end | ||
|
||
desc "Dump remote database, download it locally and restore local database" | ||
task :sync do | ||
localize | ||
restore | ||
end | ||
end | ||
|
||
namespace :remote do | ||
desc "Dump remote database" | ||
task :dump do | ||
dbyml = capture "cat #{shared_path}/config/database.yml" | ||
info = YAML.load dbyml | ||
db = info[stage.to_s] | ||
user, pass, database, host = db['username'], db['password'], db['database'], db['host'] | ||
commands = <<-CMD | ||
pg_dump -U #{user} -h #{host} #{database} | \ | ||
gzip > #{postgresql_dump_path}/#{postgresql_dump_file}.gz | ||
CMD | ||
run commands do |ch, stream, data| | ||
if data =~ /Password/ | ||
ch.send_data("#{pass}\n") | ||
end | ||
end | ||
end | ||
|
||
desc "Uploads local sql.gz file to remote server" | ||
task :upload do | ||
dumpfile = "#{postgresql_local_dump_path}/#{postgresql_dump_file}.gz" | ||
upfile = "#{postgresql_dump_path}/#{postgresql_dump_file}.gz" | ||
put File.read(dumpfile), upfile | ||
end | ||
|
||
desc "Restores remote database" | ||
task :restore do | ||
dumpfile = "#{postgresql_dump_path}/#{postgresql_dump_file}" | ||
gzfile = "#{dumpfile}.gz" | ||
dbyml = capture "cat #{shared_path}/config/database.yml" | ||
info = YAML.load dbyml | ||
db = info['production'] | ||
user, pass, database, host = db['username'], db['password'], db['database'], db['host'] | ||
|
||
commands = <<-CMD | ||
gzip -cd #{gzfile} > #{dumpfile} && \ | ||
cat #{dumpfile} | \ | ||
psql -U #{user} -h #{host} #{database} | ||
CMD | ||
|
||
run commands do |ch, stream, data| | ||
if data =~ /Password/ | ||
ch.send_data("#{pass}\n") | ||
end | ||
end | ||
end | ||
|
||
desc "Uploads and restores remote database" | ||
task :sync do | ||
upload | ||
restore | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Capistrano::Configuration.instance(true).load do | ||
after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path | ||
after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code | ||
after "deploy:restart" , "rails:repair_permissions" # fix the permissions to work properly | ||
after "deploy:restart" , "rails:ping" # ping passenger to start the rails instance | ||
end | ||
#after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain your reasoning for removing? Is this a change for everybody or just you. because you could chose to do
instead of
in your deploy.rb and let this file remain unmodified for those who still depend on it. |
||
#after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code | ||
#after "deploy:restart" , "rails:repair_permissions" # fix the permissions to work properly | ||
#after "deploy:restart" , "rails:ping" # ping passenger to start the rails instance | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,7 @@ def addgroup(group,options={}) | |
switches = '' | ||
switches += " --system" if options[:system] | ||
switches += " --gid #{options[:gid]} " if options[:gid] | ||
invoke_command "/usr/sbin/addgroup #{switches} #{group}", :via => run_method | ||
invoke_command "sudo /usr/sbin/addgroup #{switches} #{group}", :via => run_method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in the form of the capistrano sudo helper? ie:
|
||
end | ||
|
||
#utilities.delgroup('deploy') | ||
|
@@ -339,6 +339,10 @@ def handle_command_with_input(local_run_method, shell_command, input_query, resp | |
def deprecated(name,replacement=nil) | ||
raise Capistrano::Error, "#{name} is deprecated, #{replacement ? "see: #{replacment}" : "no replacement" }." | ||
end | ||
|
||
def set_default(name, *args, &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you document an example and it's usage? does this duplicate the _cset capistrano internal method? |
||
set(name, *args, &block) unless exists?(name) | ||
end | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These top comments obviously came from the nginx recipe, and should be removed from the postgresql recipe.
I suggest you update the author tag with your email. But you can omit it if you want. I just think it's good to know who was the brainchild behind each recipe.