Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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  
share|improve this question
    
What happens when you run <scriptname> start? –  Kamil Kisiel Mar 4 '10 at 23:12
    
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)? –  massi Mar 6 '10 at 3:33
1  
post the output of "/bin/sh -x /etc/init.d/bluepill_script start" –  Justin Mar 6 '10 at 5:47
    
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 –  massi Mar 6 '10 at 17:23
add comment

6 Answers 6

up vote 3 down vote accepted

try adding

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

to the top of the init script.

share|improve this answer
    
Thanks Justin !!! it is now working just as expected ! –  massi Mar 7 '10 at 20:42
    
Justin, why this is needed to be in the script ? –  massi Mar 7 '10 at 23:56
    
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. –  Justin Mar 8 '10 at 1:55
add comment

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.

share|improve this answer
    
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 –  massi Mar 6 '10 at 3:36
add comment

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|improve this answer
add comment

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.

share|improve this answer
    
yes ... see the update –  massi Mar 6 '10 at 3:34
add comment

Another dumb question, is bluepill loaded in memory after the script is run? ps -ef | grep bluepill

share|improve this answer
add comment

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.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.