Wie Rails 2.3.2 app mit Capistrano von oben (für FastCGI) implementieren?
-
22-08-2019 - |
Frage
Disclaimer:. Ich bin ein noob Rails und Capistrano (aber eine Zwischen .NET C # -Entwickler) versucht, mehr zu lernen
i have been haben die härteste Zeit ein Capistrano Entwicklungsprozess Set-up zu bekommen. hier ist, was ich bisher für meine deploy.rb haben:
set :application, "MyAppName"
set :domain, "domainname"
set :user, "userid"
set :repository, "svn+ssh://#{user}@#{domain}/home/#{user}/svn/#{application}/trunk"
set :rails_env, :production
set :chmod755, %w(app config db lib public vendor script tmp public/dispatch.cgi public/dispatch.fcgi public/dispatch.rb)
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :deploy_via, :checkout
set :group_writable, false
default_run_options[:pty] = true
role :app, domain
role :web, domain
role :db, domain, :primary => true
hier ist mein Capfile:
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
namespace :deploy do
task :restart, :roles => :app do
run "#{current_path}/script/process/reaper --dispatcher=dispatch.fcgi"
end
desc "Set the proper permissions for directories and files on HostingRails accounts"
task :after_deploy do
run(chmod755.collect do |item|
"chmod 755 #{current_path}/#{item}"
end.join(" && "))
end
end
- Rails 2.3.2 nicht das Skript / Prozessverzeichnis hat so die Neustart Aufgabe überhaupt nicht funktioniert. Wie kann ich dieses Problem beheben?
- Gibt es eine Möglichkeit, die RAILS_ENV Variable in environment.rb zu auf „Produktion“, wenn die Anwendung bereitgestellt wird ( „eingestellt: RAILS_ENV,: Produktion“ tut es nicht) ?
- Auch bin ich etwas anderes aus diesen 2 Dateien fehlt?
Lösung
Hier ist mein deploy.rb, was nicht wirklich wurde in einer langen Zeit aktualisiert hat. Ich betreiben zwei sed Befehle, um die Umgebung in meiner einzustellen: after_update_code Aufgabe. Ich bin sicher, es gibt einen einfacheren Weg, es zu tun, aber das ist meine aktuelle Methode.
require 'erb'
before "deploy:setup", :db
after "deploy:update_code", "db:symlink"
after "deploy", "deploy:cleanup"
def prompt_with_default(var, default)
set(var) do
Capistrano::CLI.ui.ask "Enter #{var} [#{default}] : "
end
set var, default if eval("#{var.to_s}.empty?")
end
default_run_options[:pty] = true
set :rake, "/usr/local/bin/rake"
set :user, "your username"
set :application, "application name"
set :repository, "svn repository path"
set :host, "domain name"
set :db_host, "DB host name"
set :db_user, "DB user name"
set :db_prefix, "any DB name prefix your host might require"
set :rails_env, "production"
set :deploy_to, "/home/username/rails/#{host}" # your deployment directory
role :app, host
role :web, host
role :db, host, :primary => true
set :use_sudo, false
set :checkout, "export"
#
# TASKS
#
desc "Tasks to execute after code update"
task :after_update_code, :roles => [:app, :db, :web] do
# Make sure we're running in production
run "sed -i -e '/ENV.*RAILS_ENV/s/# //' #{release_path}/config/environment.rb"
run "sed -i -e '/ENV.*RAILS_ENV/s/production/#{rails_env}/' #{release_path}/config/environment.rb"
# Add banned IPs
deny_lines = []
File.readlines("#{release_path}/config/banned_ips").each {|ip|
deny_lines << "deny from #{ip}"
}
ip_ban_block = <<EOBAN
# Bannination
order allow,deny
#{deny_lines.join}
allow from all
EOBAN
run "sed -i -e 's/# BANNED IPS/#{ip_ban_block}/' #{release_path}/public/.htaccess"
run "chmod +x #{release_path}/script/runner"
run "chmod +x #{release_path}/script/process/reaper"
run "chmod +x #{release_path}/script/process/spawner"
run "chmod 755 #{release_path}/public/dispatch.*"
end
desc "Restarting after deployment"
task :after_deploy, :roles => [:app, :db, :web] do
run "cd #{current_path} && rake RAILS_ENV=production db:sessions:clear tmp:clear"
# fix permissions
run "dos2unix #{release_path}/public/dispatch.*"
run "dos2unix #{release_path}/public/.htaccess"
run "chmod -R 755 #{release_path}"
run "chmod -R 775 #{release_path}/log #{release_path}/tmp #{release_path}/script"
run "find #{release_path}/ | xargs touch"
run "touch #{deploy_to}/current/public/dispatch.fcgi"
end
desc "Restarting after rollback"
task :after_rollback, :roles => [:app, :db, :web] do
run "touch #{deploy_to}/current/public/dispatch.fcgi"
end
namespace :db do
desc "Create database yaml in shared path"
task :default do
prompt_with_default(:db_password, "")
db_config = ERB.new <<-EOF
base: &base
adapter: mysql
port: 3306
host: #{db_host}
username: #{db_user}
password: #{db_password}
development:
database: #{db_prefix}#{application}development
<<: *base
test:
database: #{db_prefix}#{application}test
<<: *base
production:
database: #{db_prefix}#{application}production
<<: *base
EOF
run "mkdir -p #{shared_path}/config"
put db_config.result, "#{shared_path}/config/database.yml"
end
desc "Make symlink for database yaml"
task :symlink do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
Nachdem ich meine Variablen einrichten, ich habe einen Bash-Skript, das ausgeführt wird:
svn export $svn_path . --force
cap deploy
Das wird mich zweimal nach meinem Passwort fragen. Einmal für aus dem SVN Export und einmal als Aufforderung automatisch meine database.yml in dem gemeinsamen Weg zu erzeugen.
Andere Tipps
meine Antwort aktualisiert, siehe # 3 ...
Ich verwende FastCGI nicht für den Einsatz, aber ein paar Dinge, die in den Sinn kommen:
- Die Prozess Skripte wurden aus Rails Kern bewegt und in ein Plugin , die Sie von GitHub greifen kann.
-
an meinem deploy.rb Datei suchen, werden Sie wahrscheinlich die RAILS_ENV Umgebungsvariable in das Skript über die Befehlszeile übergeben müssen, ähnlich wie:
run #{current_path}/script/process/reaper RAILS_ENV=#{rails_env} --dispatcher=dispatch.fcgi
- EDIT: Eigentlich ist es etwas seltsam Ihre Aufgaben im Capfile haben statt deploy.rb - obwohl dieses Thema auf der Capistrano Google-Gruppe , ist es nicht völlig verpönt. Bis zu Ihnen / Ihrem Team, nehme ich an.
Hope diese Punkte, die Sie in der richtigen Richtung.