init.d脚本启动时的PATH问题

我有一个简单的脚本,启动一个独angular兽实例(在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 

调用时它的行为是正确的: /etc/init.d/unicorn_boot.sh start

我希望它在启动时启动,所以我运行: update-rc.d -f unicorn_boot.sh defaults

当我现在重新启动我得到以下错误:

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

我检查了bundle命令,它安装在/usr/local/bin ,与ruby命令相同。

看来在启动时, PATH还没有包含/usr/local/bin 。 我怎样才能解决这个问题?

Initscripts负责自行设置适当的path。 在脚本的顶部设置$PATHvariables:

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