首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >班德勒:命令找不到。无法启动puma,甚至无法打开rails控制台。

班德勒:命令找不到。无法启动puma,甚至无法打开rails控制台。
EN

Stack Overflow用户
提问于 2022-07-12 21:38:03
回答 2查看 304关注 0票数 2

我正在使用capistrano来部署rails 5.2应用程序。一切都进行得很顺利,除了美洲狮还没有开始。

执行tail -f /var/www/tuma/shared/log/puma_error.logsudo systemctl start puma_tuma_production的结果

代码语言:javascript
复制
bundler: command not found: puma
Install missing gem executables with `bundle install`

我注意到,当我抄送到当前的rails文件夹时,我甚至不能打开rails控制台。

bundle exec rails c production返回:

代码语言:javascript
复制
bundler: command not found: rails
Install missing gem executables with `bundle install`

下面是在gem list bundler上执行时/var/www/tuma/current的输出

代码语言:javascript
复制
*** LOCAL GEMS ***

bundler (2.3.17, default: 2.1.4)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)

gem list bundler在当前文件夹之外运行时,它返回:/home/ubuntu/.rvm/gems/ruby-2.7.1/bin/bundler

这是sudo systemctl status puma_tuma_production的输出

代码语言:javascript
复制
× puma_tuma_production.service - Puma HTTP Server for tuma (production)
     Loaded: loaded (/etc/systemd/system/puma_tuma_production.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-07-12 15:22:28 UTC; 24s ago
    Process: 320774 ExecStart=/home/ubuntu/.rvm/bin/rvm default do bundle exec --keep-file-descriptors puma -C /var/www/tuma/shared/puma.rb (code=exited, status=127)
   Main PID: 320774 (code=exited, status=127)
        CPU: 558ms

Jul 12 15:22:26 ip-172-31-42-199 systemd[1]: puma_tuma_production.service: Main process exited, code=exited, status=127/n/a
Jul 12 15:22:26 ip-172-31-42-199 systemd[1]: puma_tuma_production.service: Failed with result 'exit-code'.
Jul 12 15:22:28 ip-172-31-42-199 systemd[1]: puma_tuma_production.service: Scheduled restart job, restart counter is at 5.
Jul 12 15:22:28 ip-172-31-42-199 systemd[1]: Stopped Puma HTTP Server for tuma (production).
Jul 12 15:22:28 ip-172-31-42-199 systemd[1]: puma_tuma_production.service: Start request repeated too quickly.
Jul 12 15:22:28 ip-172-31-42-199 systemd[1]: puma_tuma_production.service: Failed with result 'exit-code'.
Jul 12 15:22:28 ip-172-31-42-199 systemd[1]: Failed to start Puma HTTP Server for tuma (production).

这是sudo systemctl cat puma_tuma_production的结果

代码语言:javascript
复制
# /etc/systemd/system/puma_tuma_production.service
[Unit]
Description=Puma HTTP Server for tuma (production)
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/var/www/tuma/current
# Support older bundler versions where file descriptors weren't kept
# See https://github.com/rubygems/rubygems/issues/3254
ExecStart=/home/ubuntu/.rvm/bin/rvm default do bundle exec --keep-file-descriptors puma -C /var/www/tuma/shared/puma.rb
ExecReload=/bin/kill -USR1 $MAINPID
StandardOutput=append:/var/www/tuma/shared/log/puma_access.log
StandardError=append:/var/www/tuma/shared/log/puma_error.log

Restart=always
RestartSec=1
SyslogIdentifier=puma
[Install]
WantedBy=multi-user.target

这是我的puma.rb文件

代码语言:javascript
复制
#!/usr/bin/env puma

directory '/var/www/tuma/current'
rackup "/var/www/tuma/current/config.ru"
environment 'production'

tag ''

pidfile "/var/www/tuma/shared/tmp/pids/puma.pid"
state_path "/var/www/tuma/shared/tmp/pids/puma.state"

threads 0,16
bind 'unix:///var/www/tuma/shared/tmp/sockets/puma.sock'
workers 2

restart_command 'bundle exec puma'
prune_bundler

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = ""
end

这是我的PATH

代码语言:javascript
复制
/home/ubuntu/.rvm/gems/ruby-2.7.1/bin:/home/ubuntu/.rvm/gems/ruby-2.7.1@global/bin:/home/ubuntu/.rvm/rubies/ruby-2.7.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.rvm/bin:/home/ubuntu/.rvm/bin

这是我的GemFile

代码语言:javascript
复制
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.1'

gem 'rails', '~> 5.2.8'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 5.6.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'terser'

gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
gem 'sidekiq'                 # Background Jobs Processing
gem 'devise'
gem 'business_time'
gem 'phony_rails'
gem 'friendly_id', '~> 5.4.0', require: "friendly_id"
gem 'meta-tags'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

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 do
  gem 'annotate'
  gem 'net-ssh', '~> 7.0.0.beta1'
  ## Deployment
  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rvm'
  gem 'capistrano3-puma', github: 'seuros/capistrano-puma'
  gem 'capistrano3-nginx'
  gem 'capistrano-db-tasks', require: false
  gem 'capistrano-sidekiq', github: 'seuros/capistrano-sidekiq'
  gem 'pry'
  gem 'pry-rails'

  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 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 chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

/home/ubuntu/.rvm/bin/rvmwhich rvm得到的结果

代码语言:javascript
复制
#!/usr/bin/env bash

if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
  declare rvmrc

  rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
     then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  fi

  for rvmrc in "${rvm_rvmrc_files[@]}"
  do
    if [[ -f "$rvmrc" ]]
    then
      if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
      then
        printf "%b" "
  Error:
    $rvmrc is for rvm settings only.
    rvm CLI may NOT be called from within $rvmrc.
    Skipping the loading of $rvmrc
"
        exit 1
      else
        source "$rvmrc"
      fi
    fi
  done
  unset rvm_rvmrc_files
  unset rvmrc
fi

# duplication marker jdgkjnfnkjdngjkfnd4fd
export rvm_path
if [[ -z "${rvm_path:-}" ]]
then
  if [[ -d "${0%/bin/rvm}" ]]
  then rvm_path="$( \cd "${0%/bin/rvm}">/dev/null; pwd )"
  elif (( UID == 0 )) && [[ -d "/usr/local/rvm" ]]
  then rvm_path="/usr/local/rvm"
  elif [[ -d "${HOME}/.rvm" ]]
  then rvm_path="${HOME}/.rvm"
  elif [[ -d "/usr/local/rvm" ]]
  then rvm_path="/usr/local/rvm"
  else echo "Can't find rvm install!" 1>&2 ; exit 1
  fi
fi

# allow disabling check temporary
: rvm_is_not_a_shell_function:${rvm_is_not_a_shell_function:=1}
export rvm_is_not_a_shell_function

# if to prevent fork-bomb
if source "${rvm_scripts_path:="$rvm_path/scripts"}/rvm"
then
  typeset -f rvm >/dev/null 2>&1 || {
    echo "RVM not loaded, aborting." >&2
    exit 1
  }
  rvm "$@"
else
  echo "Error sourcing RVM!"  1>&2
  exit 1
fi

config/deploy.rb结果

代码语言:javascript
复制
# config valid for current version and patch releases of Capistrano
lock "~> 3.17.0"
require 'capistrano-db-tasks'

set :application, "tuma"
set :repo_url, "git@gitlab.com:<MYGITLABUSERNAME>/tuma.git"

set :use_sudo, false

# if you want to remove the local dump file after loading
set :db_local_clean, false

# Default branch is :master
ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
set :use_sudo, false
set :bundle_binsstubs, nil

append :rvm_map_bins, 'puma', 'pumactl', 'sidekiq', 'sidekiqctl'

set :app_path, "#{deploy_to}/current"
set :pty, false

append :linked_files, 'config/database.yml', 'config/secrets.yml', 'config/application.yml', 'config/sidekiq.yml'

append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system', 'public/uploads'

set :disallow_pushing, false

set :assets_dir, %w(public/uploads)
set :local_assets_dir, %w(public/uploads)

### Puma Configuration ###
set :nginx_use_ssl, true
set :puma_workers, 2

### Sidekiq Configuration ###
SSHKit.config.command_map[:sidekiq] = "bundle exec sidekiq"
SSHKit.config.command_map[:sidekiqctl] = "bundle exec sidekiqctl"

set :sidekiq_default_hooks, true
set :sidekiq_pid, File.join(shared_path, 'tmp', 'pids', 'sidekiq.pid') # ensure this path exists in production before deploying.
set :sidekiq_env, :production
set :sidekiq_log, File.join(shared_path, 'log', 'sidekiq.log')
set :sidekiq_config, File.join(shared_path, 'config', 'sidekiq.yml') 

这是我的Capfile

代码语言:javascript
复制
# Load DSL and set up stages
require 'capistrano/setup'

require 'capistrano/deploy'

require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git

require 'capistrano/rvm'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/puma'
require 'capistrano/sidekiq'
require 'capistrano/nginx'

install_plugin Capistrano::Puma  # Default puma tasks
install_plugin Capistrano::Puma::Workers  # if you want to control the workers (in cluster mode)
install_plugin Capistrano::Puma::Nginx  # if you want to upload a nginx site template
install_plugin Capistrano::Sidekiq::Systemd
install_plugin Capistrano::Puma::Systemd  # if you use SystemD
install_plugin Capistrano::Nginx

Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

我已经更改了将:rvm_bin_stubs设置为追加:rvm_bin_stubs,而没有运气

EN

回答 2

Stack Overflow用户

发布于 2022-11-19 15:07:58

我怀疑systemctl需要正确地设置$PATH变量--看来bundle无法找到RVM设置的gem路径。您可能在shell中有一个有效的$PATH集,但可能不是在systemctl的上下文中。我相信有两种方法可以做到这一点。

首先,您可以在systemctl配置中为服务设置一个$PATH,就像下面的答案概述了https://stackoverflow.com/a/37341810/261940一样

代码语言:javascript
复制
# /etc/systemd/system/nagios.service.d/env.conf
[Service]
Environment="PATH=/home/ubuntu/.rvm/gems/ruby-2.7.1/bin:/home/ubuntu/.rvm/gems/ruby-2.7.1@global/bin:/home/ubuntu/.rvm/rubies/ruby-2.7.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/.rvm/bin:/home/ubuntu/.rvm/bin"

其次,您可以尝试编辑您的ExecStart以使用bash,我认为它将正确地加载$PATH,如下所示:

代码语言:javascript
复制
ExecStart=/bin/bash -lc '/home/ubuntu/.rvm/bin/rvm default do bundle exec --keep-file-descriptors puma -C /var/www/tuma/shared/puma.rb'

我很高兴提供更多的跟进,如果你尝试这些,并让我知道发生了什么。

票数 0
EN

Stack Overflow用户

发布于 2022-11-22 20:34:50

您会运行which bundle并确保被指向正确的rvm构建吗?

也只是为了确认你运行过bundle update吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72958658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档