2012-01-12 11 views
3

tl; dr
実行するにはルビが必要なサービスを実行しようとしています。しかし、RubyはRVMとインストールされています。ここでは、rootユーザーはエラー/usr/bin/env: ruby: No such file or directoryを生成してアクセスできないようです。 rvmsudoは機能しません。
rootユーザーがRubyにアクセスできないのでsudoでサービスを開始できません

背景には、私はunicorn serverを開始することになっているinit.dスクリプトを持っています。私はconfigディレクトリにスクリプトを保存し、/etc/init.d/busables_unicornから私のレールアプリケーションとそれへのシンボリックリンクを保ちます。 $APP_ROOTは私のRailsアプリケーションのルートへのパスです

$APP_ROOT/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb -E production 

:(一番下に追加されます)

$ ls -l /etc/init.d/busables_unicorn 
-> lrwxrwxrwx 1 root root 62 2012-01-12 15:02 busables_unicorn -> /home/dtuite/dev/rails/busables/current/config/unicorn_init.sh 

このスクリプトは、基本的にだけで次のコマンドを実行します。そのinit.dスクリプトでコマンドが実行されるたびに、dtuite(my deploy)ユーザとして実行されるはずです。これを達成するために、$CMDではなくsu -c "$CMD" - dtuiteに電話します。

/bin/unicornは、Bundlerによって生成された "ビンスクリプト"であり、config/unicorn.rbにはいくつかの設定オプションが含まれています。

ユニコーンbinscriptは次のようになります。

#!/usr/bin/env ruby 
# 
# This file was generated by Bundler. 
# 
# The application 'unicorn' is installed as part of a gem, and 
# this file is here to facilitate running it. 
# 

require 'pathname' 
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", 
    Pathname.new(__FILE__).realpath) 

require 'rubygems' 
require 'bundler/setup' 

load Gem.bin_path('unicorn', 'unicorn') 

を今、私は実行して、私のユニコーンサービスを開始しようとしている:

/usr/bin/env: ruby: No such file or directory 
:しかし、エラーが発生し

sudo service busables_unicorn start 

私はrootユーザーとしてサービスを実行していますが、RVMはRubyをインストールしているためdtuiteユーザーのホームディレクトリの下にあり、ルートユーザーにはアクセスできません。

[email protected]:$ which ruby 
-> /home/dtuite/.rvm/rubies/ruby-1.9.3-p0/bin/ruby 
[email protected]:$ su 
Password: 
[email protected]:$ which ruby 
[email protected]:$ 

質問
私はこの仕事をするために行うには何が必要ですか?

マイセットアップ
- Ubuntuの11.10
- ルビー1.9.3p0(2011年10月30日リビジョン33570)[i686の-linuxの]
- nginxの:nginxのバージョン:nginxの/ 1.0。5

私は

rvmsudo

$ rvmsudo service busables_unicorn start 
/usr/bin/env: ruby: No such file or directory 

rvm-auto-ruby

$ sudo service cakes_unicorn start 
-> [sudo] password for dtuite: 
-> -su: /home/dtuite/dev/rails/cakes/current/bin/unicorn: rvm-auto-ruby: bad interpreter: No such file or directory 

This other questionを試してみたことは、私は実際にそれを理解していない正直にするのではなく、役立つかもしれません。

付録
それの全体がbusables_unicornスクリプト。

# INFO: This file is based on the example found at 
# https://github.com/defunkt/unicorn/blob/master/examples/init.sh 
# Modifications are courtesy of Ryan Bate's Unicorn Railscast 
# Install Instructions: 
# sudo ln -s full-path-to-script /etc/init.d/APP_NAME_unicorn 
# Once installed, an app's unicorn can be reloaded by running 
# sudo service APP_NAME_unicorn restart 

#!/bin/sh 
set -e 
# Example init script, this can be used with nginx, too, 
# since nginx and unicorn accept the same signals 

# Feel free to change any of the following variables for your app: 
TIMEOUT=${TIMEOUT-60} 

APP_ROOT=/home/dtuite/dev/rails/busables/current 
PID=$APP_ROOT/tmp/pids/unicorn.pid 
# in order to access this, we need to first run 
# 'bundle install --binstubs'. THis will fill our 
# app/bin directory with loads of stubs for executables 
# this is the command that is run when we run this script 
CMD="$APP_ROOT/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb -E production" 
# we don't need an init config because this file does it's job 
action="$1" 
set -u 

old_pid="$PID.oldbin" 

cd $APP_ROOT || exit 1 

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

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

case $action in 
start) 
    sig 0 && echo >&2 "Already running" && exit 0 
    # NOTE: We have to change all these lines. 
    # Otherwise, the app will run as the root user 
    su -c "$CMD" - dtuite 
    ;; 
stop) 
    sig QUIT && exit 0 
    echo >&2 "Not running" 
    ;; 
force-stop) 
    sig TERM && exit 0 
    echo >&2 "Not running" 
    ;; 
restart|reload) 
    sig HUP && echo reloaded OK && exit 0 
    echo >&2 "Couldn't reload, starting '$CMD' instead" 
    su -c "$CMD" - dtuite 
    ;; 
upgrade) 
    if sig USR2 && sleep 2 && sig 0 && oldsig QUIT 
    then 
     n=$TIMEOUT 
     while test -s $old_pid && test $n -ge 0 
     do 
      printf '.' && sleep 1 && n=$(($n - 1)) 
     done 
     echo 

     if test $n -lt 0 && test -s $old_pid 
     then 
      echo >&2 "$old_pid still exists after $TIMEOUT seconds" 
      exit 1 
     fi 
     exit 0 
    fi 
    echo >&2 "Couldn't upgrade, starting '$CMD' instead" 
    su -c "$CMD" - dtuite 
    ;; 
reopen-logs) 
    sig USR1 
    ;; 
*) 
    echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" 
    exit 1 
    ;; 
esac 
+0

にあなたが実行コマンドを変更してみてくださいと思います。そのユーザーが変更を加えるとどうなりますか?プロダクションサーバーでは、必要なRubyの1つのバージョンをインストールします。また、ユーザーはアカウントを持たず、管理者だけです。 –

+0

プライベートプロダクションサーバーです。 'dtuite'は私です。 –

答えて

2

su読み取りシェルを産卵されていないように聞こえます通常rvm環境を設定するプロファイルファイル。

私は、これは本番サーバーである場合は、ユーザーのディレクトリにベースのRubyを使用してはいけません

source "/home/dtuite/.rvm/scripts/rvm" && $APP_ROOT/bin/unicorn... 
+0

これとAndrei Sの両方の答えがどちらも役に立ちます。私はこれを最初に試したので、私はこれを受け入れるだろうと思う。みんなありがとう。 –

1

このような輸出文では、起動スクリプトの先頭でどこかルビーのパスを追加してみてください:

export PATH=/home/dtuite/.rvm/rubies/ruby-1.9.3-p0/bin:$PATH

関連する問題