systemd // 失败,结果为“dependency”

systemd // 失败,结果为“dependency”

我对这个systemd话题很陌生。我有一些单元有不同的要求、之后和之前。在某些单位上我收到如下消息:

tinc.service: Job tinc.service/start failed with result 'dependency'.

但具体是哪个依赖关系呢?这就是我试图深入研究问题的方法:

core@chimp ~ $ systemctl status tinc.service
● tinc.service - Tinc VPN Service
   Loaded: loaded (/etc/systemd/system/tinc.service; static; vendor preset: disabled)
   Active: inactive (dead)

May 04 18:09:18 chimp systemd[1]: Dependency failed for Tinc VPN Service.
May 04 18:09:18 chimp systemd[1]: tinc.service: Job tinc.service/start failed with result 'dependency'.

看看需要哪些服务...

core@chimp ~ $ cat /etc/systemd/system/tinc.service
[Unit]
Description=Tinc VPN Service
Requires=flannel-wait.service
After=flanneld.service tinc-env.service flannel-wait.service

#Before=early-docker.target

[Service]
Restart=always
RestartSec=3
Environment="DOCKER_HOST=unix:///var/run/early-docker.sock"
EnvironmentFile=/etc/tinc-env

EnvironmentFile=/etc/environment


ExecStartPre=/usr/bin/docker pull jenserat/tinc
ExecStartPre=/usr/bin/rm -rf /srv/tinc
ExecStartPre=/usr/bin/mkdir -p /srv/tinc
ExecStartPre=/bin/sh -c "/usr/bin/docker run --rm --volume /srv/tinc:/etc/tinc  jenserat/tinc init $TINC_HOSTNAME"
ExecStartPre=/bin/sh -c "/usr/bin/docker run --rm --volume /srv/tinc:/etc/tinc  jenserat/tinc add Address = $COREOS_PUBLIC_IPV4"
EnvironmentFile=/run/flannel/subnet.env
ExecStartPre=/bin/sh -c "/usr/bin/docker run --rm --volume /srv/tinc:/etc/tinc  jenserat/tinc add Subnet = `echo $FLANNEL_SUBNET | sed -e 's/1\\/24/0\\/24/'`"
ExecStartPre=/bin/sh -c "/usr/bin/docker run --rm --volume /srv/tinc:/etc/tinc  jenserat/tinc add Mode = switch"
ExecStartPre=/bin/sh -c "/usr/bin/docker run --rm --volume /srv/tinc:/etc/tinc  jenserat/tinc add DeviceType = tap"
ExecStartPre=-/usr/bin/docker rm -f tinc
ExecStartPre=/usr/bin/docker run --name tinc  -d --volume /srv/tinc:/etc/tinc --net=host --device=/dev/net/tun --cap-add NET_ADMIN jenserat/tinc start  -D

ExecStart=/bin/sh -c "while true; do etcdctl set /services/tinc/$TINC_HOSTNAME  \"\\\"` cat /srv/tinc/hosts/$TINC_HOSTNAME `\"\\\" --ttl 60;sleep 45;done"

#ExecStop=/usr/bin/docker rm -f tinc
ExecStopPost=/bin/sh -c  "etcdctl rm /services/tinc/$TINC_HOSTNAME"

继续flannel-wait.service

core@chimp ~ $ systemctl status flannel-wait.service
● flannel-wait.service - Wait For Flannel
   Loaded: loaded (/etc/systemd/system/flannel-wait.service; static; vendor preset: disabled)
   Active: inactive (dead)

May 04 18:09:18 chimp systemd[1]: Dependency failed for Wait For Flannel.
May 04 18:09:18 chimp systemd[1]: flannel-wait.service: Job flannel-wait.service/start failed with result 'dependency'.
core@chimp ~ $ cat /etc/systemd/system/flannel-wait.service

[Unit]
Description=Wait For Flannel
Requires=flanneld.service
After=flanneld.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo \"TINC_HOSTNAME=`hostname | sed -e 's/-/_/g'`\" > /etc/tinc-env"
ExecStartPre=/bin/sh -c "while [ ! -f /run/flannel/subnet.env ] ; do sleep 1; done"

钻德珀..

core@chimp ~ $ systemctl status flanneld.service
● flanneld.service - Network fabric for containers
   Loaded: loaded (/usr/lib64/systemd/system/flanneld.service; static; vendor preset: disabled)
  Drop-In: /etc/systemd/system/flanneld.service.d
           └─50-network-config.conf
   Active: active (running) since Wed 2016-05-04 18:09:24 CEST; 12min ago
     Docs: https://github.com/coreos/flannel
  Process: 929 ExecStartPost=/usr/bin/docker run --net=host --rm -v /run:/run quay.io/coreos/flannel:${FLANNEL_VER} /opt/bin/mk-docker-opts.sh -d /run/flannel_docker_opts.env -i (code=exited, status=0/SUCCESS)
  Process: 879 ExecStartPre=/usr/bin/etcdctl set /coreos.com/network/config { "Network": "10.1.0.0/16", "Backend": { "Type": "alloc"} } (code=exited, status=0/SUCCESS)
  Process: 877 ExecStartPre=/usr/bin/touch ${FLANNEL_ENV_FILE} (code=exited, status=0/SUCCESS)
  Process: 875 ExecStartPre=/usr/bin/mkdir -p ${ETCD_SSL_DIR} (code=exited, status=0/SUCCESS)
  Process: 873 ExecStartPre=/usr/bin/mkdir -p /run/flannel (code=exited, status=0/SUCCESS)
  Process: 871 ExecStartPre=/sbin/modprobe ip_tables (code=exited, status=0/SUCCESS)
 Main PID: 886 (sdnotify-proxy)
   Memory: 12.0M
      CPU: 93ms
   CGroup: /system.slice/flanneld.service
           ├─886 /usr/libexec/sdnotify-proxy /run/flannel/sd.sock /usr/bin/docker run --net=host --privileged=true --rm --volume=/run/flannel:/run/flannel --env=NOTIFY_SOCKET=/run/flannel/sd.sock --env=AW...
           └─889 /usr/bin/docker run --net=host --privileged=true --rm --volume=/run/flannel:/run/flannel --env=NOTIFY_SOCKET=/run/flannel/sd.sock --env=AWS_ACCESS_KEY_ID= --env=AWS_SECRET_ACCESS_KEY= --e...

May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.131290 00001 main.go:275] Installing signal handlers
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.139346 00001 main.go:188] Using 178.XXXXXX as external interface
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.139363 00001 main.go:189] Using 178.XXXXX as external endpoint
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.140740 00001 etcd.go:129] Found lease (10.1.6.0/24) for current IP (178.XXXX), reusing
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.176357 00001 etcd.go:84] Subnet lease acquired: 10.1.6.0/24
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.234997 00001 ipmasq.go:50] Adding iptables rule: FLANNEL -d 10.1.0.0/16 -j ACCEPT
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.237095 00001 ipmasq.go:50] Adding iptables rule: FLANNEL ! -d 224.0.0.0/4 -j MASQUERADE
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.256054 00001 ipmasq.go:50] Adding iptables rule: POSTROUTING -s 10.1.0.0/16 -j FLANNEL
May 04 18:09:24 chimp sdnotify-proxy[886]: I0504 16:09:24.258241 00001 ipmasq.go:50] Adding iptables rule: POSTROUTING ! -s 10.1.0.0/16 -d 10.1.0.0/16 -j MASQUERADE
May 04 18:09:24 chimp systemd[1]: Started Network fabric for containers.

据我了解,flannel-wait.service依赖于flanneld.service正在运行的 -which 。但归根结底,为什么会失败呢?

提前致谢!

答案1

我的猜测是 flanneld.service 必须下载 flannel 容器,这可能需要一秒钟的时间。您的 flannel 等待可能已等待依赖项的默认时间(可能是 30 秒?),然后失败。我不确定它是如何影响这一点的。对于普通服务,您只需添加 restart=always 就可以了。我不确定一次性是否可以有重新启动参数,因为它实际上设计为运行一次。但这只是猜测。

相关内容