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

时间:2017-03-15 19:19:06

标签: linux bash azure virtual-machine

Azure(和Linux)的新手......

CentOS 7.2 VM。

我配置了一个新的Azure CentOS VM,并为“Custom Script for Linux”扩展设置了以下内容: 脚本文件:bob.sh(从本地工作站选择) 命令:sh bob.sh

bob.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进入虚拟机:

文件test.txt不存在。

我试图在/var/log/azure/custom-script/handler.log上查看VM上的日志文件,但我没有权限。

我可以成功手动运行脚本中的每一步。

有什么建议吗?

更新

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

要使文件在VM上可用,只需将其上传到公共可用的位置并发出命令即可下载。见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')]"
    }
  }
}