我已经编写了以下ruby守护进程代码:
require 'rubygems'
require 'daemons'
pwd = File.dirname(File.expand_path(__FILE__))
file = pwd + '/../lib/background_service.rb'
Daemons.run_proc(
'background_service', # name of daemon
# :dir_mode => :normal
# :dir => File.join(pwd, 'tmp/pids'), # directory where pid file will be stored
# :backtrace => true,
# :monitor => true,
:log_output => true
) do
exec "ruby #{file}"
end
它应该从在系统启动时执行的shellscript执行。
#!/bin/bash
2 HOME=/opt/halogen/ui
3
4 ruby $HOME/daemon.rb start > log
当我像./test.sh
一样手动执行这个shellcript时,它运行正常。执行ruby守护进程。但是,根据我的要求,应该在系统启动时调用它。当系统调用test.sh文件时,它不起作用,并且不执行ruby守护进程。
请帮我解决这个问题。
答案 0 :(得分:0)
我的猜测是你的shell脚本是在root
用户下运行的,该用户没有安装ruby
。
尝试使用su
调用它:
su halogen -c ruby $HOME/deamon.rb start > log
要进一步调查您的问题 - 您应该看看脚本中是否有任何错误。
将脚本中的第一行替换为:
#!/bin/bash -ex
exec > >(tee /var/log/shellscript.log) 2>&1
这将使bash
脚本详细,并将详细输出写入/var/log/shellscript.log
。这可以让你看看是否有任何错误,以及它们是什么。