用於啟動 Rails 應用程式的服務存在一些問題。 ruby安裝是透過rbenv管理的,服務文件是這樣的:
[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
當系統啟動時,涉及此服務時會拋出此錯誤:
$ 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'.
看起來 PATH 存在問題,並且在嘗試執行“rails”命令時失敗。如何避免這種情況,以便服務成功啟動 Rails 應用程式?
答案1
所以這很簡單,是嗎?看起來我忘記了 ExecStart 行中“bundle”之前的“exec”,並且還需要將類型設為“simple”而不是“forking”