簡體   English   中英

Unicorn服務upstart腳本拋出“-su:bundle:command not found”

[英]Unicorn service upstart script throws “-su: bundle: command not found”

我最近在DigitalOcean上創建了一個VPS來托管rails應用程序。 我按照他們的指南用我的應用程序設置了Unicorn。 https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04

我運行sudo service unicorn_appxyz start時出現問題。 給出的錯誤是-su: bundle: command not found

我跟蹤了init.d腳本並在終端中粘貼了評估的服務器啟動命令,並且在用戶joe (安裝rbenv的用戶和應用程序的所有者)下執行時,它可以正常工作。 評估的命令是

su - joe -c cd /home/joe/appxyz && bundle exec unicorn -c config/unicorn.rb -E production -D

我然后sudo su - 進入root用戶並運行service unicorn_appxyz start錯誤當然是一樣的。 然后我在root下運行了evaluate命令,它返回了這個錯誤

The program 'bundle' is currently not installed. You can install it by typing:
apt-get install bundler

看來腳本沒有切換用戶? 這可能是我啟動VPS時獨角獸無法啟動的原因。

完整的獨角獸新貴腳本在這里:

#!/bin/sh

### BEGIN INIT INFO
# Provides:          unicorn
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the unicorn app server
# Description:       starts unicorn using start-stop-daemon
### END INIT INFO

set -e

USAGE="Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"

# app settings
USER="joe"
APP_NAME="appxyz"
APP_ROOT="/home/$USER/$APP_NAME"
ENV="production"

# environment settings
PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH"
CMD="cd $APP_ROOT && bundle exec unicorn -c config/unicorn.rb -E $ENV -D"
PID="$APP_ROOT/shared/pids/unicorn.pid"
OLD_PID="$PID.oldbin"

# make sure the app exists
cd $APP_ROOT || exit 1

sig () {
  test -s "$PID" && kill -$1 `cat $PID`
}

oldsig () {
  test -s $OLD_PID && kill -$1 `cat $OLD_PID`
}

case $1 in
  start)
    sig 0 && echo >&2 "Already running" && exit 0
    echo "Starting $APP_NAME"
    su - $USER -c "$CMD"
    ;;
  stop)
    echo "Stopping $APP_NAME"
    sig QUIT && exit 0
    echo >&2 "Not running"
    ;;
  force-stop)
    echo "Force stopping $APP_NAME"
    sig TERM && exit 0
    echo >&2 "Not running"
    ;;
  restart|reload|upgrade)
    sig USR2 && echo "reloaded $APP_NAME" && exit 0
    echo >&2 "Couldn't reload, starting '$CMD' instead"
    $CMD
    ;;
  rotate)
    sig USR1 && echo rotated logs OK && exit 0
    echo >&2 "Couldn't rotate logs" && exit 1
    ;;
  *)
    echo >&2 $USAGE
    exit 1
    ;;
esac

更多相關信息

這是用戶joe下的ruby,rails和bundler的路徑。 在根目錄下,他們找不到。

joe@vps:~$ which ruby
/home/joe/.rbenv/shims/ruby
joe@vps:~$ which rails
/home/joe/.rbenv/shims/rails
joe@vps:~$ which bundle
/home/joe/.rbenv/shims/bundle

有意義的是在root用戶下找不到bundler,但upstart命令應該切換到用戶'joe'來運行bundle命令。 這是我不理解的部分。

我發現了這個問題。 說明如下,

啟動時root用戶首先su - 進入rails用戶(在本例中為'joe')然后執行bundle以啟動unicorn。 rbenv是單用戶,只有'joe'安裝了bundle。 bundle的路徑可能存儲在我的.bashrc文件中。 但是.bashrc文件不是通過su登錄而調用的 - 並且導致bundle未安裝錯誤。

我在.profile中包含了與rbenv相關的路徑。 這種方式當root su - into'joe'時,路徑被加載。

在Unbutu我用這個內容創建了我的文件/etc/profile.d/rbenv.sh:

export RBENV_ROOT=/home/YOUR_USER_PATH/.rbenv
export PATH=$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM