ruby-on-rails - 无法将 Puma 作为守护进程运行 OptionParser::AmbiguousOption:模糊选项:-d

标签 ruby-on-rails ruby puma

我升级到 Puma 5.0.2 并像往常一样启动我的 rails 应用程序:

bundle exec puma -d -e production -b unix:///home/user/app/tmp/puma.sock
现在我得到错误:
OptionParser::AmbiguousOption: ambiguous option: -d
将 puma 作为守护进程运行的正确方法是什么?

最佳答案

上下文:快速链接:
从 Puma 5.0.0 开始,Daemonize 选项已被删除而无需替换(来源:https://github.com/puma/puma/blob/master/History.md)
你可以在他们的文档中引用这个部分的守护进程:https://github.com/puma/puma/blob/master/docs/deployment.md#should-i-daemonize
解决方案:
根据您的操作系统发行版为 puma 创建一个 systemd 服务。
在您的应用程序目录中的 config/puma 中配置您的环境。
/etc/systemd/system中添加一个名为puma.service的服务文件(该路径在 SLES15 上对我有用)。
这是一个适用于我的示例(根据您的需要替换 <> 中的文本):

[Unit]
Description=Puma HTTP Server
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=<UserForPuma>
WorkingDirectory=<YourAppDir>
Environment=RAILS_MASTER_KEY=<EncryptionKeyIfUsedByRailsApp>
ExecStart=/usr/bin/rails s puma -b 'ssl://127.0.0.1:3000?key=<path_to_privatekey.key>&cert=<path_to_certificate.crt>' -e production
Restart=always
RestartSec=2
KillMode=process

[Install]
WantedBy=multi-user.target
将上述内容保存为上述目录路径中名为 puma.service 的文件。
之后只需启用并启动服务:
# systemctl daemon-reload
# systemctl --now enable puma.service

Created symlink /etc/systemd/system/multi-user.target.wants/puma.service → /etc/systemd/system/puma.service.

# systemctl status puma

● puma.service - Puma HTTP Server
   Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-10-09 12:59:28 CEST; 7s ago
 Main PID: 2854 (ruby.ruby2.5)
    Tasks: 21
   CGroup: /system.slice/puma.service
           ├─2854 puma 5.0.2 (ssl://127.0.0.1:3000?key=<your_key_path.key>&cert=<your_cert_path.crt>) [rails-app-dir]
           ├─2865 puma: cluster worker 0: 2854 [rails-app-dir]
           └─2871 puma: cluster worker 1: 2854 [rails-app-dir]
检查美洲狮状态:ps -ef | grep puma现在应该显示正在运行的 puma 进程(主进程和工作进程)。
这是初学者如何创建 systemd 服务的链接:
https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
系统文档:
  • https://www.freedesktop.org/software/systemd/man/systemd.unit.html
  • https://www.freedesktop.org/software/systemd/man/systemd.service.html

  • 对不起,但我不是 Windows 人,但我相信这个想法是一样的。在 Windows 中工作的任何人都可以尝试创建一个 bat 文件并将其作为 Windows 服务在后台运行。
    希望有帮助。

    关于ruby-on-rails - 无法将 Puma 作为守护进程运行 OptionParser::AmbiguousOption:模糊选项:-d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64259474/

    相关文章:

    ruby-on-rails - 为什么我的 Rails 回调被调用了两次?

    javascript - Sir Trevor CSS 的样式无法正确显示 Ruby On Rails 应用程序

    ruby-on-rails - 使用 FactoryGirl 创建具有所需关联的对象

    ruby - SQLite3 Activerecord 太慢

    ruby-on-rails - Ruby on Rails 中一个共享 View 的两个 Controller

    ruby - 无法加载此类文件 -- rack/handler/puma

    ruby-on-rails - rake 数据库 :seed generates ArgumentError: missing keywords: from, 到

    ruby-on-rails - 在 mongo 分片环境中排序会降低性能

    ruby-on-rails - Actioncable Nginx 和 Puma WebSocket 握手 : Unexpected response

    ruby-on-rails - Rails 4,实时流媒体,保持打开状态,阻止请求