init.d script not working .... but the command works if I execute it in the console

32,451

Solution 1

try adding

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

to the top of the init script.

Solution 2

I'll echo Kamil's call for output when run.

Furthermore, have you tried chkconfig --add bluepill and chkconfig bluepill on.

Otherwise, I'm betting it's some sort of environment variable in the script. Try sourcing an environment at the start via . /etc/profile or the like. Especially since this looks like it's installed in /usr/local/bin. It may need PATH or LD_LIBRARY_PATH set properly.

Solution 3

I'm using the following init.d script, and was having a similar problem because the bluepill gem was installed under an rvm installation. Notice having to source either the rvm environment variable, but the same could have been achieved by sourcing /etc/profile (since it's also being set there). I'm using an Opscode cookbook recipe to set these, so those paths are set to be variable given where the rvm cookbook is installing its gems.

#!/bin/bash
#
# Bluepill
#
# chkconfig: - 85 15
# description: start, stop, restart bluepill
#

RETVAL=0

if [[ -s /usr/local/rvm/scripts/rvm ]] ; then source /usr/local/rvm/scripts/rvm ; fi

case "$1" in
    start)
      for i in /etc/bluepill/*.pill; do
        /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill load $i
      done
      RETVAL=$?
  ;;
    stop)
      /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill stop
      /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill quit
      RETVAL=$?
  ;;
    restart)
      /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill restart
      RETVAL=$?
  ;;
    status)
      /usr/local/rvm/gems/ruby-1.9.2-p180/bin/bluepill status
      RETVAL=$?
  ;;
    *)
      echo "Usage: bluepill {start|stop|restart|status}"
      exit 1
  ;;
esac

exit $RETVAL
Share:
32,451

Related videos on Youtube

Max
Author by

Max

Updated on September 17, 2022

Comments

  • Max
    Max almost 2 years

    I have a command that is working fine if I executed it from the command line ... but when I put it in an init.d script it wont's start (well .. it starts but have a behavior different from that when it is run directly).

    Any idea why this is not working on the init script ?

    The command is : bluepill load /var/www/html/bluepill.conf

    And the init.d script is :

        #!/bin/sh
    
        ## Based on http://www.novell.com/coolsolutions/feature/15380.html
        # chkconfig: 345 99 1
        # processname: solr
        # Provides: bluepill
        # Default-Start: 3 4 5
        # Default-Stop: 0 1 2 6
        # Short-Description: bluepill daemon, providing process monitoring
        # Description: Bluepill
    
        # Check for missing binaries
        BLUEPILL_BIN=/usr/local/bin/bluepill
        test -x $BLUEPILL_BIN || { echo "$BLUEPILL_BIN not installed";
                if [ "$1" = "stop" ]; then exit 0;
                else exit 5; fi; }
    
        # Check for existence of needed config file and read it
        BLUEPILL_CONFIG=/var/www/html/bluepill.conf
        test -r $BLUEPILL_CONFIG || { echo "$BLUEPILL_CONFIG not existing";
                if [ "$1" = "stop" ]; then exit 0;
                else exit 6; fi; }
    
        case "$1" in
          start)
            echo -n "Starting bluepill "
            $BLUEPILL_BIN load $BLUEPILL_CONFIG
            ;;
          stop)
            echo -n "Shutting down bluepill "
            $BLUEPILL_BIN quit
            ;;
          restart)
            ## Stop the service and regardless of whether it was
            ## running or not, start it again.
            $0 stop
            $0 start
          ;;
          *)
            ## If no parameters are given, print which are avaiable.
            echo "Usage: $0 {start|stop|restart}"
            exit 1
            ;;
        esac
    

    Update (to answer few questions) :

    I also added the script in order to be executed at boot time using :

    chkconfig --add bluepill_script  
    chkconfig --level 345 bluepill_script  on  
    
    • Rahim
      Rahim over 14 years
      What happens when you run <scriptname> start?
    • Max
      Max over 14 years
      when running service bluepill_script start it seems to work ... but not doing its job ... but when I stop it with service bluepill_script stop and then manually run the command : bluepill load /var/www/html/bluepill.conf it works fine ! .... I don't see where is the problem ... because the script is executing the same command ... can it be related to access privileges (even if I used chmod 777 for the script)?
    • Justin
      Justin over 14 years
      post the output of "/bin/sh -x /etc/init.d/bluepill_script start"
    • Max
      Max over 14 years
      Justin, when running : /bin/sh -x /etc/init.d/bluepill_script start I'm getting : + BLUEPILL_BIN=/usr/local/bin/bluepill + test -x /usr/local/bin/bluepill + BLUEPILL_CONFIG=/var/www/html/bluepill.conf + test -r /var/www/html/bluepill.conf + case "$1" in + echo -n 'Starting bluepill 'Starting bluepill + /usr/local/bin/bluepill load /var/www/html/bluepill.conf
  • Max
    Max over 14 years
    yes ... see the update
  • Max
    Max over 14 years
    As I said in a response to Kamil Kisiel's comment, even after the server is started ... when I try service bluepill_script start it seems to work (no error is displayed) but it's not doing its job
  • Max
    Max over 14 years
    Justin, why this is needed to be in the script ?