3

我用 capistrano 部署了项目,但是 puma 在服务器重新启动后没有启动..

我应该做 ->盖帽生产 puma:每次都开始

我试过了:

/etc/init.d/myscript

#!/bin/sh
/etc/init.d/puma_start.sh

puma_start.sh

#!/bin/bash 
puma -C /root/project/shared/puma.rb

但是,我有错误

/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem puma (>= 0.a) (Gem::GemNotFoundException)
    from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems.rb:298:in `activate_bin_path'
    from /usr/local/rvm/gems/ruby-2.3.3@project/bin/puma:22:in `<main>'
    from /usr/local/rvm/gems/ruby-2.3.3@project/bin/ruby_executable_hooks:15:in `eval'
    from /usr/local/rvm/gems/ruby-2.3.3@project/bin/ruby_executable_hooks:15:in `<main>'

如果我把它放在控制台root@host:~# puma -C /root/project/shared/puma.rb它工作,一切都好。

我认为我没有正确的宝石 puma 路径

服务器重新启动后如何执行 puma 自动启动
谢谢

4

3 回答 3

2

从 Ubuntu 16.04 开始推荐使用systemctl。在我使用暴发户之前。我为自己创建了这个指令。也许它对某人有用。

https://gist.github.com/DSKonstantin/708f346f1cf62fb6d61bf6592e480781


操作说明:

Article: https://github.com/puma/puma/blob/master/docs/systemd.md
#1 nano /etc/systemd/system/puma.service
#2 paste from puma.service

Commands:
# After installing or making changes to puma.service
systemctl daemon-reload

# Enable so it starts on boot
systemctl enable puma.service

# Initial start up.
systemctl start puma.service

# Check status
systemctl status puma.service

# A normal restart. Warning: listeners sockets will be closed
# while a new puma process initializes.
systemctl restart puma.service

puma.service 文件

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

[Service]
Type=simple

User=root
Group=root

WorkingDirectory=<path_to_project>/current
Environment=SECRET_KEY_BASE='<SECRET KEY>'

ExecStart=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec puma -C <path_to_project>/shared/puma.rb --daemon
ExecStop=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec pumactl -S <path_to_project>/shared/tmp/pids/puma.state -F <path_to_project>/shared/puma.rb stop

#Restart=always
Restart=on-failure

[Install]
WantedBy=multi-user.target
于 2019-02-19T13:25:26.830 回答
0

我找到了这个http://codepany.com/blog/rails-5-puma-capistrano-nginx-jungle-upstart/

这对我有帮助->

cd ~
$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma-manager.conf
$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma.conf

打开下载的 puma.conf 文件并为 setuid 和 setguid 设置系统的用户帐户。(在我们的例子中,我们使用 root 帐户,但建议使用权限较低的帐户):

vim puma.conf

setuid root
setgid root

将下载的新贵文件移动到 /etc/init 并创建另一个 puma.conf

$ sudo cp puma.conf puma-manager.conf /etc/init
$ sudo touch /etc/puma.conf

打开 /etc/puma.conf 并添加应用路径:

/root/name_of_your_app/current

打开 /etc/init/puma.conf ,找到类似的东西

exec bundle exec puma -C /root/project/shared/puma.rb

并替换您的文件 puma.rb 的路径

谢谢

于 2017-04-10T19:59:08.290 回答
0

实际上有一种非常简单的方法可以诊断和解决这个问题:

1.找到您的 rvm 可执行文件。

which rvm

就我而言,它是:

/usr/share/rvm/bin/rvm

...但您的可能会有所不同!所以你必须首先找出你的可执行文件在哪里。

2.找出您的服务器正在运行的 Ruby 版本。

ruby --version

对我来说是 2.6.2。您只需要那个版本号。没有其他的。

3.尝试类似康斯坦丁推荐的方法,但改为这样做:

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

[Service]
Type=simple
User=root
Group=root
WorkingDirectory= /var/www/your/current

ExecStart=/usr/share/rvm/bin/rvm 2.6.2 do bundle exec pumactl -S /var/www/your/shared/tmp/pids/puma.state -F /var/www/your/shared/puma.rb start
ExecStop=/usr/share/rvm/bin/rvm 2.6.2 do bundle exec pumactl -S /var/www/your/shared/tmp/pids/puma.state -F /var/www/your/shared/puma.rb stop

# Restart=always
Restart=on-failure

[Install]
WantedBy=multi-user.target

4.那么这是一个简单的问题:

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

然后就是这样!下次启动服务器时,puma 应该可以正常启动。

于 2021-08-08T16:24:46.280 回答