如何让 kea-dhcp4-server 在 Ubuntu 22.04 上启动期间等待 postgresql 数据库准备就绪?

如何让 kea-dhcp4-server 在 Ubuntu 22.04 上启动期间等待 postgresql 数据库准备就绪?

我的 kea-dhcp4-server 依赖于我的 postgresql 数据库。重新启动后,dhcp 服务器出现如下错误:

    sudo systemctl status kea-dhcp4-server
× kea-dhcp4-server.service - Kea IPv4 DHCP daemon
     Loaded: loaded (/lib/systemd/system/kea-dhcp4-server.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kea-dhcp4-server.service.d
             └─override.conf
     Active: failed (Result: exit-code) since Sun 2024-02-11 17:09:18 UTC; 11min ago
       Docs: man:kea-dhcp4(8)
    Process: 1104 ExecStart=/usr/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf (code=exited, status=1/FAILURE)
   Main PID: 1104 (code=exited, status=1/FAILURE)
        CPU: 39ms

Feb 11 17:09:18 ns1 systemd[1]: Started Kea IPv4 DHCP daemon.
Feb 11 17:09:18 ns1 kea-dhcp4[1104]: 2024-02-11 17:09:18.166 ERROR [kea-dhcp4.dhcp4/1104.140666424032896] DHCP4_CONFIG_LOAD_FAIL configuration error using file: /etc/kea/kea-dhcp4.conf, reason: Unable to open database: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection>
Feb 11 17:09:18 ns1 kea-dhcp4[1104]:         Is the server running on that host and accepting TCP/IP connections?
Feb 11 17:09:18 ns1 kea-dhcp4[1104]: 2024-02-11 17:09:18.166 ERROR [kea-dhcp4.dhcp4/1104.140666424032896] DHCP4_INIT_FAIL failed to initialize Kea server: configuration error using file '/etc/kea/kea-dhcp4.conf': Unable to open database: connection to server at "localhost" (127.0.0.1), port 5432>
Feb 11 17:09:18 ns1 kea-dhcp4[1104]:         Is the server running on that host and accepting TCP/IP connections?
Feb 11 17:09:18 ns1 systemd[1]: kea-dhcp4-server.service: Main process exited, code=exited, status=1/FAILURE
Feb 11 17:09:18 ns1 systemd[1]: kea-dhcp4-server.service: Failed with result 'exit-code'.

所以看起来 Postgresql 数据库稍后启动和/或尚未准备好。注意:当我手动启动此 kea-dhcp4-sever 服务时,一切正常。

我在编辑 kea-dhcp4-server.service 时尝试了不同的选项,使用:

sudo systemctl edit kea-dhcp4-server

用 Wants=、After= 和 Requires= 都进行了测试,但没有成功。

甚至可能是 Postgres <== Network ==> Dhcp 服务器之间的循环依赖关系?

所以我的问题是:如何让 kea-dhcp4-server 在 Ubuntu 22.04 上启动期间等待 postgresql 数据库准备就绪?

答案1

回答我自己的问题:

也许我在 kea-dhcp4-server.service 的 override.conf 中输入了太多内容。当我尝试这个时,启动顺序变得正确并且可以工作:

more /etc/systemd/system/kea-dhcp4-server.service.d/override.conf
[Unit]
Requires=postgresql.service
After=postgresql.service

相关内容