为什么“systemd”无法识别 etcd 的别名? [已关闭]

问题描述 投票:0回答:1

我的服务取决于

etcd2

# vim: ft=systemd :

[Unit]
Description=SkyDNS Service
After=docker.service
After=etcd2.service
Requires=docker.service
Requires=etcd2.service

[Service]
EnvironmentFile=/etc/environment
# XXX: Must set HOME in order to make docker load its config file
Environment=HOME=/home/core
Environment=TAG=prd-2020-05-08

TimeoutStartSec=0
ExecStartPre=/usr/bin/docker pull project/skydns:${TAG}
ExecStartPre=-/usr/bin/docker rm -f skydns
ExecStartPre=/usr/bin/etcdctl set \
  /skydns/ca/plntr/hosts/%m '{"host":"${COREOS_PRIVATE_IPV4}"}'
ExecStartPre=/usr/bin/etcdctl set \
  /skydns/ca/plntr/hosts/%H '{"host":"${COREOS_PRIVATE_IPV4}"}'
ExecStart=/bin/bash -c '                                           \
  set -ex;                                                         \
  docker run -t --name skydns --net host                           \
    -e SERVICE_IGNORE=true                                         \
    project/skydns:${TAG}                                         \
      -addr 172.17.42.1:53                                         \
      -local "%m.hosts.plntr.ca"                                   \
      -nameservers 8.8.8.8:53                                      \
      -domain plntr.ca.;                                           \
'
ExecStop=-/usr/bin/docker rm -f skydns
Restart=always
RestartSec=3

但这会失败,因为依赖项无法启动:

░░
░░ A start job for unit etcd2.service has finished with a failure.
░░
░░ The job identifier is 5453 and the job result is failed.
Aug 14 13:29:06 ip-172-31-4-62 systemd[1]: Starting etcd - highly-available key value store...
░░ Subject: A start job for unit etcd2.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit etcd2.service has begun execution.
░░
░░ The job identifier is 5540.
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: recognized and used environment variable ETCD_DATA_DIR=/var/lib/etcd/defa>
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: recognized and used environment variable ETCD_NAME=ip-172-31-4-62
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: etcd Version: 3.3.25
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: Git SHA: Not provided (use ./build instead of go build)
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: Go Version: go1.18.1
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: Go OS/Arch: linux/amd64
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: setting maximum number of CPUs to 4, total number of available CPUs is 4
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: the server is already initialized as member before, starting as etcd memb>
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: listening for peers on http://localhost:2380
Aug 14 13:29:06 ip-172-31-4-62 etcd[19508]: listen tcp 127.0.0.1:2379: bind: address already in use
Aug 14 13:29:06 ip-172-31-4-62 systemd[1]: etcd2.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecStart= process belonging to unit etcd2.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Aug 14 13:29:06 ip-172-31-4-62 systemd[1]: etcd2.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit etcd2.service has entered the 'failed' state with result 'exit-code'.
Aug 14 13:29:06 ip-172-31-4-62 systemd[1]: Failed to start etcd - highly-available key value store.
░░ Subject: A start job for unit etcd2.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit etcd2.service has finished with a failure.
░░
░░ The job identifier is 5540 and the job result is failed.

我很好奇。

etcd
服务有一个别名为
etcd2
,所以我想在检查
systemd
etcd
的依赖性时,
etcd2
应该检测到
skydns
已经启动。这是我的配置文件:

$ sudo systemctl list-units --type=service | grep etcd
  etcd.service                                   loaded active running etcd - highly-available key value store
● etcd2.service                                  loaded failed failed  etcd - highly-available key value store

/lib/systemd/system/etcd.service

[Unit]
Description=etcd - highly-available key value store
Documentation=https://etcd.io/docs
Documentation=man:etcd
After=network.target
Wants=network-online.target

[Service]
Environment=DAEMON_ARGS=
Environment=ETCD_NAME=%H
Environment=ETCD_DATA_DIR=/var/lib/etcd/default
EnvironmentFile=-/etc/default/%p
Type=notify
User=etcd
PermissionsStartOnly=true
#ExecStart=/bin/sh -c "GOMAXPROCS=$(nproc) /usr/bin/etcd $DAEMON_ARGS"
ExecStart=/usr/bin/etcd $DAEMON_ARGS
Restart=on-abnormal
#RestartSec=10s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
Alias=etcd2.service                       #<<<--- NOTICE THIS

/etc/systemd/system/etcd2.service

[Unit]
Description=etcd - highly-available key value store
Documentation=https://etcd.io/docs
Documentation=man:etcd
After=network.target
Wants=network-online.target

[Service]
Environment=DAEMON_ARGS=
Environment=ETCD_NAME=ip-172-31-4-62
Environment=ETCD_DATA_DIR=/var/lib/etcd/default
EnvironmentFile=-/etc/default/%p
Type=notify
User=etcd
PermissionsStartOnly=true
#ExecStart=/bin/sh -c "GOMAXPROCS=$(nproc) /usr/bin/etcd $DAEMON_ARGS"
ExecStart=/usr/bin/etcd $DAEMON_ARGS
Restart=on-abnormal
#RestartSec=10s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
Alias=etcd2.service

我检查了

systemd
没有看到配置的别名:

$ systemctl show -p Id --value etcd.service
etcd.service
$ systemctl show -p Id --value etcd2.service
etcd2.service
$ systemctl show -p Names --value etcd.service
etcd.service
$ systemctl show -p Names --value etcd2.service
etcd2.service

如何配置

systemd
,以便将
etcd
etcd2
视为别名?

alias systemd
1个回答
1
投票

根据 systemd 的 systemd.unit 手册页,systemd 使用符号链接作为别名:

通过在单元搜索路径之一中创建从新名称到现有名称的符号链接,可以为单元设置别名(具有备用名称)

Alias
部分中的
[Install]
配置也会创建符号链接:

单元文件可以通过 [Install] 部分中的 Alias= 指令指定别名。当启用该单元时,将为这些名称创建符号链接,并在禁用该单元时将其删除。

所以我推断您的别名配置已损坏。尝试删除文件 /etc/systemd/system/etcd2.service 并创建指向 /lib/systemd/system/etcd.service 的符号链接 /lib/systemd/system/etcd2.service - 如果这还不存在。

在尝试该解决方案之前,您可能应该保留要删除的文件的副本,以防万一,以便在出现真正问题时可以恢复它。

© www.soinside.com 2019 - 2024. All rights reserved.