使用 Capistrano 的 Rails 服务器上 Ruby 的挂载点错误

Mountpoint error in Ruby on Rails server using Capistrano

我正在尝试使用 capistrano 自动部署应用程序。我几乎完成了除 s3 挂载和卸载配方之外的所有任务。

这是我写的食谱,它在某些条件下有效,在某些条件下无效。但是食谱中使用的命令运行如果我手动登录服务器并自己执行它们。

desc "Mounting S3 for the first time"
    task :mounting_s3 do
        on %w(uat2_sub1 uat2_main), in: :sequence, wait: 5 do |host|
            as 'cc' do
                within '/var/www/test_cap/current' do
                    code_folder = "/var/www/test_cap/current"
                    path = "/var/www/test_cap/current/public/system"
                    unmount_path = "/var/www/test_cap/shared/public/system"

                    # check first if public/system exists
                    puts "** Checking if public/system folder exists on #{host}"
                    if test("[ -d #{path} ]")
                        puts "** public/system folder exists.."
                        puts "** Checking if S3 is mounted"
                        result = execute! "mountpoint #{path}"
                        puts "result #{result}"
                        if result.match('is a mountpoint') != nil
                            puts "** S3 is mounted at #{path} on #{host}"
                            puts "** unmounting s3 at #{unmount_path}"
                            execute! "fusermount -u #{unmount_path}"
                            puts "** s3 unmounted at #{unmount_path} on #{host}"
                        elsif result.match('is not a mountpoint') != nil
                            puts "** #{path} is not a mountpoint on #{host}"    
                        end 
                    else
                        puts "** public/system folder does not exists.."
                        puts "** Mounting S3"
                        execute! "cd #{code_folder} && s3fs cc-system-uat #{path}"  
                    end 
                end
            end
        end 
    end

如果我自己从服务器安装了 s3,我可以使用 fusermount -u 从 capistrano 卸载 S3

同样,如果我自己从服务器上卸载了 s3,我可以从 capistrano 挂载 s3

我运行以cc 用户 的身份执行所有命令。我仍然不明白为什么会出现以下错误。在日志中可以看到 public/system 不是挂载点,但我无法从该点继续前进。因为我想将 mountpoint "public/system" 的结果存储在一个变量中,然后执行不同的任务。

** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env 
** Invoke deploy:mounting_s3 (first_time)
** Execute deploy:mounting_s3
** Checking if public/system folder exists on uat2_sub1
** public/system folder exists..
** Checking if S3 is mounted
00:00 deploy:mounting_s3
      01 mountpoint /var/www/test_cap/current/public/system
      01 /var/www/test_cap/current/public/system is not a mountpoint
cap aborted!
Exception while executing on host uat2_sub1: mountpoint /var/www/test_cap/current/public/system exit status: 1
mountpoint /var/www/test_cap/current/public/system stdout: /var/www/test_cap/current/public/system is not a mountpoint
mountpoint /var/www/test_cap/current/public/system stderr: Nothing written
/home/xyz/.rvm/gems/ruby-2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/sequential.rb:31:in `rescue in run_backend'

这个 raise_on_non_zero_exit: false 选项修复了它。如果没有输出,实际上捕获会抛出错误。

result = capture "cd #{code_folder} && mountpoint public/system" , raise_on_non_zero_exit: false