启用的systemd单元无法在启动时启动


35

我有一个systemd-unit我的系统已启用的。问题是,重新启动后它不会重新启动。它取决于两个都按预期启动的其他服务。

该服务是已知的,已启用的并且已失效:

[centos@ansible-kube-4 ~]$ sudo systemctl status flanneld
flanneld.service - Flanneld overlay address etcd agent
   Loaded: loaded (/usr/lib/systemd/system/flanneld.service; enabled)
   Active: inactive (dead)

单位文件:

[centos@ansible-kube-4 ~]$ cat /usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
After=etcd.service

[Service]
Type=notify
Restart=always
RestartSec=3

EnvironmentFile=/etc/sysconfig/flanneld
EnvironmentFile=-/etc/sysconfig/docker-network
ExecStart=/usr/bin/flanneld -etcd-endpoints=${FLANNEL_ETCD} -etcd-prefix=${FLANNEL_ETCD_KEY} $FLANNEL_OPTIONS
ExecStartPost=/usr/libexec/flannel/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker

[Install]
WantedBy=multi-user.target

更新1

dmesg的输出:

$ dmesg | grep systemd
[    1.312165] systemd[1]: systemd 208 running in system mode. (+PAM +LIBWRAP +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ)
[    1.317238] systemd[1]: Detected virtualization 'kvm'.
[    1.319597] systemd[1]: Running in initial RAM disk.
[    1.323489] systemd[1]: No hostname configured.
[    1.324874] systemd[1]: Set hostname to <localhost>.
[    1.327570] systemd[1]: Initializing machine ID from KVM UUID.
[    1.389047] systemd[1]: Expecting device dev-disk-by\x2duuid-a78bb152\x2de525\x2d4f0e\x2d961a\x2dbf6147ac7d3e.device...
[    1.394577] systemd[1]: Starting -.slice.
[    1.396820] systemd[1]: Created slice -.slice.
[    1.397990] systemd[1]: Starting System Slice.
[    1.400212] systemd[1]: Created slice System Slice.
[    1.401503] systemd[1]: Starting Slices.
[    1.403556] systemd[1]: Reached target Slices.
[    1.404756] systemd[1]: Starting Timers.
[    1.406834] systemd[1]: Reached target Timers.
[    1.408042] systemd[1]: Starting Dispatch Password Requests to Console Directory Watch.
[    1.410065] systemd[1]: Started Dispatch Password Requests to Console Directory Watch.
[    1.413402] systemd[1]: Starting Paths.
[    1.415399] systemd[1]: Reached target Paths.
[    1.416574] systemd[1]: Starting Journal Socket.
[    1.418894] systemd[1]: Listening on Journal Socket.
[    1.420242] systemd[1]: Started dracut ask for additional cmdline parameters.
[    1.422150] systemd[1]: Starting dracut cmdline hook...
[    1.424870] systemd[1]: Started Load Kernel Modules.
[    1.426124] systemd[1]: Starting Journal Service...
[    1.429731] systemd[1]: Started Journal Service.
[    1.692884] systemd-udevd[213]: starting version 208
[    2.621300] systemd-journald[90]: Received SIGTERM
[    2.968711] systemd[1]: Successfully loaded SELinux policy in 274.569ms.
[    3.023076] systemd[1]: Relabelled /dev and /run in 20.031ms.
[    3.365195] systemd-udevd[382]: starting version 208
[    3.482910] systemd-journald[377]: Received request to flush runtime journal from PID 1

更新2

输出chkconfig

sudo chkconfig

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

输出systemctl list-dependencies flanneld

flanneld.service
├─system.slice
└─basic.target
  ├─microcode.service
  ├─rhel-autorelabel-mark.service
  ├─rhel-autorelabel.service
  ├─rhel-configure.service
  ├─rhel-dmesg.service
  ├─rhel-loadmodules.service
  ├─paths.target
  ├─slices.target
  │ ├─-.slice
  │ └─system.slice
  ├─sockets.target
  │ ├─dbus.socket
  │ ├─rpcbind.socket
  │ ├─systemd-initctl.socket
  │ ├─systemd-journald.socket
  │ ├─systemd-shutdownd.socket
  │ ├─systemd-udevd-control.socket
  │ └─systemd-udevd-kernel.socket
  ├─sysinit.target
  │ ├─dev-hugepages.mount
  │ ├─dev-mqueue.mount
  │ ├─kmod-static-nodes.service
  │ ├─proc-sys-fs-binfmt_misc.automount
  │ ├─sys-fs-fuse-connections.mount
  │ ├─sys-kernel-config.mount
  │ ├─sys-kernel-debug.mount
  │ ├─systemd-ask-password-console.path
  │ ├─systemd-binfmt.service
  │ ├─systemd-journal-flush.service
  │ ├─systemd-journald.service
  │ ├─systemd-modules-load.service
  │ ├─systemd-random-seed.service
  │ ├─systemd-sysctl.service
  │ ├─systemd-tmpfiles-setup-dev.service
  │ ├─systemd-tmpfiles-setup.service
  │ ├─systemd-udev-trigger.service
  │ ├─systemd-udevd.service
  │ ├─systemd-update-utmp.service
  │ ├─systemd-vconsole-setup.service
  │ ├─cryptsetup.target
  │ ├─local-fs.target
  │ │ ├─-.mount
  │ │ ├─rhel-import-state.service
  │ │ ├─rhel-readonly.service
  │ │ ├─systemd-fsck-root.service
  │ │ └─systemd-remount-fs.service
  │ └─swap.target
  └─timers.target
    └─systemd-tmpfiles-clean.timer

Answers:


32

单位文件已修改:

之前:

[Install]
RequiredBy=docker.service

后:

[Install]
WantedBy=multi-user.target

修改之后,我没有重新启用该单元。原来,这是systemd重新配置所必需的:

$ sudo systemctl reenable flanneld
rm '/etc/systemd/system/docker.service.requires/flanneld.service'
ln -s '/usr/lib/systemd/system/flanneld.service' '/etc/systemd/system/multi-user.target.wants/flanneld.service'

2
我也发现这有所帮助,我也不知道为什么。也许reenable纠正了我没做过的东西,或者因为我没有足够努力地斜视而看不见的东西。无论如何,在我配置为重启后启动服务的两台相同主机中,一台可以正常工作,而另一台直到我对它进行操作后才起作用。
Russ Bateman '18

1
是否有可能由于升级而被禁用?我有一台可疑服务器,升级后该服务器被禁用... sudo systemctl reenable rails-puma.service解决了这个问题
Dave Collins


9

我发现在您的配置中没有证据表明该服务应在引导时启动。 systemd允许通过两种方式启用服务,以便在引导时启动该服务:

chkconfig flanneld on

要么:

systemctl enable flanneld

实际上,第一种是调用第二种的旧方法,我不确定chkconfig默认情况下是否安装了该软件包,但是可以使用apt-get或安装它yum


服务已启用。我曾经sudo systemctl enable flanneld启用它。
maklemenz

运行后,它仍然无法启动吗?
nKn

每次重新启动后,我都必须手动启动该服务。它从第一次尝试开始,没有任何错误消息或警告。
maklemenz's

1
肯定还有其他失败的地方。正式地,在systemd中启用启动服务的方法是systemctl enable servicename。大多数示例还包括.service命令中的终止符,但是我不确定这应该有什么区别。
nKn

.service后缀在用户省略时会自动添加。
mrg2k8
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.