2012-03-25 9 views
0

以下はmy rc.localファイルの内容です。私がsudo /etc/rc.localを実行するとうまく動作します。私が起動してインスタンスを作るとき。私はmonitがインストールされることを期待しますが、そうではありません。私は完全な損失にあります。私は通常rc.localを使用しますが、これはむしろ混乱しています。ec2上のubuntuのrc.localは動作しません

#!/bin/sh -e 
# 
# rc.local 
# 
# This script is executed at the end of each multiuser runlevel. 
# Make sure that the script will "exit 0" on success or any other 
# value on error. 
# 
# In order to enable or disable this script just change the execution 
# bits. 
# 
# By default this script does nothing. 

apt-get -y install monit 
/etc/init.d/monit stop 
cd /home/ubuntu/workspace/rtbopsConfig/ 
git fetch 
git checkout origin/master rtb_ec2_boot/ec2_boot.py 
git checkout origin/master config/ 
cp /home/ubuntu/workspace/rtbopsConfig/config/monit/redis/monitrc /etc/monit/ 
/usr/bin/python /home/ubuntu/workspace/rtbopsConfig/rtb_ec2_boot/ec2_boot.py >> /home/ubuntu/workspace/ec2_boot.txt 2>&1 

/etc/init.d/monit start 
chkconfig monit on 

exit 0 

答えて

4

あなたはしてスクリプトを起動することがあります:あなたのaptのキャッシュは、 "apt-getのインストール" の日付の外にあるかもしれないよう

apt-get update 

またこれらの二行でそれを開始することで、スクリプトをデバッグすることができます。

#!/bin/bash -ex 
exec > >(tee /var/log/rc.local.log|logger -t rc.local -s 2>/dev/console) 2>&1 

これは/var/log/rc.local.logする各コマンドとその出力をエコーし​​ますので、あなたは何を見つけることができます失敗していて、どのようなエラーが発生しています。

ファイルが実行可能であることを確認してください:rc.localには上で実行されていることを

sudo chmod 755 /etc/rc.local 

注意をすべてのブーツだけでなく、最初のブート。システムがしばらくしてからもう一度実行されていることを確認してください。

ここで私は上記の「実行」コマンドの詳細に書いた記事です:私の場合はhttp://alestic.com/2010/12/ec2-user-data-output

+0

感謝。私はやってみたが、まだ役に立たなかった。これはむしろ奇妙です。 – Tampa

+0

これらの2行でrc.localを起動して再起動したときの詳細については、 /var/log/rc.local.logファイルが作成されていますか?それには何が含まれていますか? –

+1

私は同じ振る舞いに気付きました。リブート後に/etc/rc.localが呼び出されない – mark

0

は、私が誤ってrc.localを内CRLF line endingsを使用しました。それらをLFエンディングに変換した後、私のrc.localが最終的に実行されました。

間違っ

#!/bin/sh\r\n 
#\r\n 
# This script will be executed *after* all the other init scripts.\r\n 
# You can put your own initialization stuff in here if you don't 
# want to do the full Sys V style init stuff.\r\n 
\r\n 
touch /var/lock/subsys/local\r\n 

正しい

#!/bin/sh\n 
... 
関連する問題