无法在Ubuntu 16.04上运行Puma upstart脚本

6

我正在尝试手动启动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之外没有其他意外,我已经完全按照此教程进行操作)。有没有好的方法让upstart工作?

我刚刚看到upstart在16.04上不可用。这是真的吗?我觉得很难相信puma没有一个好的解决方法。这似乎太常见了。

感谢您的帮助!

3个回答

11

我曾经遇到同样的问题,一度让我不敢升级到Ubuntu 16,但是我们必须跟上这些变化。Systemd可能会让人感到害怕,但是一旦你开始有了设置服务脚本的经验,它可能比Upstart更容易。

  1. 在/etc/systemd/system/目录下创建一个名为puma.service的文件,类似于以下内容:

  2. [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
    
    运行以下命令来启动systemd服务。
  3. 运行以下命令以启动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

3
谢谢,这很完美。我想提一点小建议,因为我遇到过这个问题,如果你正在使用rvm,请确保在ExecStart中使用'wrappers'而不是'bin'。参见此线程以获取更多信息:https://dev59.com/ol8d5IYBdhLWcg3w8WFt?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa - Terry Ray
2
@TerryRay 这更多是关于使用 which puma 并使用你得到的路径来设置 ExecStart - Emba Moussa

3

没错,你应该在Ubuntu 16.04 LTS中使用SystemD。这里是相关的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 15.04或更高版本(例如16.04)作为生产服务器,就会出现此问题,如此处所述。

以下命令对我有效 -

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

别忘了重启,否则命令不会生效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接