Systemd Rails 引导脚本因 rbenv 而失败,(代码=退出,状态=1/失败)
Systemd Rails boot script fails with rbenv, (code=exited, status=1/FAILURE)
创建用于启动 rails 应用程序的 systemd 服务后,该服务失败并出现此错误:
$ systemctl status evrserver
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2019-04-03 18:34:22 BST; 2min 51s ago
Process: 425 ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66 (code=exited, status=1/FAILURE)
CGroup: /system.slice/evrserver.service
Apr 03 18:34:22 raspberrypi systemd[1]: Failed to start evr server boot.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Unit entered failed state.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Failed with result 'exit-code'.
根据其他在线教程进行设置,以便 systemd 在 rbenv 管理环境中启动 rails 应用程序,如此处所述:
https://gist.github.com/arteezy/5d53d99f6ee617fae1f0db0576fdd418
https://mikewilliamson.wordpress.com/2015/08/26/running-a-rails-app-with-systemd-and-liking-it/
这是服务文件:
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
此设备还有两个其他服务,它们是自定义实现,没有问题,都不是 rails 进程。我在这里缺少什么来获得 rails 服务 运行?
啊,有点好笑。它总是小事是吗?在 bundle 之前忘记了一个 exec 并且类型需要简单而不是分叉。
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv exec bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
和成功日志:
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 04:05:45 BST; 8min ago
Main PID: 460 (ruby)
CGroup: /system.slice/evrserver.service
└─460 puma 3.12.0 (tcp://192.168.1.66:3000) [evr]
Apr 04 04:05:45 raspberrypi systemd[1]: Started evr server boot.
Apr 04 04:06:08 raspberrypi rbenv[460]: => Booting Puma
Apr 04 04:06:08 raspberrypi rbenv[460]: => Rails 6.0.0.beta3 application starting in development
Apr 04 04:06:08 raspberrypi rbenv[460]: => Run `rails server --help` for more startup options
Apr 04 04:13:51 raspberrypi rbenv[460]: Puma starting in single mode...
Apr 04 04:13:51 raspberrypi rbenv[460]: * Version 3.12.0 (ruby 2.6.2-p47), codename: Llamas in Pajamas
Apr 04 04:13:51 raspberrypi rbenv[460]: * Min threads: 5, max threads: 5
Apr 04 04:13:51 raspberrypi rbenv[460]: * Environment: development
Apr 04 04:13:51 raspberrypi rbenv[460]: * Listening on tcp://192.168.1.66:3000
Apr 04 04:13:51 raspberrypi rbenv[460]: Use Ctrl-C to stop
创建用于启动 rails 应用程序的 systemd 服务后,该服务失败并出现此错误:
$ systemctl status evrserver
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2019-04-03 18:34:22 BST; 2min 51s ago
Process: 425 ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66 (code=exited, status=1/FAILURE)
CGroup: /system.slice/evrserver.service
Apr 03 18:34:22 raspberrypi systemd[1]: Failed to start evr server boot.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Unit entered failed state.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Failed with result 'exit-code'.
根据其他在线教程进行设置,以便 systemd 在 rbenv 管理环境中启动 rails 应用程序,如此处所述:
https://gist.github.com/arteezy/5d53d99f6ee617fae1f0db0576fdd418
https://mikewilliamson.wordpress.com/2015/08/26/running-a-rails-app-with-systemd-and-liking-it/
这是服务文件:
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
此设备还有两个其他服务,它们是自定义实现,没有问题,都不是 rails 进程。我在这里缺少什么来获得 rails 服务 运行?
啊,有点好笑。它总是小事是吗?在 bundle 之前忘记了一个 exec 并且类型需要简单而不是分叉。
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv exec bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
和成功日志:
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 04:05:45 BST; 8min ago
Main PID: 460 (ruby)
CGroup: /system.slice/evrserver.service
└─460 puma 3.12.0 (tcp://192.168.1.66:3000) [evr]
Apr 04 04:05:45 raspberrypi systemd[1]: Started evr server boot.
Apr 04 04:06:08 raspberrypi rbenv[460]: => Booting Puma
Apr 04 04:06:08 raspberrypi rbenv[460]: => Rails 6.0.0.beta3 application starting in development
Apr 04 04:06:08 raspberrypi rbenv[460]: => Run `rails server --help` for more startup options
Apr 04 04:13:51 raspberrypi rbenv[460]: Puma starting in single mode...
Apr 04 04:13:51 raspberrypi rbenv[460]: * Version 3.12.0 (ruby 2.6.2-p47), codename: Llamas in Pajamas
Apr 04 04:13:51 raspberrypi rbenv[460]: * Min threads: 5, max threads: 5
Apr 04 04:13:51 raspberrypi rbenv[460]: * Environment: development
Apr 04 04:13:51 raspberrypi rbenv[460]: * Listening on tcp://192.168.1.66:3000
Apr 04 04:13:51 raspberrypi rbenv[460]: Use Ctrl-C to stop