我的systemd
服务连接到consul
服务器的haproxy
后面的consul
。 consul-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"/>
也无效。
非常感谢任何帮助。
答案 0 :(得分:1)
解决方法是将一个bash文件作为入口点,在那里添加你需要的所有东西,然后它就会神奇地工作