4

I have this in my httpd.conf:

Listen 216.XX.YY.ZZZZ:80

Just to make sure, I made sure httpd is enabled at boot:

systemctl httpd enable

When the system boots, I have:

systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2017-02-23 22:21:03 PST; 8min ago
  Process: 719 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 719 (code=exited, status=1/FAILURE)

Feb 23 22:21:00 centosXXXXXX.aspadmin.net systemd[1]: Starting The Apache HTTP Server...
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address 216.XX.YY.XXX:80
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: no listening sockets available, shutting down
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: AH00015: Unable to open logs
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: Failed to start The Apache HTTP Server.
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: Unit httpd.service entered failed state.
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: httpd.service failed.

I can then start it by running:

systemctl start httpd

And everything works:

systemctl status httpd


● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-02-23 22:31:53 PST; 3s ago
 Main PID: 2804 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
       ├─2804 /usr/sbin/httpd -DFOREGROUND
       ├─2805 /usr/sbin/httpd -DFOREGROUND
       ├─2806 /usr/sbin/httpd -DFOREGROUND
       ├─2808 /usr/sbin/httpd -DFOREGROUND
       ├─2824 /usr/sbin/httpd -DFOREGROUND
       └─2831 /usr/sbin/httpd -DFOREGROUND

Feb 23 22:31:53 centosXXXXXX.aspadmin.net systemd[1]: Starting The Apache HTTP Server...
Feb 23 22:31:53 centosXXXXXX.aspadmin.net httpd[2804]: AH00558: httpd:     Feb 23 22:31:53 centosXXXXXX.aspadmin.net systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

The IP is assigned to eth0 using a normal network script in /etc/sysconfig/network-scripts/ifcfg-eth0.

Checking /lib/systemd/system/httpd.service I have:

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

The only similar problem on the net is here: https://unix.stackexchange.com/questions/207063/apache-httpd-failing-to-start-on-boot-centos-7 However, their advice:

systemctl enable NetworkManager-wait-online.service
Failed to execute operation: No such file or directory

Doesn't seem to work.

I am totally lost.

Merc
  • 789
  • 1
  • 6
  • 16
  • Do you really need to bind to a specific IP address? The answer is almost certainly no. And read https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ to understand the issue. – Michael Hampton Feb 24 '17 at 13:19
  • I have an Apache web server listening to an IP address for a list of public web sites, and an Nginx server listening to ANOTHER IP address being the reverse proxy for a bunch of nodeJS apps. So YES, absolutely. They will both listen to port 80. And ANYWAY, this is something BASIC that has been done a MILLION times without bloody systemd. I am starting to understand why people dislike it so much. – Merc Feb 25 '17 at 03:04
  • `systemctl enable systemd-networkd-wait-online.service` doesn't work on CentOs 7. At this point I need to find a way to create a service that is up once networking is actually setup AND make `httpd` depend on it. The "how" part escapes me, and I am AMAZED that CentOs doesn't come with it by default – Merc Feb 25 '17 at 03:07
  • I ran `# systemctl edit httpd.service` and added `After=network.target network-online.target remote-fs.target nss-lookup.target` . I saved the file -- although nothing seems to be saved under `/lib/systemd/system/httpd.service.d`. I also did `# systemctl enable network-online.target` . Still nothing. – Merc Feb 25 '17 at 03:15
  • "If you are a developer, instead of wondering what to do about network.target, please just fix your program to be friendly to dynamically changing network configuration." Is this suggesting I patch HTTPD so that it gracefully waits for the IP to be configured before binding...? Sorry I don't mean to sound cranky, It's just that this problem is proving way more difficult than it should be – Merc Feb 25 '17 at 03:18
  • Did you actually configure networking on the system with NetworkManager or systemd-networkd? You'll need to be using one of the two. If you are using only the old-style networking scripts then you can't really do this. – Michael Hampton Feb 25 '17 at 17:45
  • It's a server. I simply changed a config file. But, installing NetworkManager and adding `After=network.target NetworkManager-wait-online.service` actually worked. Was that just luck? – Merc Feb 25 '17 at 23:01
  • I assumed NetworkManager was somehow aware of the init scripts... – Merc Feb 25 '17 at 23:02
  • NetworkManager is aware of the old-style scripts and will import settings from them. But if it was never there in the first place... – Michael Hampton Feb 25 '17 at 23:09
  • Will it import then only once at install time? Or will it update its config when changing the old style scripts? If it doesn't update, how can you? Plus we call them old style scripts but... Are they really old? What are you meant to do with a server keeping up with the times? – Merc Feb 26 '17 at 00:25
  • I've made changes to them and they've always taken effect in NetworkManager for me. So I haven't worried much about it. But when I mean it's old-style, it's really old style. NM was introduced in RHEL 6. It will probably be replaced with systemd-networkd in RHEL 8, but that's still up in the air. – Michael Hampton Feb 26 '17 at 00:31
  • So to be not obsolete I should configure network interfaces with networkd? – Merc Feb 26 '17 at 02:29
  • Ask me again in a year or so. – Michael Hampton Feb 26 '17 at 02:31
  • @MichaelHampton, trust me... a lot of admin wants web servers compartmentalized at interface level. Think of it this way... corporate-specific website and public-facing Internet website... Separate web server. Peace of mind. – John Greene May 20 '17 at 17:59

1 Answers1

2

As it turns out, you need to use NetworkManager for this to work, since you want to wait for the IPs to actually be available. NetworkManager is not installed by default in CentOs 7.

So:

# yum install NetworkManager

Enable it:

systemctl enable NetworkManager-wait-online

Then:

# systemctl edit httpd.service

And add:

After=network.target NetworkManager-wait-online.service remote-fs.target nss-lookup.target

At this point, HTTPD will only start once the IP is assigned to the interface and bingo, it will actually start.

Merc
  • 789
  • 1
  • 6
  • 16