如何获得Systemd以Puma重新启动Rails App [英] How to get systemd to restart Rails App with Puma

查看:139
本文介绍了如何获得Systemd以Puma重新启动Rails App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了一个星期,似乎真的找不到答案.我已经用Capistrano部署了我的Rails应用程序.我将Puma用作服务器.

I've been struggling with this a week now and really can't seem to find an answer. I've deployed my Rails App with Capistrano. I use Puma as a server.

部署后,一切正常.问题是要让Puma在重新启动和/或崩溃时启动.

When I deploy, everything works ok. The problem is to get Puma to start at reboot and/or when it crashes.

要获得部署设置,我已将此

To get the deployment setup, I've used this tutorial. I'm also using RVM. The problem I seem to get is to get the service to start Puma. Here's what I've used (service file):

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

[Service]
Type=simple

#User=my-user

WorkingDirectory=/home/my-user/apps/MyApp/current

ExecStart=/home/my-user/apps/MyApp/current/sbin/puma -C /home/my-user/apps/MyApp/shared/puma.rb

Restart=always

[Install]
WantedBy=multi-user.target

那是行不通的.我开始认为问题出在不是为所有用户都安装了Ruby,所以我为所有用户安装了RVM,但仍然遇到相同的问题.我的服务器只有root和my-user.

That doesn't work. I was starting to think the problem was Ruby not being installed for all users, so I've installed RVM for all users and still get the same problem. My server has only root and my-user.

查看Capistrano的部署方式,它运行的命令是:cd /home/my-user/apps/MyApp/current && ( RACK_ENV=production /home/my-user/.rvm/bin/rvm default do bundle exec puma -C /home/my-user/apps/MyApp/shared/puma.rb --daemon ).如果使用前面提到的命令,我会从Systmd收到错误消息,抱怨缺少参数.因此,我已经用它编写了一个脚本,并获得了服务文件来调用该脚本来启动应用程序.

Looking at how Capistrano deploys, the command it runs is: cd /home/my-user/apps/MyApp/current && ( RACK_ENV=production /home/my-user/.rvm/bin/rvm default do bundle exec puma -C /home/my-user/apps/MyApp/shared/puma.rb --daemon ). If I use the aforementioned command, I get an error from Systmd complaining about missing parameters. So I've written a script with it and got the service file to call this script to start the app.

那也不行.请注意,如果我从服务器上的任何位置调用脚本,脚本都会启动该应用程序,因此这是配置Systemd的问题,但是我无法弄清楚出了什么问题,并且不确定如何调试它.我已经在System网站上看到了调试页面,但是它对我没有帮助.如果我运行systemctl status puma.service,则只能告诉我该服务处于失败状态,但不能告诉我如何或为什么.

That doesn't work either. Note that if I call the script from anywhere on the server the script does start the App, so its an issue on configuring Systemd, but I can't figure out what's wrong and I'm not sure how to debug it. I've seen the debug page on System's website, but it didn't help me. If I run systemctl status puma.service all it tells me is that the service is in failed state, but it doesn't tell me how or why.

还值得注意的是:如果我从我的App文件夹中运行bundle exec puma -C /home/my-user/apps/MyApp/shared/puma.rb,它可以正常运行,那么如何使用Systemd服务复制此命令?

Also worth noting: If I run bundle exec puma -C /home/my-user/apps/MyApp/shared/puma.rb from my App folder it works ok, so how I could duplicate this command with Systemd service?

推荐答案

您是否研究过工头? 如果应用程序具有多个进程,则使用Foreman可以轻松启动和停止您的应用程序. 顺便说一句,它还提供了一个导出函数,该函数可以为该文件生成一些systemdupstart脚本您可以(重新)启动和停止应用程序.

Have you looked into Foreman ? Foreman makes it easy to start and stop your application if it has multiple processes. Incidentally it also provides an export function that can generate some systemd or upstart scripts for you to (re)start and stop your application.

由于您已经在使用capistrano,因此可以使用 capistrano-foreman 与所有这些很好地集成Capistrano.

As you are already using capistrano you can use capistrano-foreman to integrate all this nicely with capistrano.

我希望您能在这些资源中找到一些用处

I hope you find some use in these resources

这篇关于如何获得Systemd以Puma重新启动Rails App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆