【问题标题】:Cannot run Puma upstart script on Ubuntu 16.04无法在 Ubuntu 16.04 上运行 Puma upstart 脚本
【发布时间】:2017-07-02 05:47:54
【问题描述】:

我正在尝试手动启动我的 Ruby on Rails 应用程序,但遇到了问题。

运行“sudo start puma-manager”或“sudo start puma app=/home//”时,我收到以下错误:“无法连接到 Upstart:无法连接到套接字 /com/ubuntu/upstart : 连接被拒绝'。

我正在阅读本教程:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04,在 Ubuntu 16.04 上(没有其他惊喜,除了使用 16.04,我已经按照本教程进行了最后的细节)。有没有让新贵开始工作的好方法?

我刚读到新贵在 16.04 上不可用。真的吗?我很难相信 puma 没有很好的解决方法。这似乎太常见了。

感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails ruby ubuntu digital-ocean puma


    【解决方案1】:

    没错。您应该在 Ubuntu 16.04 LTS 中使用 SystemD。 Here 是相关的 Puma 文档和提供的示例服务单元文件:

    [Unit]
    Description=Puma HTTP Server
    After=network.target
    
    # Uncomment for socket activation (see below)
    # Requires=puma.socket
    
    [Service]
    # Foreground process (do not use --daemon in ExecStart or config.rb)
    Type=simple
    
    # Preferably configure a non-privileged user
    # User=
    
    # Specify the path to your puma application root
    # WorkingDirectory=
    
    # Helpful for debugging socket activation, etc.
    # Environment=PUMA_DEBUG=1
    
    # The command to start Puma
    # Here we are using a binstub generated via:
    # `bundle binstubs puma --path ./sbin`
    # in the WorkingDirectory (replace <WD> below)
    # You can alternatively use `bundle exec --keep-file-descriptors puma`
    # ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
    
    # Alternatively with a config file (in WorkingDirectory) and
    # comparable `bind` directives
    # ExecStart=<WD>/sbin/puma -C config.rb
    
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,有一段时间这是我不升级到 Ubuntu 16 的原因,但我们必须继续进行这些更改。 Systemd 可能很可怕,但是一旦您开始有设置服务脚本的经验,它就会比 Upstart 更容易。

      1. 在 /etc/systemd/system/ 中创建一个名为 puma.service 的文件,类似于这个:

        [Unit]
        Description=Puma HTTP Server
        After=network.target
        [Service]
        Type=simple
        # Preferably configure a non-privileged user
        User=appuser
        
        # Specify the path to your puma application root
        WorkingDirectory=/home/deploy/appname
        
        # Helpful for debugging socket activation, etc.
        Environment=PUMA_DEBUG=1
        # Setting secret_key_base for rails production environment. We can set other Environment variables the same way, for example PRODUCTION_DATABASE_PASSWORD
        Environment=SECRET_KEY_BASE=b7fbccc14d4018631dd739e8777a3bef95ee8b3c9d8d51f14f1e63e613b17b92d2f4e726ccbd0d388555991c9e90d3924b8aa0f89e43eff800774ba29
        
        # The command to start Puma, use 'which puma' to get puma's bin path, specify your config/puma.rb file
        ExecStart=/usr/local/bin/puma -C /home/deploy/appname/config/puma.rb
        Restart=always
        [Install]
        WantedBy=multi-user.target
        
      2. 运行这些命令来启动 systemd 服务。

        systemctl daemon-reload
        systemctl enable puma.service
        systemctl start puma.service
        

      如果您正确完成了本指南的其他步骤,您的服务将会启动: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04

      请记住,您可以使用以下命令检查服务的状态:

      systemctl status puma.service
      systemctl status nginx
      

      您可以对这些日志文件使用“tail -f”进行调试:

      /home/deploy/appname/shared/log/puma.stderr.log
      /home/deploy/appname/log/production.log
      /var/log/nginx/error.log
      

      【讨论】:

      • 谢谢。这是完美的。一个边注我会提到,因为我遇到了这个,如果你使用的是 rvm,一定要在你的 ExecStart 中使用 'wrappers' 而不是 'bin'。有关信息,请参阅此线程:stackoverflow.com/questions/26247926/…
      • @TerryRay 更多的是使用which puma 并使用您为ExecStart 获得的路径
      【解决方案3】:

      如果您在 Ubuntu 15.04 或更高版本(例如 16.04)上运行生产服务器,则会出现此问题,如 here 所述。

      以下命令对我有用-

      $ sudo apt-get install upstart-sysv
      $ sudo update-initramfs -u
      $ reboot
      

      不要忘记重启,否则命令不会生效。

      【讨论】:

        猜你喜欢
        • 2017-02-06
        • 2018-05-06
        • 2016-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-23
        • 2016-11-05
        相关资源
        最近更新 更多