PATH issues for init.d scripts on startup
12,007
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
Author by
Peterdk
Updated on September 18, 2022Comments
-
Peterdk almost 2 years
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 theruby
command.It appears that on boot the
PATH
does not yet include/usr/local/bin
. How can I fix this? -
Peterdk over 11 yearsOk, thanks. Didn't know that. It's fixed now!
-
jaseeey over 8 yearsAlternatively 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. -
SineSwiper over 6 yearsRelying on an outside $PATH is a security risk. Don't append an existing PATH! Create your own with the exact list you need.