2

I'm trying to get a starter script (for a ruby gem called ar_sendmail) working in /etc/init.d/ar_sendmail:

#! /bin/sh

echo "in /etc/init.d/ar_sendmail"
DIR=/home/max/work/e_learning_resource/trunk
PATH=/var/lib/gems/1.8/bin
DAEMON=/var/lib/gems/1.8/bin/ar_sendmail
DAEMON_OPTS="-e production -d --batch-size 100 --delay 150"
NAME=ar_sendmail
DESC=ar_sendmail
PID_FILE=/home/max/work/e_learning_resource/trunk/shared/log/ar_sendmail.pid


test -x $DAEMON || exit 0
set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon -d $DIR --start --quiet --pidfile $PID_FILE \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        kill -TERM `cat $PID_FILE`        
    rm $PID_FILE
        echo "$NAME."
        ;;
  restart)
        echo -n "Restarting $DESC: "
        kill -TERM `cat $PID_FILE`        
    rm $PID_FILE
        sleep 1
        start-stop-daemon -d $DIR --start --quiet --pidfile \
                $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload}" >&2
            exit 1   
            ;;
    esac

    exit 0

It's blowing up on the start-stop-daemon line, saying "start-stop-daemon: not found". But, when i plug the values into that line manually, and run it on the command line, it works.

My first thought was it was the shebang line but #! /bin/sh should be right shouldn't it? It's definitely the right folder and what i use in my other /etc/init.d scripts.

My second thought was that it's sudo related: i'd been testing start-stop-daemon in non-sudo and running /etc/init.d/ar_sendmail in sudo mode. But, i can run start-stop-daemon fine with sudo as well.

Kind of stumped, any ideas?

Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • 1
    Check the line where you are overwriting the PATH variable, stopping access to /sbin, /usr/sbin, etc. You may want to make it PATH=$PATH:/blah/blah, or add necessary directories explicitly. – vhallac Mar 08 '11 at 10:23
  • @Dysaster, that should be an answer... – sarnold Mar 08 '11 at 10:35
  • @sarnold True, don't know why I used a comment. :) – vhallac Mar 08 '11 at 10:44
  • 1
    Please don't [cross-post](http://superuser.com/questions/254747/start-stop-daemon-works-at-command-line-but-doesnt-work-in-etc-init-d-script). – Dennis Williamson Mar 08 '11 at 11:40

2 Answers2

2

As @Dysaster points out, you're overwriting your PATH with this line:

PATH=/var/lib/gems/1.8/bin

Because you're giving the complete pathname for your daemon, I think you probably don't even need to add /var/lib/gems/1.8/bin to your path, unless ar_sendmail needs to execute programs in that directory without knowing their path. (That would sure be unfortunate, but easily fixed with: PATH=/var/lib/gems/1.8/bin:$PATH.)

sarnold
  • 102,305
  • 22
  • 181
  • 238
0

Add a source /etc/profile to the start of the script, so you get your path setup.

Erik
  • 88,732
  • 13
  • 198
  • 189