Apache2 won't auto-start even with unit file update post reboot
Issue : after server reboot apache2 won't automatically start (have to manually ssh and start via systemctl which starts without any issue)
Error message:
Feb 08 05:53:46 domain1_test.com systemd[1]: Starting The Apache HTTP Server...
Feb 08 05:53:47 domain1_test.com apachectl[834]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80
Feb 08 05:53:47 domain1_test.com apachectl[834]: no listening sockets available, shutting down
Feb 08 05:53:47 domain1_test.com apachectl[834]: AH00015: Unable to open logs
Feb 08 05:53:47 domain1_test.com apachectl[809]: Action 'start' failed.
Feb 08 05:53:47 domain1_test.com apachectl[809]: The Apache error log may have more information.
Feb 08 05:53:47 domain1_test.com systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
Feb 08 05:53:47 domain1_test.com systemd[1]: apache2.service: Failed with result 'exit-code'.
Current apache setup :
# port.conf
Listen xxx.xxx.xx.xx:80
Listen xxx.xxx.xx.xx:443
Listen [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80
Listen [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:443
---
# domain1_test.com.conf
<VirtualHost xxx.xxx.xx.xx:80 [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:80>
....
<VirtualHost xxx.xxx.xx.xx:443 [xxxx:xxxx::xxxx:xxxx:xxxx:xxxx]:443>
I have already tested adding network dependency through target and wants in the apache2 unit file but still getting the cannot bind socket error upon checking on the apache2 status post reboot
[Unit]
Description=The Apache HTTP Server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
Documentation=https://httpd.apache.org/docs/2.4/
[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl stop
ExecReload=/usr/sbin/apachectl graceful
PrivateTmp=true
Restart=on-abort
[Install]
WantedBy=multi-user.target
Environment :
- Linode
Ubuntu 20.04.2 LTS
Apache/2.4.41
- VirtualMin/webmin
Interface conf:
iface eth0 inet dhcp
iface eth0 inet6 manual
pre-up /sbin/modprobe -q ipv6 ; /bin/true
systemd network conf:
[Match]
Name=eth0
[Network]
DHCP=no
DNS=xxx.x.xx.xx xxx.xxx.xx.x xxx.xxx.xx.x
Domains=members.linode.com
IPv6PrivacyExtensions=false
Gateway=xxx.xxx.xx.x
Address=xxx.xxx.xx.xx/24
Appreciate any inputs on the matter 🙏
6 Replies
Welcome to the wonderful world of systemd! This kind of stuff is pretty common…which is why I hate it so much (and stopped using Linux because of it).
-- sw
Although I'm personally more knowledgable with NGINX, but I found this post on Gentoo Forums that seems to walk-through how to remedy this issue:
If you haven't done this already, you may also want to enable Apache to automatically start on boot: (sudo) systemctl enable apache2
In case you happen to be using both Apache and NGINX, this Linode Community Questions post addresses both configuration steps for using Apache as a proxy for NGINX and visa versa:
yeah, systemd is quite a handful esp for a newbie like me 😅
@jhartman yep, I have done those as well. I checked whether anything was using port 80 but i don't see anything. May I confirm how Linode is auto configuring the ipv6? I'm thinking the auto configuration for it might be delayed so when the server reboots it only initially configures ipv4 then gives the signal for the network-online.target
and then automatically configures ipv6 that's why after the reboot i have to login and when i manually turn apache2 on it's able to run successfully.
*adding more info for the environment on the question above^
The IPV6 guide indicates the following:
All Compute Instances are created with one IPv6 address, which is acquired by Stateless Address Autoconfiguration (SLAAC).
You can find out more about SLAAC here.
Blake
Thank you very much for the info @tech10!! Now i'm exploring on how to properly execute a script that checks for the presence of the ipv6 before starting the Apache server.
current work around I have implemented is to add the snippet below in the apache unit service file:
ExecStartPre=/bin/sleep 10
Admittedly it's a bit hacky so I'm wondering if there's a better way to do it.
Thank you very much for the info @tech10!! Now i'm exploring on how to properly execute a script that checks for the presence of the ipv6 before starting the Apache server.
current work around I have implemented is to add the snippet below in the apache unit service file:
ExecStartPre=/bin/sleep 10
Admittedly it's a bit hacky so I'm wondering if there's a better way to do it.