Capostrano: cap прерван! Не знаю, как создать задачу ‘start’ (см. Список доступных задач с помощью `cap —tasks`)

#ruby-on-rails #puma #rbenv #capistrano3

#ruby-on-rails #puma #rbenv #capistrano3

Вопрос:

в Интернете найдено много проблем с этой проблемой, но я не нашел ни одной, которая могла бы решить мою проблему, и мне трудно понять все.

Это моя единственная проблема.

Я начал переписывать приложение ruby on rails, используя rbenv. Я хочу попробовать развернуть это приложение с помощью Capistrano Puma и Nginx (нужен ли мне также Passenger или я могу использовать только Puma?)

Я написал свой проект на локальном компьютере. и теперь я пытаюсь развернуть ее на сервере. но с самого начала у меня возникла эта проблема с конфигурацией Capistrano.

Здесь что не так?

 $ cap --tasks --trace
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'start' (See the list of available tasks with `cap --tasks`)
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task_manager.rb:59:in `[]'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:405:in `[]'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/dsl/task_enhancements.rb:7:in `before'
/home/deploy/ecran-village-plannings/config/deploy.rb:85:in `block in <top (required)>'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task_manager.rb:232:in `in_namespace'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/dsl_definition.rb:141:in `namespace'
/home/deploy/ecran-village-plannings/config/deploy.rb:76:in `<top (required)>'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_module.rb:29:in `load'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/rake_module.rb:29:in `load_rakefile'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/default_loader.rb:11:in `load'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:781:in `load_imports'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/application.rb:105:in `load_imports'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:711:in `raw_load_rakefile'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:104:in `block in load_rakefile'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:103:in `load_rakefile'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:82:in `block in run'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/application.rb:14:in `run'
/home/deploy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/bin/cap:3:in `<top (required)>'
/home/deploy/.rbenv/versions/2.7.2/bin/cap:23:in `load'
/home/deploy/.rbenv/versions/2.7.2/bin/cap:23:in `<main>'
 

Вот мои файлы:

Gemfile

 source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.2'

gem 'rails-i18n'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'sorcery'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# gem "dotenv-rails"

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development, :production do
  #Add Capistrano
  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rbenv' 
  gem 'capistrano3-puma', github: "seuros/capistrano-puma"
  gem 'capistrano-nginx'
  gem 'capistrano-ext'
  
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end
 

Capfile — Файл

 require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require "capistrano/rails/migrations"
require 'capistrano/rbenv'
require 'capistrano/nginx'
require 'capistrano/puma'
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Nginx
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
# require "capistrano/scm/git"
# install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

#set :rbenv_type, :user
#set :rbenv_ruby, '2.7.2'
 

config/deploy.rb

 # config valid for current version and patch releases of Capistrano
lock "~> 3.14.1"

server 'seances.ecranvillage.ovh', roles: [:web, :app, :db], primary: true

set :repo_url, "git@framagit.org:rodinux/ecran-village-plannings.git"
set :application, "ecran_village_plannings"
ask :branch, 'master'
set :bundle_without, %w{development test}.join(' ')

set user: 'deploy', roles: %w{app db web}
# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto

# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
append :linked_files, "config/master.key", "config/database.yml"

# Default value for linked_dirs is []
append :linked_dirs, "bin", "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle" "public/system", "storage"

# Default value for default_env is {}
#set :default_env, { path: "/opt/ruby/bin:$PATH" }
#set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')

# Default value for linked_dirs is []
#set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads' )

# Rbenv specific settings
set :rbenv_path, '/home/deploy/.rbenv/'
set :rbenv_type, :system # or :system, depends on your rbenv setup
set :rbenv_ruby, 'ruby 2.7.2p137'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"

# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }

set :rails_env, 'production'
# Default value for keep_releases is 5
set :keep_releases, 5
# if you want to remove the dump file after loading
set :db_local_clean, true
# if you want to remove the dump file from the server after downloading
set :db_remote_clean, true
# if you are highly paranoid and want to prevent any push operation to the server
set :disallow_pushing, false

# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
set :puma_threads,    [4, 16]
set :puma_workers,    2
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }

set :nginx_config_name, 'ecran_village_plannings'
set :nginx_server_name, 'seances.ecranvillage.ovh'

set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord
set :puma_workers, 2

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) 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
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end
# when using db, you should add config/database.yml here
# set :linked_files, fetch(:linked_files, []).concat(%w{.rbenv-vars})
# set :linked_dirs, fetch(:linked_dirs, []).concat(%w{log tmp/pids tmp/cache tmp/sockets vendor/bundle})
 

/config/deploy/production.rb

 # server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:
set :stage, :production # this defines production stage for deployment

set :branch, 'master'
server "seances.ecranvillage.ovh", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}




# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{deploy@example.com}, my_property: :my_value
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
# role :db,  %w{deploy@example.com}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
set :ssh_options, {
    keys: %w(/home/deploy/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
}
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server "example.com",
#   user: "user_name",
#   roles: %w{web app},
#   ssh_options: {
#     user: "user_name", # overrides user setting above
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#     # password: "please use keys"
#   }
 

Я добавил файлы, такие как /config/secrets.yml и т. Д…

Возможно, я не использую хорошую практику для использования Capistrano… почему я не могу это сделать?

Комментарии:

1. bundle exec cap --tasks --trace работает ли?

2. bundle exec решил проблему для меня.

3. Вы поняли это? Я только что обновил свое приложение Rails до версии 6.1, и теперь у меня точно такая же проблема

Ответ №1:

в основном это связано с проблемами с обновленной версией ruby, rails и ubuntu. У меня такая же проблема.

Добавлена в Capfile эта строка перед последней строкой, и это решило мою проблему (только если ваша версия puma <5 ).

 install_plugin Capistrano::Puma::Daemon
 

Для справки следуйте приведенному ниже руководству. Было бы полезно для кого-то. Потому что я потратил много времени, чтобы найти решение для этого.
https://matthewhoelter.com/2020/11/10/deploying-ruby-on-rails-for-ubuntu-2004.html

Ответ №2:

Вам нужно добавить это в свой Capfile в соответствии с документами

install_plugin Capistrano::Puma::Daemon # If you using puma daemonized (not supported in Puma 5 )

Приветствия

Комментарии:

1. Спасибо за ответ, я вернусь к использованию своего старого приложения без capistrano, если смогу…

Ответ №3:

bundle exec cap --tasks --trace работает

 cap puma:make_dirs                  # Create Directories for Puma Pids and Socket
cap puma:nginx_config               # Setup nginx configuration
cap puma:phased-restart             # phased-restart puma
cap puma:restart                    # restart puma
cap puma:start                      # Start puma
cap puma:status                     # status puma
cap puma:stop                       # stop puma
cap puma:workers:count              # Add a worker
cap puma:workers:less               # Worker--
cap puma:workers:more               # Worker  
 

но cap <environment> deploy сбой

cap coffee deploy:check --trace
** Invoke coffee (first_time)
** Execute coffee
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
Don't know how to build task 'start' (See the list of available tasks with `cap --tasks`)
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task_manager.rb:59:in `[]'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:405:in `[]'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/dsl/task_enhancements.rb:7:in `before'
config/deploy.rb:207:in `block in <top (required)>'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task_manager.rb:232:in `in_namespace'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/dsl_definition.rb:141:in `namespace'
config/deploy.rb:199:in `<top (required)>'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/setup.rb:27:in `load'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/setup.rb:27:in `block (3 levels) in <top (required)>'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/configuration/variables.rb:32:in `untrusted!'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/2.7.0/delegate.rb:83:in `method_missing'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/setup.rb:26:in `block (2 levels) in <top (required)>'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `block in execute'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `each'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:281:in `execute'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `synchronize'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:199:in `invoke_with_call_chain'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/task.rb:188:in `invoke'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:160:in `invoke_task'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `each'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:116:in `block in top_level'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:125:in `run_with_threads'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:110:in `top_level'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:83:in `block in run'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.3/lib/rake/application.rb:80:in `run'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/lib/capistrano/application.rb:14:in `run'
/Users/ram/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/capistrano-3.14.1/bin/cap:3:in `<top (required)>'
/Users/ram/.rbenv/versions/2.7.1/bin/cap:23:in `load'
/Users/ram/.rbenv/versions/2.7.1/bin/cap:23:in `<main>'
Tasks: TOP => coffee
 

Исправлено: добавить bundle exec в cap <environment> deploy команду

Что изменилось?: Я использовал oh-my-zsh bundler плагин with, который автоматически загружается bundle exec в мою оболочку, но недавно я удалил его, чтобы ускорить запуск терминала

Комментарии:

1. Спасибо за ответ. Извините, я попытался удалить rbenv для установки rvm, и теперь у меня другие проблемы… Я возвращаюсь к первому проекту, который был развернут пять лет назад и выпущен, но без capistrano и puma, как и раньше, с passenger. Но плохой идеей было попробовать изменить мой менеджер версий…