【问题标题】:How to get a Rails App Deployed with Puma and Capistrano to start on reboot如何让使用 Puma 和 Capistrano 部署的 Rails 应用程序在重启时启动
【发布时间】:2016-07-07 16:31:22
【问题描述】:

我已经成功地使用 Capistrano 部署了 Rails 4、Puma、Nginx 应用程序。当我部署cap production deploy 时,一切正常。我的问题是如果服务器由于某种原因重新启动或崩溃,它不会重新启动。

我在 DigitalOcean 上使用 Debian 8。似乎 Debian 8 使用了systemd,所以我按照Puma 的说明进行操作,但它没有用。经过一番研究,我发现了更多脚本,其中最明智的一个是:

[Unit]
Description=Rails-Puma Webserver

[Service]
Type=simple
User=myuser
WorkingDirectory=/home/myuser/apps/myapp
ExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

我已经将上面的文件保存在/etc/systemd/system/rails-puma.service 然后我启用它:sudo systemctl enable rails.service 最后启动它:sudo systemctl start rails-puma.service

不幸的是,这没有奏效。这是sudo systemctl status rails-puma.service的结果:

    ● rails-puma.service - Rails-Puma Webserver
   Loaded: loaded (/etc/systemd/system/rails-puma.service; enabled)
   Active: failed (Result: start-limit) since Thu 2016-07-07 12:11:58 EDT; 4s ago
  Process: 4373 ExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production (code=exited, status=203/EXEC)
 Main PID: 4373 (code=exited, status=203/EXEC)

Jul 07 12:11:58 mrcProd systemd[1]: rails-puma.service: main process exited, code=exited, status=203/EXEC
Jul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.
Jul 07 12:11:58 mrcProd systemd[1]: rails-puma.service start request repeated too quickly, refusing to start.
Jul 07 12:11:58 mrcProd systemd[1]: Failed to start Rails-Puma Webserver.
Jul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.

我在这里做错了什么?

【问题讨论】:

  • 也许this 有用。
  • 不幸的是没有...我一直在尝试各种组合但无济于事...
  • 您的 puma 错误日志文件中是否有任何有用的信息?
  • 有一个/var/myapp/current/log/puma.error 文件,它没有显示任何与启动/停止相关的内容。我猜如果应用程序未运行,则不会使用此文件,但我不知道 systemd 的日志位于何处...
  • 也许debugging options 可以帮助你。另外,如果你手动运行/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production会发生什么?

标签: ruby-on-rails ruby nginx puma systemd


【解决方案1】:

我有类似的服务,但我声明的略有不同/etc/systemd/system/puma.service

[Unit]
Description=Puma Control
After=network.target auditd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/puma/puma-start
ExecStop=/etc/puma/puma-stop

[Install]
WantedBy=multi-user.target

然后在/etc/puma/puma-start

#!/bin/bash -

cd /home/changeuser/apps/changeapp/current && ( export RACK_ENV="production" ; /home/changeuser/.rvm/bin/rvm default do bundle exec puma -C /home/changeuser/apps/changeapp/shared/puma.rb --daemon )

/etc/puma/puma-stop

#!/bin/bash -

cd /home/changeuser/apps/changeapp/current && ( export RACK_ENV="production" ; /home/changeuser/.rvm/bin/rvm default do bundle exec pumactl -S /home/changeuser/apps/changeapp/shared/tmp/pids/puma.state stop )

记得设置后执行

chmod +x /etc/puma/puma-start
chmod +x /etc/puma/puma-stop
systemctl enable puma

然后去测试

systemctl start puma
systemctl stop puma
systemctl restart puma
systemctl status puma

【讨论】:

  • 只是对许多现有 gem 的当前状态的更新,以处理启动和进程管理。似乎 capistrano-foreman、foreman 和 RVM/Rubygems/Bundler 的开发速度已经放缓,并且 gem 依赖关系没有跟上。在玩了一段时间之后,我决定走这条路线进行手动安装,事实证明这是最干净、最快捷的方式。
  • 使用 Ubuntu 16.04 我遇到了 CD 问题并在 puma-start/stop 中导出,所以我使用:~/.rvm/bin/rvm default do bundle exec puma -C /home /deployer/apps/app_name/shared/config/puma.rb --daemon 似乎正在生产中加载。
猜你喜欢
  • 2016-11-13
  • 2016-03-16
  • 2021-07-20
  • 2016-04-11
  • 2021-12-18
  • 2017-03-16
  • 2018-08-24
  • 2011-09-30
  • 1970-01-01
相关资源
最近更新 更多