使ExecStartPost命令在后台运行

时间:2016-11-25 07:05:35

标签: linux fork systemd consul consul-template

我的systemd服务连接到consul服务器的haproxy后面的consulconsul-template提供haproxy通过consul-template命令自动更新consul-template配置文件中的服务位置。

haproxy获取模板文件并写入最终的haproxy配置文件,然后重新加载consul-template

现在,systemd进程需要始终与我的应用程序一起在后台运行,以便在应用程序启动时,它可以检测新应用程序启动并在配置文件中更新其位置。

这是我的[Unit] Description=myservice Requires=network-online.target After=network-online.target [Service] Type=forking PIDFile=/home/dragon/myservice/run/myservice.pid ExecStart=/home/dragon/myservice/bin/myservice-script start ExecReload=/home/dragon/myservice/bin/myservice-script reload ExecStop=/home/dragon/myservice/bin/myservice-script stop ExecStartPost=consul-template -template '/etc/haproxy/haproxy.cfg.template:/etc/haproxy/haproxy.cfg:sudo systemctl reload haproxy' User=dragon [Install] WantedBy=multi-user.target 服务文件。

systemctl start myservice

现在,当我启动consul-template时,我的应用程序启动,对consul-template的调用也有效,但Ctl+C进程不在后台。我必须按systemctl,然后consul-template回来,我的应用程序和联合模板流程都在运行。

  

是否可以在ExecStartPost中指定的后台运行&流程?

我试图在ExecStartPost命令的末尾添加consul-template,但后来/bin/sh -c "consul-template command here..."抱怨它是一个额外的无效参数,但它失败了。

我也试图将命令设为nohup,但这也不起作用。甚至此命令中的<t:radiogroup t:id="myRadioGroup" value="radioGroupValue" > <t:loop source="myRadioGroupList" value="radioGroupItem"> <div class="radio"> <input t:type="radio" t:id="radio3" value="${radioGroupItem}"/> </div> </t:loop> </t:radiogroup> <t:error for="myRadioGroup"/> 也无效。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

解决方法是将一个bash文件作为入口点,在那里添加你需要的所有东西,然后它就会神奇地工作