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

标签 linux bash azure virtual-machine

Azure(和 Linux)新手...

CentOS 7.2 虚拟机。

我配置了一个新的 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

虚拟机部署后,我在仪表板上收到“部署失败”错误。

因为 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 的日志文件,但我没有权限。

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

有什么建议吗?

更新:

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

最佳答案

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

关于linux - CustomScript 扩展 - 无法在 Azure CentOS VM 上运行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42818839/

相关文章:

linux - 如何将变量值从循环 A 更新到另一个循环 B - 在 bash 中

linux bash命令以空格分隔

linux - HAL - UDISKS,人类可读,在 bash 脚本中将字节转换为千兆字节

linux - 用于检查日志是否针对当前时间戳生成的 Shell 脚本

linux - shell脚本中grep搜索的回显结果

python - 如何使用python从Azure应用程序库获取数据库密码?我正在 google Dataproc 集群上运行这个 python 文件

java - Tomcat、mod_jk、Plesk 和 SSL 设置问题

linux - 使用 grep/sed/perl 在一行中提取多个项目

python - Microsoft Azure 数据仓库和 SqlAlchemy

Azure Monitor(Application Insights)日志查询图表 - Y 轴上有什么?