如何为 Rails 应用程序 (rvm) 设置 Puma 服务的 ExecStart?

问题描述 投票:0回答:1

我正在尝试正确配置我的 puma 服务的设置,但仍然不成功。我的 nginx.conf 看起来像这样:

upstream puma {
  server unix:///home/rails/myapps/myproj/shared/tmp/sockets/myproj-puma.sock;
}

server {
  listen 80 default_server deferred;
  # server_name example.com;

  root /home/rails/myapps/myproj/current/public;
  access_log /home/rails/myapps/myproj/current/log/nginx.access.log;
  error_log /home/rails/myapps/myproj/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

文件

/home/rails/myapps/myproj/shared/tmp/sockets/myproj-puma.sock
不存在,目录为空。

myproj_puma_production.service
中是以下内容:

[Unit]
Description=redata-app
#Requires=network.target

[Service]
Type=simple
User=rails
#Group=rails
#WorkingDirectory=/home/rails/myapps/myproj/
WorkingDirectory=/home/rails/myapps/myproj/
#ExecStart=/usr/share/rvm/bin/rvm all do bundle exec puma -b tcp://0.0.0.0:3000 -e production
#ExecStart=/usr/share/rvm/rubies/ruby-3.2.2/bin/bundle exec puma -C /home/rails/myapps/myproj/current/config/puma.rb
ExecStart=/usr/share/rvm/rubies/ruby-3.2.2/bin exec puma -C /home/rails/myapps/myproj/current/config/puma.rb
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target

当我运行 systemctl --user status reda_puma_product 时,我收到以下错误,引用了错误的

ExecStart

● myproj_puma_production.service - myproj-app
     Loaded: loaded (/etc/xdg/systemd/user/myproj_puma_production.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Mon 2024-04-15 16:06:43 UTC; 25s ago
    Process: 122683 ExecStart=/usr/share/rvm/rubies/ruby-3.2.2/bin exec puma -C /home/rails/myapps/myproj/current/config/puma.rb (code=exited, status=216/GROUP)
   Main PID: 122683 (code=exited, status=216/GROUP)
        CPU: 2ms

我不知道如何正确配置 ExecStart 字段。我尝试运行

which puma
,但只得到空输出。
puma
安装在 Rails 应用程序中。

我错过了什么?

ruby-on-rails ruby ubuntu capistrano puma
1个回答
0
投票

不确定是否可以提供帮助,但我的 Rails systemD 服务看起来像这样

[Unit]
Description=myapp

[Service]
WorkingDirectory=/home/maxence/Desktop/myapp

User=maxence
Group=maxence
# ProtectProc=invisible

ExecStart=/bin/bash -lc "bin/start_app"

# Let systemd restart this service always
Restart=always

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of threads this process can create
TasksMax=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no

[Install]
WantedBy=multi-user.target

其中

bin/start_app
刚刚启动了两个工头服务。一个用于准备应用程序,第二个用于运行它,使用两个不同的 procfiles

#!/bin/bash
foreman start -f Procfile_prepare -e .env
foreman start -f Procfile_services -e .env

Puma 和 Sidekiq 基本上都是通过 Foreman 启动的

我的Nginx文件也没有upstream属性

关于您的服务,工作目录已设置,因此您不能仅以经典方式启动 Rails

rails s -e production
吗?

© www.soinside.com 2019 - 2024. All rights reserved.