nginx service start needs to wait dns service
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
nginx (Ubuntu) |
Triaged
|
Undecided
|
Unassigned |
Bug Description
When using nginx as reverse proxy you can have one or more upstream server set up with a hostname instead of its IP address like this:
upstream myUpstream {
server this-host-
}
If nginx it's started *before* the DNS subsystem it's working nginx won't be started because it cannot resolve the this-host-
# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/
Active: failed (Result: exit-code) since Tue 2023-06-06 06:45:48 CEST; 20s ago
Docs: man:nginx(8)
Process: 561 ExecStartPre=
Jun 06 06:45:48 ip-172-31-9-7 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 06 06:45:48 ip-172-31-9-7 nginx[561]: nginx: [emerg] host not found in upstream "this-host-
Jun 06 06:45:48 ip-172-31-9-7 nginx[561]: nginx: configuration file /etc/nginx/
Jun 06 06:45:48 ip-172-31-9-7 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jun 06 06:45:48 ip-172-31-9-7 systemd[1]: nginx.service: Failed with result 'exit-code'.
Jun 06 06:45:48 ip-172-31-9-7 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
To fix this we need to set on systemd some other targets to be waited before the nginx service it's started.
I tried with this change but it doesn't worked.
# diff /etc/systemd/
16c16
< After=network.
---
> After=network-
I fixed it setting an ip address on the upstream but I think a simple bug like this should be fixed.
Regards,
tags: | added: network-online-ordering |
Hello and thanks for your bug report. This is part of a wider category of bugs caused by the fact that some services require network to be "up" to start correctly, but the definition of "network is up" is tricky. The issue is not adding After=network- online. target, but is defining what network- online. target should represent. An approach is being discussed here:
https:/ /discourse. ubuntu. com/t/spec- definition- of-an-online- system/ 27838