如何使用Terraform设置启动远程服务? [英] How can I start a remote service using Terraform provisioning?
问题描述
我希望Terraform配置提供服务器并最后通过调用命令并继续运行来启动服务.我试过使用nohup和使用remote-exec进行屏幕操作:
I want my Terraform config to provision a server and start the service at the end by invoking a command and keep running it. I tried using nohup and screen using remote-exec:
nohup:
provisioner "remote-exec" {
inline = "nohup sudo command &"
}
屏幕:
provisioner "remote-exec" {
inline = "screen -d -m sudo command"
}
我通过手动登录来检查命令是否正在运行.但是它们不能使进程保持运行.如果我手动尝试这些命令并使用ssh调用它们,它们也会起作用.
I check if the commands are running by logging in manually. But they do not keep a process running. These commands do work if I try them manually and invoking them with ssh also works.
在返回控制流时,如何使用Terraform配置来启动命令并使它保持运行状态?
How can I use Terraform provisioning to start a command and keep it running while returning control flow?
推荐答案
尝试在nohup之后添加睡眠.为我工作.我怀疑您的最后一个远程执行程序可以让Terraform在子进程有机会启动之前摆脱连接的束缚.
Try adding a sleep after your nohup. Worked for me. I suspect backgrounding your last remote-exec lets Terraform get away with shutting down the connection before the child process has a chance to start up, despite the nohup.
provisioner "remote-exec" {
inline = [
"nohup sudo command &",
"sleep 1"
]
}
这篇关于如何使用Terraform设置启动远程服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!