I'm using Ubuntu 18.04 with the default install of Apache, in which I configured a virtual directory. I would like to run Apache as a srevice, that automatically starts when the system reboots. I noticed Apache wasn't running upon system restart and then noticed this
$ sudo /etc/init.d/apache2 start [sudo] password for davea: [....] Starting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because a timeout was exceeded. See "systemctl status apache2.service" and "journalctl -xe" for details. failed! davea
I wasn't sure what it meant so I tried getting the status as recommended above ...
$ sudo systemctl status apache2.service ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: failed (Result: timeout) since Mon 2021-01-18 19:00:16 UTC; 4min 33s ago Process: 800 ExecStart=/usr/sbin/apachectl start (code=killed, signal=TERM) Jan 18 18:58:47 prod systemd: Starting The Apache HTTP Server... Jan 18 18:58:47 prod apachectl: Invoking 'systemctl start apache2'. Jan 18 18:58:47 prod apachectl: Use 'systemctl status apache2' for more info. Jan 18 19:00:16 prod systemd: apache2.service: Start operation timed out. Terminating. Jan 18 19:00:16 prod systemd: apache2.service: Failed with result 'timeout'. Jan 18 19:00:16 prod systemd: Failed to start The Apache HTTP Server.
I'm still unclear what else I need to do. I'm able to restart Apache without any problems using
$ sudo apachectl restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 2607:f298:5:101d:f816:3eff:feac:4c03. Set the 'ServerName' directive globally to suppress this message
Not sure why there is a warning or if I shoudl be concerned about it but I defined the "ServerName" in my conf file below
What else do I need to do to get Apache to run as a service upon system startup?
Edit: In response to comments, here's configtest and journalctl output immediately after restarting ...
$ sudo apachectl configtest AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 2607:f298:5:101d:f816:3eff:feac:4c03. Set the 'ServerName' directive globally to suppress this message Syntax OK $ sudo journalctl -xe -- -- Unit UNIT has finished starting up. -- -- The start-up result is RESULT. Jan 22 01:36:35 prod systemd: Started User Manager for UID 1001. -- Subject: Unit email@example.com has finished start-up -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Unit firstname.lastname@example.org has finished starting up. -- -- The start-up result is RESULT. Jan 22 01:36:35 prod systemd: Reached target Default. -- Subject: Unit UNIT has finished start-up -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Unit UNIT has finished starting up. -- -- The start-up result is RESULT. Jan 22 01:36:35 prod systemd: Startup finished in 219ms. -- Subject: User manager start-up is now complete -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- The user manager instance for user 1001 has been started. All services queued -- for starting have been started. Note that other services might still be starting -- up or be started at any later time. -- -- Startup of the manager took 219137 microseconds. Jan 22 01:36:55 prod systemd-timesyncd: Synchronized to time server [2001:67c:1560:8003::c8]:123 (ntp.ubuntu.com). Jan 22 01:37:03 prod sudo: davea : TTY=pts/0 ; PWD=/home/davea ; USER=root ; COMMAND=/bin/journalctl -xe Jan 22 01:37:03 prod sudo: pam_unix(sudo:session): session opened for user root by davea(uid=0)
Edit 2: Contents of /lib/systemd/system/apache2.service after attempting suggested answer ...
[Unit] Description=The Apache HTTP Server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking EnvironmentFile=/etc/environment ExecStart=/usr/sbin/apachectl start ExecStop=/usr/sbin/apachectl stop ExecReload=/usr/sbin/apachectl graceful PrivateTmp=true Restart=on-abort TimeoutStartSec=300 [Install] WantedBy=multi-user.target
Rebooting still fails to start Apache. However, when I manually run "sudo apachectl restart" that starts things up.