美好的一天,
我正在从带Terraform的vSphere上的模板中配置VM。虚拟机启动后,文件供应商将复制本地静态内容(图片)。完成后,远程执行预配置程序将执行以下操作:
provisioner "remote-exec" {
inline = [
"mkdir /home/foo/static","mv /home/foo/logo.jpg /home/foo/static/","echo 'python /home/foo/app.py 2>&1 &' > /home/foo/start_app.sh","chmod u+x /home/foo/start_app.sh","/home/foo/start_app.sh 2>&1","sleep 60"
]
}
app.py是一个Python flask项目。该代码将启动并在60秒钟内正常显示内容。当我的睡眠计时器到期时,我怀疑Terraform产生的外壳消失了,app.py也是如此。我尝试在后台启动start_app.sh,尝试对它(前景和背景)进行sudoing无济于事。行为相同。如果我直接在remote-exec块内启动python /home/foo/app.py而不是调用start_app.sh,则TF永远不会退出外壳,而我的Jenkins构建将永远旋转。
我认为这没有什么区别,但是为了完整起见,当Git将Webhook发送给Jenkins时,将应用我的TF VMware计划。詹金斯将TF计划作为管道阶段的一部分进行调用。这是Jenkins的控制台输出:
vsphere_virtual_machine.vm[1]: Provisioning with 'file'...
vsphere_virtual_machine.vm[1]: Provisioning with 'remote-exec'...
vsphere_virtual_machine.vm[1] (remote-exec): Connecting to remote host via SSH...
vsphere_virtual_machine.vm[1] (remote-exec): Host: 1.1.1.200
vsphere_virtual_machine.vm[1] (remote-exec): User: foo
vsphere_virtual_machine.vm[1] (remote-exec): Password: true
vsphere_virtual_machine.vm[1] (remote-exec): Private key: false
vsphere_virtual_machine.vm[1] (remote-exec): SSH Agent: false
vsphere_virtual_machine.vm[1] (remote-exec): Checking Host Key: false
vsphere_virtual_machine.vm[1] (remote-exec): Connected!
vsphere_virtual_machine.vm[1] (remote-exec): * Serving flask app "app" (lazy loading)
vsphere_virtual_machine.vm[1] (remote-exec): * Environment: production
vsphere_virtual_machine.vm[1] (remote-exec): WARNING: This is a development server. Do not use it in a production deployment.
vsphere_virtual_machine.vm[1] (remote-exec): [2m Use a production WSGI server inst
vsphere_virtual_machine.vm[1] (remote-exec): * Debug mode: off
vsphere_virtual_machine.vm[1] (remote-exec): * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
vsphere_virtual_machine.vm.1: Still creating... (8m30s elapsed)
vsphere_virtual_machine.vm.0: Still creating... (8m30s elapsed)
vsphere_virtual_machine.vm.1: Still creating... (8m40s elapsed)
vsphere_virtual_machine.vm.0: Still creating... (8m40s elapsed)
vsphere_virtual_machine.vm.1: Still creating... (8m50s elapsed)
vsphere_virtual_machine.vm.0: Still creating... (8m50s elapsed)
vsphere_virtual_machine.vm.1: Still creating... (9m0s elapsed)
vsphere_virtual_machine.vm.0: Still creating... (9m0s elapsed)
vsphere_virtual_machine.vm.1: Still creating... (9m10s elapsed)
vsphere_virtual_machine.vm.0: Still creating... (9m10s elapsed)
vsphere_virtual_machine.vm[0]: Creation complete after 9m15s (ID: 4228d941-a19c-361d-073a-4441cde5973e)
在TF的remote-exec完成后,如何保持TF产生的外壳持久化?