2013-07-10 26 views
3

我已經在Ubuntu系統上安裝了一個關閉腳本,它沒有被執行。它是一個Amazon EC2實例。我不確定它只是想指出這一點。爲什麼關機腳本不能運行?

該腳本應將一些日誌文件推送到Amazon S3存儲桶,以便在網絡連接啓動時執行。

這裏是我安裝的腳本:在/etc/init.d/push-apache-logs-to-s3.sh與所需的命令

1)創建的文件。

2)製成它可執行與執行的sudo chmod +x push-apache-logs-to-s3.sh

3)sudo update-rc.d push-apache-logs-to-s3.sh start 0 0 .從上述

輸出是:

update-rc.d: warning: /etc/init.d/push-apache-logs-to-s3.sh missing LSB information 
update-rc.d: see <http://wiki.debian.org/LSBInitScripts> 
Adding system startup for /etc/init.d/push-apache-logs-to-s3.sh ... 
    /etc/rc0.d/S00push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh 

/etc/rc0.d/內容現在是:

lrwxrwxrwx 1 root root 17 Jul 31 2012 K09apache2 -> ../init.d/apache2 
lrwxrwxrwx 1 root root 29 Jun 16 2012 K10unattended-upgrades -> ../init.d/unattended-upgrades 
lrwxrwxrwx 1 root root 26 Jun 16 2012 K15landscape-client -> ../init.d/landscape-client 
lrwxrwxrwx 1 root root 19 Apr 10 11:11 K20memcached -> ../init.d/memcached 
-rw-r--r-- 1 root root 353 Jul 26 2012 README 
lrwxrwxrwx 1 root root 35 Jul 10 12:01 S00push-apache-logs-to-s3.sh -> ../init.d/push-apache-logs-to-s3.sh 
lrwxrwxrwx 1 root root 18 Jun 16 2012 S20sendsigs -> ../init.d/sendsigs 
lrwxrwxrwx 1 root root 17 Jun 16 2012 S30urandom -> ../init.d/urandom 
lrwxrwxrwx 1 root root 22 Jun 16 2012 S31umountnfs.sh -> ../init.d/umountnfs.sh 
lrwxrwxrwx 1 root root 20 Jun 16 2012 S35networking -> ../init.d/networking 
lrwxrwxrwx 1 root root 18 Jun 16 2012 S40umountfs -> ../init.d/umountfs 
lrwxrwxrwx 1 root root 20 Jun 16 2012 S60umountroot -> ../init.d/umountroot 
lrwxrwxrwx 1 root root 14 Jun 16 2012 S90halt -> ../init.d/halt 

當我手動執行與sudo ./push-apache-logs-to-s3.sh腳本,它的目標工作。

這些腳本是由root執行的嗎?我錯過了什麼?

+0

需要多長時間才能運行?如果實例處於關閉狀態,但時間過長,則ec2將通過終止將其清除。您應該嘗試將腳本直接放入rc0.d中,因爲它不是普通的服務控制腳本。 – datasage

+0

你是否正在用shutdown/halt關閉實例,還是使用ec2 terminate/stop關閉它? –

+0

也是你暫停它(0)或告訴它重新啓動(6)。 ? – Doon

回答

1

不兼容LSB的初始化腳本仍應運行。我發現原因是s3cmd無法讀取其配置文件。出於某種原因,在運行級別更改(0)期間,當init執行init腳本時,顯然運行這些腳本的root用戶不算作「真實」用戶,因此它沒有「主目錄」目錄從s3cmd嘗試讀取配置。

使用--config=...命令行參數s3cmd明確指定配置文件的位置可解決此問題。

+2

init腳本中的root用戶是真正的用戶,但缺乏環境。所以沒有$ HOME可以擴展。它就像一個cron調用的腳本 – theist

1

我不確定該腳本是否已經完成了這些要求,但我會嘗試的第一件事是檢查該腳本是否爲有效的LSB腳本,afaik腳本需要適應LSB友好結構。 這意味着您需要:

它也是一個好主意,包括用於記錄和調試的init.d功能,如log_success_msg或log_failure_msg,您需要包含t他在你的腳本中: 。/lib/lsb/init-functions

無論如何,有很多關於LSB初始化腳本的文檔。

我希望有幫助。

關於。

相關問題