Linux

systemd 終止使用 podman 啟動的 etcd 服務 - 僅允許主 PID 接收

  • August 21, 2021

我嘗試將etcd作為在podman容器中執行的 systemd 服務啟動。

啟動後,我從 systemd 收到此錯誤日誌:

systemd[1]: etcd.service: Got notification message from PID 4696, but reception only permitted for main PID 4868

但是 etcd 似乎可以開始嘗試通知容器守護程序:

21T15:31:08.817Z","caller":"etcdserver/server.go:2500","msg":"cluster version>
Aug 21 15:31:08 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:31:08.817Z","caller":"etcdmain/main.go:47","msg":"notifying init daemon>
Aug 21 15:31:08 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:31:08.818Z","caller":"etcdmain/main.go:53","msg":"successfully notified>

但 systemd 似乎沒有意識到這一點並終止了 etcd 服務:

Aug 21 15:32:34 ip-10-0-0-71 systemd[1]: etcd.service: start operation timed out. Terminating.
Aug 21 15:32:35 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:32:35.000Z","caller":"osutil/interrupt_unix.go:64","msg":"received sign>
Aug 21 15:32:35 ip-10-0-0-71 podman[4696]: {"level":"info","ts":"2021-08-21T15:32:35.000Z","caller":"embed/etcd.go:367","msg":"closing etcd server","n>

這是 systemd 服務狀態:

$ sudo systemctl status etcd.service
● etcd.service - etcd
    Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: enabled)
    Active: failed (Result: timeout) since Sat 2021-08-21 15:32:35 UTC; 8min ago
   Process: 4868 ExecStart=/usr/bin/podman run -p 2380:2380 -p 2379:2379 --volume=/var/lib/etcd:/etcd-data:z --name etcd 842445240665.dkr.ecr.eu-nort>
  Main PID: 4868 (code=exited, status=0/SUCCESS)
       CPU: 3.729s

這是我從 podman 開始的 etcd 的 systemd 單元服務文件:

cat <<EOF | sudo tee /etc/systemd/system/etcd.service
[Unit]
Description=etcd
After=podman_ecr_login.service mk_etcd_data_dir.service

[Service]
Type=notify
ExecStart=/usr/bin/podman run -p 2380:2380 -p 2379:2379 --volume=/var/lib/etcd:/etcd-data:z \
--name etcd <my-aws-account>.dkr.ecr.eu-north-1.amazonaws.com/etcd:v3.5.0 \
/usr/local/bin/etcd --data-dir=/etcd-data \
--name etcd0 \
--advertise-client-urls http://127.0.0.1:2379 \
--listen-client-urls http://0.0.0.0:2379 \
--initial-advertise-peer-urls http://127.0.0.1:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster etcd0=http://127.0.0.1:2380

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable etcd
sudo systemctl start etcd

我懷疑這可能與Type=notify我使用 podman 或 etcd 的方式有關。我以與 etcd 文件中所述類似的方式啟動 etcd:在容器內執行 etcd 集群 - 執行單個節點 etcd。我在 Debian 11 上使用 Podman 3.0.1 執行它。

關於如何使用 podman 作為 systemd 服務啟動 etcd 的任何建議?

根據此問題評論,這些服務應該執行,Type=simple因為它們不會向 systemd 發出信號。這個podman 的PR設置它Type=exec似乎也很好用。

Type=exec在我的服務單元文件中更改後,它現在可以工作:

$ sudo systemctl status etcd.service
● etcd.service - etcd
    Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: enabled)
    Active: active (running) since Sat 2021-08-21 15:59:23 UTC; 1min 28s ago
  Main PID: 4662 (podman)
     Tasks: 11 (limit: 442)
    Memory: 137.9M
       CPU: 3.576s
    CGroup: /system.slice/etcd.service
            ├─4662 /usr/bin/podman run -p 2380:2380 -p 2379:2379 --volume=/var/lib/etcd:/etcd-data:z --name etcd <my-aws-account>.dkr.ecr.eu-north-1.amaz>
            └─4846 /usr/bin/conmon --api-version 1 -c 616b317dc255ca86b308857dc6a180510fc166975a8a28437f3434111f03e7ad -u 616b317dc255ca86b308857dc6a>

引用自:https://serverfault.com/questions/1075280