运行我有一个systemd
服务连接到服务器consul
我春天启动的应用程序,背后haproxy
。 consul
提供consul-template
经由consul-template
命令自动更新haproxy
配置文件中的服务位置。让ExecStartPost命令在后台
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
回来,我有我的两个应用和领事模板进程运行。
有没有办法运行在
ExecStartPost
指定在后台consul-template
过程?
我试图在ExecStartPost
命令的末尾添加&
,但随后consul-template
抱怨说,它是一个额外的无效参数,它失败。
我也试图使命令/bin/sh -c "consul-template command here..."
,但后来这也不起作用。即使nohup
在此命令中也不起作用。
任何帮助非常感谢。
你可能与'领事template'过程中分离到自己更成功系统单元。 – Amir