Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Mina时无法通过ssh连接到服务器_Ruby On Rails_Ruby_Deployment_Rubygems_Ruby On Rails 5 - Fatal编程技术网

Ruby on rails 使用Mina时无法通过ssh连接到服务器

Ruby on rails 使用Mina时无法通过ssh连接到服务器,ruby-on-rails,ruby,deployment,rubygems,ruby-on-rails-5,Ruby On Rails,Ruby,Deployment,Rubygems,Ruby On Rails 5,我尝试使用来自动化RubyonRails应用程序的部署过程。我在我的config/deploy.rb文件中定义了一个ssh用户,如下所示: set :user, 'unix-username' require 'mina/rails' require 'mina/git' require 'mina/rvm' set :application_name, 'app-name' set :domain, 'ip-address-of-my-server' set :user, 'unix-us

我尝试使用来自动化RubyonRails应用程序的部署过程。我在我的
config/deploy.rb
文件中定义了一个ssh用户,如下所示:

set :user, 'unix-username'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'

set :application_name, 'app-name'
set :domain, 'ip-address-of-my-server'
set :user, 'unix-username'
set :deploy_to, "/home/#{fetch(:user)}/app"
set :repository, 'git@github.com:path/to/repo.git'
set :branch, 'master'
set :rvm_use_path, '/etc/profile.d/rvm.sh'

set :execution_mode, :exec if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/

# Optional settings:
#   set :user, 'foobar'          # Username in the server to SSH to.
#   set :port, '30000'           # SSH port number.
#   set :forward_agent, true     # SSH forward_agent.

set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')

task :remote_environment do
  ruby_version = File.read('.ruby-version').strip
  raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?

  invoke :'rvm:use', ruby_version
end

task :setup do

  in_path(fetch(:shared_path)) do

    command %[mkdir -p config]

    # Create database.yml for Postgres if it doesn't exist
    path_database_yml = "config/database.yml"
    database_yml = %[production:
  database: #{fetch(:user)}
  adapter: postgresql
  pool: 5
  timeout: 5000]
    command %[test -e #{path_database_yml} || echo "#{database_yml}" > #{path_database_yml}]

    # Create secrets.yml if it doesn't exist
    path_secrets_yml = "config/secrets.yml"
    secrets_yml = %[production:\n  secret_key_base:\n    #{`bundle exec rake secret`.strip}]
    command %[test -e #{path_secrets_yml} || echo "#{secrets_yml}" > #{path_secrets_yml}]

    # Remove others-permission for config directory
    command %[chmod -R o-rwx config]
  end

end

desc "Deploys the current version to the server."
task :deploy do
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      # command "sudo service #{fetch(:user)} restart"
    end
  end
end
但是,当我调用
mina setup
时,用户名没有设置,因此脚本尝试使用本地dev maschine的windows用户名ssh到我的服务器(这是默认行为,我知道,当没有提供用户名时)

如何才能成功使用脚本

我的
deploy.rb
文件:

set :user, 'unix-username'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm'

set :application_name, 'app-name'
set :domain, 'ip-address-of-my-server'
set :user, 'unix-username'
set :deploy_to, "/home/#{fetch(:user)}/app"
set :repository, 'git@github.com:path/to/repo.git'
set :branch, 'master'
set :rvm_use_path, '/etc/profile.d/rvm.sh'

set :execution_mode, :exec if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/

# Optional settings:
#   set :user, 'foobar'          # Username in the server to SSH to.
#   set :port, '30000'           # SSH port number.
#   set :forward_agent, true     # SSH forward_agent.

set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')

task :remote_environment do
  ruby_version = File.read('.ruby-version').strip
  raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?

  invoke :'rvm:use', ruby_version
end

task :setup do

  in_path(fetch(:shared_path)) do

    command %[mkdir -p config]

    # Create database.yml for Postgres if it doesn't exist
    path_database_yml = "config/database.yml"
    database_yml = %[production:
  database: #{fetch(:user)}
  adapter: postgresql
  pool: 5
  timeout: 5000]
    command %[test -e #{path_database_yml} || echo "#{database_yml}" > #{path_database_yml}]

    # Create secrets.yml if it doesn't exist
    path_secrets_yml = "config/secrets.yml"
    secrets_yml = %[production:\n  secret_key_base:\n    #{`bundle exec rake secret`.strip}]
    command %[test -e #{path_secrets_yml} || echo "#{secrets_yml}" > #{path_secrets_yml}]

    # Remove others-permission for config directory
    command %[chmod -R o-rwx config]
  end

end

desc "Deploys the current version to the server."
task :deploy do
  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      # command "sudo service #{fetch(:user)} restart"
    end
  end
end

您使用哪一版本的mina?1.2.2,但也使用1.2.3进行了测试。您可以
捆绑打开mina
,并在
/lib/mina/backend/remote.rb
中使用
p fetch(:user)
,或者使用byebug或pry-before或任何其他您喜欢调试问题的技术。请分享用户在ssh方法中的作用。另一个建议是删除与一般mina配置无关的代码,并使用最小配置运行mina,而该配置实际上不起任何作用。通过测试mina是否能正确使用最小配置。通过这种方式,您可以定位问题的根源。