【发布时间】:2016-11-25 07:05:34
【问题描述】:
我的 Spring Boot 应用程序有一个 systemd 服务,连接到 consul 服务器,位于 haproxy 后面。 consul提供consul-template通过consul-template命令自动更新haproxy配置文件中的服务位置。
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 也不起作用。
非常感谢任何帮助。
【问题讨论】:
-
将
consul-template进程分离到它自己的systemd 单元可能会更成功。
标签: linux fork systemd consul consul-template