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 service busables_unicorn start
/usr/bin/env: ruby: No such file or directory
$ 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
にあなたが実行コマンドを変更してみてくださいと思います。そのユーザーが変更を加えるとどうなりますか?プロダクションサーバーでは、必要なRubyの1つのバージョンをインストールします。また、ユーザーはアカウントを持たず、管理者だけです。 –
プライベートプロダクションサーバーです。 'dtuite'は私です。 –