2012-03-25 24 views
0

以下是我的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-get update 

爲您容易緩存可能是過時了 「的apt-get安裝」。

您也可以通過這兩條線也開始調試腳本:

#!/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這樣你就可以找出什麼失敗並出現什麼錯誤。

確保文件是可執行文件:

sudo chmod 755 /etc/rc.local 

注意的rc.local是在跑每啓動,不只是第一次啓動。確保系統啓動一段時間後再次運行它可以正常運行。

這裏有一個文章,我有更多的細節寫了上面的「執行」命令:http://alestic.com/2010/12/ec2-user-data-output

+0

感謝。我嘗試過但仍然無濟於事。這很奇怪。 – Tampa 2012-03-25 17:16:59

+0

請提供更多的細節,當你用這兩行啓動rc.local時會發生什麼並重啓。文件/var/log/rc.local.log是否被創建?它包含什麼? – 2012-03-26 16:55:51

+1

我注意到了相同的行爲。重啓後不會調用/etc/rc.local – mark 2012-09-12 12:01:31

0

在我的情況,我用CRLF line endings內rc.local中意外。將它們轉換爲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 
... 
相關問題