V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
xivisi
V2EX  ›  Linux

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

  •  
  •   xivisi · 2021-03-08 20:31:30 +08:00 · 1837 次点击
    这是一个创建于 1116 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如标题所述,自启动 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 条附言  ·  2021-03-08 22:03:12 +08:00
    添加 ExecStartPre=/bin/ifconfig lan1 后,发现确实如猜测那样,静态 ip 还没有配置进去。
    8 条回复    2021-03-09 21:18:38 +08:00
    codehz
        1
    codehz  
       2021-03-08 20:46:18 +08:00 via Android
    试试
    After=network-online.target
    Wants=network-online.target
    jim9606
        2
    jim9606  
       2021-03-08 20:50:13 +08:00
    试下改成这个
    After=systemd-networkd.service
    Before=network.target
    参考自 systemd-resolved.setvice
    Jirajine
        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.
    xivisi
        4
    xivisi  
    OP
       2021-03-08 21:01:20 +08:00
    @codehz 会导致一直等待服务中,没有真正运行程序。
    xivisi
        5
    xivisi  
    OP
       2021-03-08 21:01:38 +08:00
    @jim9606 现象一样……
    defunct9
        6
    defunct9  
       2021-03-08 23:19:12 +08:00 via iPhone
    开 ssh,让我上去看看
    tinkerer
        7
    tinkerer  
       2021-03-09 00:21:45 +08:00
    要暴力一点直接把 Restart=always 加进去
    xivisi
        8
    xivisi  
    OP
       2021-03-09 21:18:38 +08:00
    @tinkerer 暂时这样暴力解决……
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3297 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:50 · PVG 21:50 · LAX 06:50 · JFK 09:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.