resque worker的systemd init脚本

时间:2017-05-17 13:58:12

标签: ruby-on-rails ruby nginx systemd

我是在Ubuntu 16.04服务器上运行的nginx网络服务器。 现在我正在尝试为Rails应用程序的resque worker和scheduler构建一个init脚本。

我在“/ etc / systemd / system /”中创建了一个文件resque-worker.service,它看起来像这样:

[Unit]
 Description=resque-worker for pageflow

[Service]
 Type=forking
 ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler QUEUE=* RAILS_ENV=production > /home/pageflow/pageflow_daad/log/resqueschedule.log &

[Install]
 WantedBy=multi-user.target

在执行“systemctl daemon-reload”和“systemctl start name.service”后出于某种原因,我收到此错误:

$ systemctl status resque-worker.service
● resque-worker.service - resque-worker for pageflow
   Loaded: loaded (/etc/systemd/system/resque-worker.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-05-17 15:52:38 CEST; 15s ago
  Process: 28096 ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler QUEUE=* RAILS_ENV=production > /home/pageflow/pageflow_daad/log/resqueschedule.log & (code=exited, status=203/EXEC)

May 17 15:52:38 ostheim systemd[1]: Starting resque-worker for pageflow...
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Control process exited, code=exited status=203
May 17 15:52:38 ostheim systemd[1]: Failed to start resque-worker for pageflow.
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Unit entered failed state.
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Failed with result 'exit-code'.

在这种情况下,我使用了我的Rails应用程序的根路径“/ home / pageflow / pageflow_daad / rake”。

在我尝试rake二进制路径之前的时间我得到了错误:May 17 15:30:26 ostheim rake[26846]: rake aborted! May 17 15:30:26 ostheim rake[26846]: ArgumentError: couldn't find HOME environment -- expanding〜'`

我希望有更多经验的人可以帮助我。

先致谢谢,并致以诚挚的问候, 罗纳德

2 个答案:

答案 0 :(得分:1)

我认为systemd单元中有两种类型的错误。以下是一些建议:

1)让systemd捕获您的应用程序日志,然后使用journalctl查看它

journalctl -u resque-worker.service

2)以系统方式使用env:

[Unit]
Description=resque-worker for pageflow

[Service]
Type=forking
ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler
Environement=QUEUE=*
Enrironement=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

然后,

systemctl daemon-reload
systemctl restart resque-worker.service

答案 1 :(得分:1)

在研究了几个文档站点和文档本身之后,我找到了一种方法来运行它。如果有人发现这是有帮助的话,只是想发布这个:

[Unit]
Description=resque-scheduler for pageflow

[Service]
User=yourUser
WorkingDirectory=/path/to/rails/app
ExecStart=/path/to/executeable/rake resque:scheduler &
Environment=QUEUE=*
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

使用此脚本,

systemctl daemon-reload

&安培;

systemctl start example.service

服务启动运行并像魅力一样运行。