LoginSignup
1
2

More than 5 years have passed since last update.

systemdのunitファイルのExecStartにスペースが含まれるとき、うまく認識されないことがある

Posted at

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
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2