简体   繁体   English

红宝石守护程序-运行但不起作用

[英]ruby daemons - running but not functioning

I have created my first ruby daemon and it functions fine for about a day but then it stops functioning but it still appears in the /var/run folder. 我创建了我的第一个ruby守护程序,它可以正常运行大约一天,但是随后停止运行,但仍显示在/ var / run文件夹中。

here is my control code - 这是我的控制代码-

require 'rubygems'
require 'daemons'
dir = File.dirname(__FILE__)
options = {
 :app_name => "rk_mail",
 :dir_mode => :system,
 :backtrace  => true,
 :log_output => true,
 :monitor    => true
}
Daemons.run(dir + '/mail_receiver.rb', options)

I have checked the logs but they dont show any errors 我已经检查了日志,但没有显示任何错误

Thanks, alex 谢谢,亚历克斯

The problem is that your script will change its directory to "/" when it starts the daemon process. 问题是您的脚本在启动守护进程时将其目录更改为“ /”。

Here's a way to fix it: 这是一种解决方法:

current_dir = Dir.pwd

options = {
  :backtrace => true,
  :app_name => "test",
  :log_dir => "#{current_dir}/log",
  :log_output => true,
  :dir_mode => :normal,
  :monitor => true
}

This will put the logs inside the log folder that's the same directory as your script. 这会将日志放入与脚本相同目录的日志文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM