I have a local website on Debian 11 which is rarely used so I thought I might want to start Apache using systemd socket activation when visiting the site and then shut down after few minutes of inactivity.
After installing apache on debian I stop and disable the service with systemctl disable --now apache2.service
, then create /etc/systemd/system/apache2.socket
with the following content, reload systemd with systemctl daemon-reload
, and start the socket with systemctl start systemd.socket
.
[Unit]
Description=Apache Server Socket
[Socket]
ListenStream=80
[Install]
WantedBy=sockets.target
I can confirm systemd is actually listening, and apache is started when visiting the site, but it stops immediately with error
apachectl[2794]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
apachectl[2794]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
According to this answer it should work.