如标题所述,自启动 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
1
codehz 2021-03-08 20:46:18 +08:00 via Android
试试
After=network-online.target Wants=network-online.target |
2
jim9606 2021-03-08 20:50:13 +08:00
试下改成这个
After=systemd-networkd.service Before=network.target 参考自 systemd-resolved.setvice |
3
Jirajine 2021-03-08 20:52:32 +08:00 via Android
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. |
6
defunct9 2021-03-08 23:19:12 +08:00 via iPhone
开 ssh,让我上去看看
|
7
tinkerer 2021-03-09 00:21:45 +08:00
要暴力一点直接把 Restart=always 加进去
|