Saturday, January 29, 2011

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

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  
  • ok.. dumb question but did you set the script to start at bootup? I'm more familiar with debian style distros but ntsysv or chkconfig might be what you need.

    massi : yes ... see the update
  • 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.

    massi : 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
  • Another dumb question, is bluepill loaded in memory after the script is run? ps -ef | grep bluepill

    From Jmarki
  • try adding

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

    to the top of the init script.

    massi : Thanks Justin !!! it is now working just as expected !
    massi : Justin, why this is needed to be in the script ?
    Justin : because /usr/local/bin/bluepill is likely trying to start more programs located in /usr/local, which it is unable to find. /usr/local/bin/bluepill might be a shell script, you can try reading it.
    From Justin
  • The lack of errors in the log is no clear indication that the init script is working. Two simple steps will debug this.

    1. Add some debugging details inside the script. I like to write the line number to a log file from various points with the script. No output? Then it's almost certainly not being run.
    2. Ensure the script has in fact been enabled to run when you think it has, as several others have already stated. If it's not being run that could account for the lack of error messages in the logs.

0 comments:

Post a Comment