運行我有一個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