systemdのunitファイルを書いてたのですが、どうにもうまく動かない。
/etc/systemd/system/consul-template.service
[Unit]
Description=consul-template
After=consul.service haproxy.service
[Service]
ExecStart=/usr/local/bin/consul-template -consul=127.0.0.1:8500 -template=/etc/haproxy/haproxy.cfg.ctmpl:/etc/haproxy/haproxy.cfg:"/bin/systemctl reload haproxy.service"
KillMode=process
Type=simple
Restart=always
[Install]
WantedBy=multi-user.target
ログを見るとどうも後半のhaproxyのreloadのあたりでコマンドがぶった切られている模様。
Jun 15 18:09:51 hogehoge systemd[1]: Starting consul-template...
Jun 15 18:09:51 hogehoge systemd[1]: Started consul-template.
Jun 15 18:09:51 hogehoge consul-template[19818]: Consul Template returned errors:
Jun 15 18:09:51 hogehoge consul-template[19818]: cli: extra argument(s): ["reload" "haproxy.service\""]
Jun 15 18:09:51 hogehoge systemd[1]: consul-template.service: main process exited, code=exited, status=14/n/a
Jun 15 18:09:51 hogehoge systemd[1]: Unit consul-template.service entered failed state.
スペースの前にバックスラッシュ入れたらうまく動きました。
/etc/systemd/system/consul-template.service
[Unit]
Description=consul-template
After=consul.service haproxy.service
[Service]
ExecStart=/usr/local/bin/consul-template -consul=127.0.0.1:8500 -template=/etc/haproxy/haproxy.cfg.ctmpl:/etc/haproxy/haproxy.cfg:"/bin/systemctl\ reload\ haproxy.service"
KillMode=process
Type=simple
Restart=always
[Install]
WantedBy=multi-user.target