2014-03-05 41 views
3

我試圖讓以下腳本在啓動GCE時在CentOS實例上運行。 我在實例名稱和下面的腳本上設置了自定義元數據「startup-script」作爲值。谷歌計算引擎啓動腳本:啓動時沒有運行

該腳本不啓動時,重新啓動執行或當我運行/ usr /共享/谷歌/運行啓動的腳本,但如果我實例上的本地創建它不執行和執行有

什麼明顯我錯過了什麼?

#! /bin/bash 
# Installs apache and a custom homepage 
# 1234567 123456 

#Get this servers name from the metadata server and use the header to authenticate 
THIS_SERVER_NAME=$(curl http://metadata/computeMetadata/v1/instance/hostname -H "X-Google-Metadata-Request: True") 
#Turn off IPtables firewall that comes installed 
service iptables stop 
#Install apache 
yum install -y httpd 
#start apache 
service httpd start 
#create custom default homepage for this server 
cat <<EOF > /var/www/html/index.html 
<html><body><h1>Hello World</h1> 
<p>This is Server: $THIS_SERVER_NAME</p> 
</body></html> 
EOF 
+0

我也嘗試從一個桶中加載腳本,至少在/ var/log/google/log中顯示我腳本已下載,但它仍然沒有實際執行任務。我需要從gcutil設置權限嗎? – mobcdi

+0

還添加了--service_account_scopes = storage-ro到gcutil命令,但仍然沒有快樂 – mobcdi

+0

我有類似的問題,但我的腳本啓動後,我重新啓動,但不是當創建實例時.... – brdido

回答

0

我個人的經驗是面臨着兩個問題:

1)必要的交互命令,將在啓動時不正常運行。例如,apt-get install要求您確認過程(是/否)?在這種情況下,你可以關閉的互動,並通過「是」與

yum -y --assumeyes install foo 
apt-get -y --force-yes install foo 

而且更換

yum install foo 
apt-get install foo 

,如果你使用Debian,任何命令之前,以下將打壓需求互動:

sudo DEBIAN_FRONTEND=noninteractive <your command here, e.g., apt-get -y install foo> 

2)另一個明顯的問題是有時你必須等待進程結束,並且可能遠遠晚於您的實例顯示爲「正在運行」發生。

0

我使用CentOS 7作爲基礎映像並安裝了一些庫,但它不起作用。切換到CentOS 6後,它運行良好(似乎CentOS 7有問題)。