8

I have a simple script that starts up a unicorn instance (on Ubuntu 12.04LTS).

#!/bin/sh

case "$1" in
    start)
       echo "starting"
       cd /path && bundle exec unicorn -c /path/config/unicorn.rb -D -E production
      ;;
     stop)
      echo "Stopping Unicorn Instances"
      kill `cat /tmp/unicorn.pid`
    ;;
    restart)
    echo "sending USR2 to all unicorns"
    kill -s USR2 `cat /tmp/unicorn.pid`
    ;;
esac
exit 0

It behaves correctly when called: /etc/init.d/unicorn_boot.sh start

I want it to start on boot, so I ran: update-rc.d -f unicorn_boot.sh defaults

When I now reboot I get the following error:

/etc/rc2.d/S20unicorn_boot.sh: 10: /etc/rc2.d/S20unicorn_boot.sh: bundle: not found

I checked the bundle command, and it's installed in /usr/local/bin, same for the ruby command.

It appears that on boot the PATH does not yet include /usr/local/bin. How can I fix this?

Peterdk
  • 183
  • 1
  • 1
  • 6

1 Answers1

9

Initscripts are responsible for setting an appropriate path themselves. Set the $PATH variable at the top of the script:

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
mgorven
  • 30,615
  • 7
  • 79
  • 122
  • Ok, thanks. Didn't know that. It's fixed now! – Peterdk Feb 22 '13 at 23:00
  • Alternatively you should be able to set `PATH="$PATH:/usr/local/bin"` to append your required paths to the variable, rather than overriding the $PATH variable entirely. – jaseeey Nov 09 '15 at 03:52
  • Relying on an outside $PATH is a security risk. Don't append an existing PATH! Create your own with the exact list you need. – SineSwiper Mar 20 '18 at 15:27