求助:启动器从 openrc 切换到 systemd,因 systemd-networkd 配置网络,导致 dnsmasq 启动失败!

2021-03-08 20:31:30 +08:00
 xivisi

如标题所述,自启动 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

1882 次点击
所在节点    Linux
8 条回复
codehz
2021-03-08 20:46:18 +08:00
试试
After=network-online.target
Wants=network-online.target
jim9606
2021-03-08 20:50:13 +08:00
试下改成这个
After=systemd-networkd.service
Before=network.target
参考自 systemd-resolved.setvice
Jirajine
2021-03-08 20:52:32 +08:00
systemd 非常的激进,你不显示指定 After 的全都会并行启动。

https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies

With systemd, 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.
xivisi
2021-03-08 21:01:20 +08:00
@codehz 会导致一直等待服务中,没有真正运行程序。
xivisi
2021-03-08 21:01:38 +08:00
@jim9606 现象一样……
defunct9
2021-03-08 23:19:12 +08:00
开 ssh,让我上去看看
tinkerer
2021-03-09 00:21:45 +08:00
要暴力一点直接把 Restart=always 加进去
xivisi
2021-03-09 21:18:38 +08:00
@tinkerer 暂时这样暴力解决……

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/759755

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX