2017-03-15 92 views
1

Azure(和Linux)的新手...CustomScript擴展 - 無法在Azure CentOS VM上運行bash腳本

CentOS 7.2 VM。

我配置一個新的Azure的CentOS的VM,併爲 「自定義腳本用於Linux」 擴展以下: 腳本文件:bob.sh(從本地工作站的選擇) 命令:sh bob.sh

鮑勃.sh:

#!/bin/bash 
sudo echo "This is a test" > test.txt 

# Update instance packages 
sudo yum -y check-update 

# Download and install Node.js 
sudo yum install -y epel-release 
sudo yum install -y nodejs npm --enablerepo=epel 

VM部署完成後,儀表板上出現「部署失敗」錯誤。

錯誤/狀態消息,因爲Azure的認爲我是一臺電腦,在JSON顯示給我的是:

{ 
    "status": "Failed", 
    "error": { 
    "code": "ResourceDeploymentFailure", 
    "message": "The resource operation completed with terminal provisioning state 'Failed'.", 
    "details": [ 
     { 
     "code": "VMExtensionProvisioningError", 
     "message": "VM has reported a failure when processing extension 'CustomScriptForLinux'. Error message: \"Malformed status file (000003)Invalid status/status: failed\"." 
     } 
    ] 
    } 
} 

畸形狀態文件(000003)無效的狀態/狀態:失敗?

DuckDuckGo先生似乎沒有關於此錯誤的信息。

我SSH到VM:

文件test.txt不存在。

我試圖在虛擬機上查看/var/log/azure/custom-script/handler.log上的日誌文件,但我沒有權限。

我可以成功地手動運行腳本中的每一步。

有什麼建議嗎?

UPDATE:

waagent.log(最後30行)

2017/03/15 18:59:08.306400 INFO Agent WALinuxAgent-2.2.5 error state: Last Failure: 0.0, Total Failures: 0, Fatal: False 
2017/03/15 18:59:08.318722 INFO Ensuring Agent WALinuxAgent-2.2.5 is downloaded 
2017/03/15 18:59:08.326959 INFO Agent WALinuxAgent-2.2.5 was previously downloaded - skipping download 
2017/03/15 18:59:08.337453 INFO Agent WALinuxAgent-2.2.5 loaded manifest from /var/lib/waagent/WALinuxAgent-2.2.5/HandlerManifest.json 
2017/03/15 18:59:08.351363 INFO Wire server endpoint:168.63.129.16 
2017/03/15 18:59:08.392832 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Expected handler state: enabled 
2017/03/15 18:59:08.405362 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Current handler state is: NotInstalled 
2017/03/15 18:59:08.418354 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Download extension package 
2017/03/15 18:59:08.451541 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Unpack extension package 
2017/03/15 18:59:08.484619 INFO Event: name=Microsoft.OSTCExtensions.CustomScriptForLinux, op=Download, message=Download succeeded 
2017/03/15 18:59:08.505998 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Initialize extension directory 
2017/03/15 18:59:08.522399 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Update settings file: 0.settings 
2017/03/15 18:59:08.538153 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Install extension. 
2017/03/15 18:59:08.553039 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Launch command:customscript.py -install 
2017/03/15 18:59:08 CustomScriptForLinux started to handle. 
2017/03/15 18:59:08 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] cwd is /var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1 
2017/03/15 18:59:08 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Change log file to /var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/1.5.2.1/extension.log 
2017/03/15 18:59:09.573891 INFO Event: name=Microsoft.OSTCExtensions.CustomScriptForLinux, op=Install, message=Launch command succeeded: customscript.py -install 
2017/03/15 18:59:09.591446 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Enable extension. 
2017/03/15 18:59:09.602945 INFO [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Launch command:customscript.py -enable 
2017/03/15 18:59:09 CustomScriptForLinux started to handle. 
2017/03/15 18:59:09 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] cwd is /var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1 
2017/03/15 18:59:09 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Change log file to /var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/1.5.2.1/extension.log 
2017/03/15 18:59:09 CustomScriptForLinux started to handle. 
2017/03/15 18:59:09 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] cwd is /var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1 
2017/03/15 18:59:09 [Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.1] Change log file to /var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/1.5.2.1/extension.log 
2017/03/15 18:59:10.628480 INFO Event: name=Microsoft.OSTCExtensions.CustomScriptForLinux, op=Enable, message=Launch command succeeded: customscript.py -enable 
2017/03/15 18:59:10.815782 INFO Event: name=WALinuxAgent, op=HealthCheck, message=Blob type match [PageBlob] 
2017/03/15 19:14:05.254971 INFO Agent WALinuxAgent-2.2.5 launched with command 'python -u bin/WALinuxAgent-2.2.5-py2.7.egg -run-exthandlers' is successfully running 
2017/03/15 19:14:05.273919 INFO Event: name=WALinuxAgent, op=Enable, message=Agent WALinuxAgent-2.2.5 launched with command 'python -u bin/WALinuxAgent-2.2.5-py2.7.egg -run-exthandlers' is successfully running 

handler.log: 
No such file or directory 
+0

'sudo su; cat /var/log/waagent.log; cat/var/log/azure/custom-script/handler.log'並在此處發帖 – 4c74356b41

+0

從本地工作站選擇的是什麼意思?您希望該文件可以在您配置的VM上神奇地可用?它不會,你必須首先將它下載到虛擬機 – 4c74356b41

+0

是的,我期望這個文件能夠神奇地可用,因爲我來自AWS背景,即UserData。使用Azure Blob存儲中的數據/文件自動進行自動配置而無需手動將文件推送到現有虛擬機的最佳做法是什麼? – programmerj

回答

1

根據您的描述,我用你的腳本和測試在我的實驗室。我得到相同的錯誤日誌。我檢查登錄/var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux‌​/1.5.2.1/extension.l‌​og。我發現一些sudo錯誤。

請刪除腳本中的sudo。 Azure以root用戶身份執行腳本。刪除sudo後,您可以成功安裝擴展。

#!/bin/bash 
echo "This is a test" > test.txt 

# Update instance packages 
yum -y check-update 

# Download and install Node.js 
yum install -y epel-release 
yum install -y nodejs npm --enablerepo=epel 
+0

不確定你爲什麼被低估;這是正確的答案。我從我的所有腳本條目中刪除了「sudo」,現在它可以工作。謝謝你的幫助!! – programmerj

0

對於文件可用在虛擬機上,只需上傳到某個地方公開,併發出命令下載。看到這example

{ 
    "type": "Microsoft.Compute/virtualMachines/extensions", 
    "name": "[concat(variables('vmName'),'/', variables('extensionName'))]", 
    "apiVersion": "[variables('apiVersion')]", 
    "location": "[resourceGroup().location]", 
    "dependsOn": [ 
    "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 
    ], 
    "properties": { 
    "publisher": "Microsoft.Azure.Extensions", 
    "type": "CustomScript", 
    "typeHandlerVersion": "2.0", 
    "autoUpgradeMinorVersion": true, 
    "settings": { 
     "fileUris": "[split(parameters('fileUris'), ' ')]", ## << file url goes here 
     "commandToExecute": "[parameters('commandToExecute')]" 
    }, 
    "protectedSettings": { ## << these are needed if you are using Azure Blob which is not publicly accessible 
     "storageAccountName": "[parameters('customScriptStorageAccountName')]", 
     "storageAccountKey": "[parameters('customScriptStorageAccountKey')]" 
    } 
    } 
} 
+0

腳本可以從您的工作站上傳到門戶網站,然後在配置虛擬機時執行該腳本。 見https://azure.microsoft.com/en-us/blog/automate-linux-vm-customization-tasks-using-customscript-extension/ 部分:通過Azure的門戶 – programmerj

+0

好運部署CustomScript擴展自動化@programmerj – 4c74356b41

+0

是的......它的第二步。我只是首先想確保我可以讓虛擬機下載併成功執行腳本。 – programmerj