以 systemd 形式运行 Ruby on Rails

以 systemd 形式运行 Ruby on Rails

操作系统:Centos 7

我尝试以 systemd 形式运行 Snorby,但脚本无法正确启动

我可以在 Snorby 文件夹中在命令行上执行 bundle exec rails server -e development -b 0.0.0.0 而不会出现任何问题,但是当我将它放入脚本中并使用 systemctl 执行时,它无法正常工作。

[Service] WorkingDirectory=/tmp/snorby Environment=RAILS_ENV=development ExecStart=/usr/local/rbenv/shims/bundle exec rails server -d -b 0.0.0.0

状态输出

snorby.service - Snorby ConfiServ

Loaded: loaded (/usr/lib/systemd/system/snorby.service; enabled; vendor preset: disabled)

Active: inactive (dead) since Thu 2017-08-03 13:25:34 UTC; 1min 18s ago
  Process: 5533 ExecStart=/usr/local/rbenv/shims/bundle exec rails server -d -b 0.0.0.0 (code=exited, status=0/SUCCESS)
 Main PID: 5533 (code=exited, status=0/SUCCESS)

Aug 03 13:25:32 TEST-02 systemd[1]:   
 Started Snorby ConfiServ.

Aug 03 13:25:32 TEST-02 systemd[1]:  
 Starting Snorby ConfiServ...

Aug 03 13:25:34 TEST-02 bundle[5533]:  
 /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-3.2.22/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant Mime::PDF

Aug 03 13:25:34 TEST-02 bundle[5533]:  
 /usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-3.2.22/lib/action_dispatch/http/mime_type.rb:102: warning: previous definition of PDF was here  

Aug 03 13:25:34 TEST-02 bundle[5533]:  
  No time_zone specified in snorby_config.yml; detected time_zone: UTC

Aug 03 13:25:34 TEST-02 bundle[5533]: => Booting Thin

Aug 03 13:25:34 TEST-02 bundle[5533]: => Rails 3.2.22 application starting in development on http://0.0.0.0:3000

答案1

就我而言,当我在脚本前使用“bash -l”时,它起作用了,如下所示。

ExecStart=/bin/bash -l'你的 ruby​​ 命令或脚本'

我猜 centos 7 在使用 systemd 加载 ruby​​ 环境变量时遇到了一些问题。不过它在没有 -l 选项的 ubuntu 上也能正常工作。

答案2

我明白了 - 你需要在 Systemd 上启动 Thin

相关内容