技术解析

求助:启动器从 openrc 切换到 systemd,因 systemd-networkd 配置网络,导致 dnsmasq 启动失败!
0
1975-02-23 08:48:39
idczone

如标题所述,自启动 dnsmasq 会失败,进入系统后手动启动 dnsmasq 服务则一切正常。 根据错误提示:

3 月 08 20:24:56 LINUX systemd[1]: Starting A lightweight DHCP and caching DNS server...

3 月 08 20:24:56 LINUX dnsmasq[228]: dnsmasq: syntax check OK.

3 月 08 20:24:56 LINUX systemd[1]: Started A lightweight DHCP and caching DNS server.

3 月 08 20:24:56 LINUX dnsmasq[232]: dnsmasq: failed to create listening socket for 10.0.1.1: 无法指定被请求的地址

3 月 08 20:24:国外服务器56 LINUX systemd[1]: dnsmasq.service: Main process exited, code=exited,,status=2/INVALIDARGUMENT

3 月 08 20:24:56 LINUX systemd[1]: dnsmasq.service: Failed with result 'exit-code'.

可知,是无法绑定我设置的局域网本机地址:10.0.1.1, 该地址是我用 systemd-networkd 配置的静态地址。根据系统启动后再次运行该服务又一切正常,初步判断是因为 dnsmasq 启动时,网络还没有配置好。

但是服务的依赖配置,感觉又没什么问题,不知道怎么解决了? 难道写个 sh 脚本,特意等待若干秒,再启动 dnsmasq ??

[Unit]

Description=A lightweight DHCP and caching DNS server

After=network.target

[Service]

Type=simple

ExecStartPre=/usr/sbin/dnsmasq --test

ExecStart=/usr/sbin/dnsmasq -k

ExecReload=/bin/kill -HUP $MAINPID

[Install]

WantedBy=multi-user.target


试试
After=network-online.target
Wants=network-online.target

试下改成这个
After=systemd-networkd.service
Before=network.target
参考自 systemd-resolved.setvice

systemd 非常的激进,你不显示指定 After 的全都会并行启动。
https://wiki.archlinux.org/index.php/Systemdsystemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit A requires the unit B to be running before A is started. In that case add Requires=B and After=B to the [Unit] section of A. If the dependency is optional, add Wants=B and After=B instead. Note that Wants= and Requires= do not imply After=, meaning that if After= is not specified, the two units will be started in parallel.

会导致一直等待服务中,没有真正运行程序。

现象一样……

开 ssh,让我上去看看

要暴力一点直接把 Restart=always 加进去

暂时这样暴力解决……

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服