1

I've done an init.d script in order to start a newrelic plugin as daemon. The problem is that when I run service rb_nr_agent start it has some errors related with "require". Output:

[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 ]

It doesn't start properly. When I run the same script but in the root path of the project it doesn't have any error and it works fine. The init.d is a copy of that one. Here you have the start option of the script:

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 }
Fran Rios
  • 821
  • 9
  • 20
  • At the top of your target file (/opt/newrelic_rb_plugin/newrelic_redborder_agent) add ``puts $LOAD_PATH`` and run it using ``service ... start``. After that run it again the way it works and check if there are any differences. – Nabeel Jun 15 '16 at 17:02

1 Answers1

1

Error text suggests that you're using RVM, but it is loaded only at user login and thus is not available in init-scripts by default.

Use rvm do to run a command with rvm enabled:

/usr/local/rvm/bin/rvm ruby-2.1.2 do /opt/newrelic_rb_plugin/newrelic_redborder_agent > /dev/null &

(you may need to correct for the exact installed ruby version and gemset name, if any is used)

Vasfed
  • 18,013
  • 10
  • 47
  • 53
  • It works but I need to run a `cd PATH_TO_PROJECT`previously in the script cause config dir is not configurable inside NR Ruby SDK. Thank you very much. – Fran Rios Jun 16 '16 at 09:09