0

我有一个systemd服务,用于连接到consul服务器的 Spring Boot 应用程序,位于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

现在,当我 start 时systemctl start myservice,我的应用程序启动并且调用consul-template也可以工作,但consul-template进程不会进入后台。我必须按下Ctl+C然后systemctl回来,我的应用程序和领事模板进程都在运行。

有没有办法consul-template在指定的后台运行进程ExecStartPost

我试图&在命令末尾添加ExecStartPost,但随后consul-template抱怨它是一个额外的无效参数并且它失败了。

我也试图将命令设为/bin/sh -c "consul-template command here...",但这也不起作用。即使nohup在这个命令中也不起作用。

非常感谢任何帮助。

4

1 回答 1

2

一种解决方法是将 bash 文件作为您的入口点,在其中添加您需要的所有内容,然后它就会神奇地工作

于 2016-12-10T20:13:26.170 回答