【发布时间】:2016-10-16 21:03:30
【问题描述】:
我已经编写了一个 init.d 脚本来启动一个 newrelic 插件作为守护进程。问题是当我运行service rb_nr_agent start 时,它有一些与“require”相关的错误。输出:
[root@device newrelic_rb_plugin]# /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- snmp (LoadError)
from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /opt/newrelic_rb_plugin/newrelic_redborder_agent:5:in `<main>'
[root@device newrelic_rb_plugin]# ./rb_nr_agent start Starting rb_nr_agent:[ OK ]
它无法正常启动。当我运行相同的脚本但在项目的根路径中它没有任何错误并且工作正常。 init.d 是那个的副本。这里有脚本的启动选项:
start() {
RESULT=`ps aux | grep $executable | grep -c -v grep`
if [ "${RESULT:-null}" -ge "1" ]; then
echo "$prog is currently running"
else
echo -n "Starting $prog: "
/opt/newrelic_rb_plugin/newrelic_redborder_agent > /dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo_success
else
echo_failure; failure
RETVAL=1
fi
echo
fi
return $RETVAL }
【问题讨论】:
-
在目标文件的顶部 (/opt/newrelic_rb_plugin/newrelic_redborder_agent) 添加
puts $LOAD_PATH并使用service ... start运行它。之后以它的工作方式再次运行它并检查是否有任何差异。