CustomScript扩展 - 无法在Azure CentOS VM上运行bash脚本

问题描述:

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

根据您的描述,我用你的脚本和测试在我的实验室。我得到相同的错误日志。我检查登录/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

对于文件可用在虚拟机上,只需上传到某个地方公开,并发出命令下载。看到这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