zaki work log

作業ログやら生活ログやらなんやら

(小ネタ) systemctlでサービスの有効化と起動を同時に設定

systemctl enableのオプションに--nowというのを追加できた…!

いつもいつも

# systemctl enable docker
# systemctl start docker

みたいに実行してて、「コマンド2回たたくの面倒だなー」か、「インストールしたときenable忘れて、何日も経った後にrebootしたらサービスが起動してないムキー」のどっちかをよくやらかしてたんだけど、

# systemctl enable --now docker

で有効化と起動を同時に設定できました。

以下man systemctlより。

--now

When used with enable, the units will also be started. When used with disable or mask, the units will also be stopped. The start or stop operation is only carried out
when the respective enable or disable operation has been successful.


Installing kubeadm - Kubernetes

これ見てて初めて知った。


Ansibleだとsystemdモジュールとか使えば、enabled: yesも設定しておけば、restartやstartついでにenable設定もやってくれる。