systemd 终止使用 podman 启动的 etcd 服务 - 仅允许主 PID 接收

systemd 终止使用 podman 启动的 etcd 服务 - 仅允许主 PID 接收

我尝试开始etcd作为 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 启动 etcd 作为 systemd 服务,有什么建议吗?

答案1

根据这个问题评论,这些服务应该按如下方式运行,Type=simple因为它们不会向 systemd 发出信号。这公共关系将 podman 设置为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>

相关内容