gpt4 book ai didi

ruby-on-rails - 如何让使用 Puma 和 Capistrano 部署的 Rails 应用程序在重启时启动

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:11 27 4
gpt4 key购买 nike

我已经成功地使用 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.

我在这里做错了什么?

最佳答案

我有类似的服务,但我声明的略有不同 /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

关于ruby-on-rails - 如何让使用 Puma 和 Capistrano 部署的 Rails 应用程序在重启时启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38250805/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com