我跟踪瑞恩的屏风并部署到VPS。所以我使用Unicorn + nginx + github +Ubuntu12.04LTS+ capistrano。此外,我还使用i18n翻译应用程序。
我还想注意一下,我使用载波进行图片上传。载波将图像保存在VPS上。当我上传图片时,它工作得很好,上传的图片也会出现。
但是每次我在服务器上部署新的更改时,我的所有图片都会被破坏。它真的很满。我尝试手动重新启动nginx:
sudo service nginx restart我试着重新启动Unicorn:
/etc/init.d/unicorn_Chirch_app restart也没什么用。
当我试图手动打开我的破页时,上面写着:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.当我试图在控制台中找到图片时:
> Photo.all
> => [#<Photo id: 3, description: nil, created_at: "2013-01-21 11:14:01", updated_at: "2013-01-21 11:14:01", image: "1320700703588.jpg">, #<Photo id: 4, description: nil, created_at: "2013-01-21 11:14:01", updated_at: "2013-01-21 11:14:01", image: "Seasonscape_by_alexiuss.jpg">, #<Photo id: 5, description: nil, created_at: "2013-01-21 11:30:30", updated_at: "2013-01-21 11:30:30", image: "Seasonscape_by_alexiuss.jpg">]据我所知,它们应该存在。
来自日志的错误:
Started GET "/ru/uploads%2Fphoto%2Fimage%2F4%2FSeasonscape_by_alexiuss" for 89.178.205.47 at 2013-01-21 11:31:17 +0000
ActionController::RoutingError (No route matches [GET] "/ru/uploads%2Fphoto%2Fimage%2F4%2FSeasonscape_by_alexiuss"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.4) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.4) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
railties (3.2.8) lib/rails/railtie/configurable.rb:30:in `method_missing'
unicorn (4.5.0) lib/unicorn/http_server.rb:552:in `process_client'
unicorn (4.5.0) lib/unicorn/http_server.rb:628:in `worker_loop'
unicorn (4.5.0) lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
unicorn (4.5.0) lib/unicorn/http_server.rb:511:in `maintain_worker_count'
unicorn (4.5.0) lib/unicorn/http_server.rb:277:in `join'
unicorn (4.5.0) bin/unicorn:121:in `<top (required)>'
/home/deployer/apps/My_app/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
/home/deployer/apps/My_app/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'我的config/deploy.rb
require "bundler/capistrano"
server "my_ip_here", :web, :app, :db, primary: true
set :application, "My_app"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@github.com:MyName/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end发布于 2013-01-21 12:54:18
好吧,我找到解决办法了。出现此问题是因为我没有更改默认文件夹以保留图像。您可以在public/uploads中找到默认文件夹。这意味着每个cap deploy将创建一个不包含旧文件的新的空文件夹。
要解决这个问题,您应该创建另一个不存在于应用程序中的文件夹。我选择了最简单的方法。我创造了辛林克。
我的脚步:
1)在服务器上,转到应用程序的共享文件夹(它是通过capistrano自动生成的)。然后创建文件夹以保存新图像:
$ mkdir uploads2)为创建的文件夹赋予必要的权限:
$ sudo chmod 775 uploads3)在您的本地计算机上的config/ployy.rb中添加:
task :symlink_config, roles: :app do
...
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end4)然后推动git并部署:
$ git push
$ cap deploy:symlink
$ cap deploy现在一切都很好。
发布于 2013-02-21 00:34:34
好样的!我延长了你的卡斯特拉诺食谱。
# config/recipes/carrierwave.rb
namespace :carrierwave do
task :uploads_folder do
run "mkdir -p #{shared_path}/uploads"
run "#{sudo} chmod 775 #{shared_path}/uploads"
end
after 'deploy:setup', 'carrierwave:uploads_folder'
task :symlink do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
after 'deploy', 'carrierwave:symlink'
endhttps://stackoverflow.com/questions/14437733
复制相似问题