如何使用Terraform设置启动远程服务? [英] How can I start a remote service using Terraform provisioning?

查看:130
本文介绍了如何使用Terraform设置启动远程服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆