My service depends on 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
But this fails because a dependency can not start:
░░
░░ 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.
I am curious. The etcd
service has an alias as etcd2
, so I suppose systemd should detect that etcd
has already started, when checking the etcd2
dependency for skydns
. Here are my configuration files:
$ 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
I checked, systemd
does not see that configured alias:
$ 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
How can I configure systemd
, so it counts etcd
and etcd2
as aliases?
According to systemd's systemd.unit manpage, systemd uses symlinks for aliases:
Units can be aliased (have an alternative name), by creating a symlink from the new name to the existing name in one of the unit search paths
Setting Alias
config in the [Install]
section creates also symlinks:
Unit files may specify aliases through the Alias= directive in the [Install] section. When the unit is enabled, symlinks will be created for those names, and removed when the unit is disabled.
So I would deduct that you have a broken alias configuration. Try to remove the file /etc/systemd/system/etcd2.service and create a symlink /lib/systemd/system/etcd2.service that points to /lib/systemd/system/etcd.service - if that is not already existing.
You should probably keep a copy of the file you are going to remove before you try that solution, just in case, so you can restore it in case something goes really wrong.