「apachectl restart」は機能しますが、「apachectl start」は機能しないのはなぜですか?

「apachectl restart」は機能しますが、「apachectl start」は機能しないのはなぜですか?

Ubuntu 18.04を使用しています。 「sudo apachectl start」を使用してApache2を再起動できないようです。私はこれを見る

~$ sudo apachectl start
Invoking 'systemctl start apache2'.
Use 'systemctl status apache2' for more info.
Job for apache2.service failed because a timeout was exceeded.
See "systemctl status apache2.service" and "journalctl -xe" for details.
Action 'start' failed.
The Apache error log may have more information.

状態を確認してみる

$ 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 Fri 2021-01-22 16:01:25 UTC; 2min 2s ago
  Process: 1453 ExecStart=/usr/sbin/apachectl start (code=killed, signal=TERM)

Jan 22 15:56:25 prod systemd[1]: Starting The Apache HTTP Server...
Jan 22 15:56:25 prod apachectl[1453]: Invoking 'systemctl start apache2'.
Jan 22 15:56:25 prod apachectl[1453]: Use 'systemctl status apache2' for more info.
Jan 22 16:01:25 prod systemd[1]: apache2.service: Start operation timed out. Terminating.
Jan 22 16:01:25 prod systemd[1]: apache2.service: Failed with result 'timeout'.
Jan 22 16:01:25 prod systemd[1]: Failed to start The Apache HTTP Server.

"journalctl -xe"は次のように言います。

$ sudo journalctl -xe
Jan 22 15:56:25 prod apachectl[1453]: Use 'systemctl status apache2' for more info.
Jan 22 16:00:00 prod sshd[1475]: Received disconnect from 113.128.15.170 port 50036:11: Bye Bye [preauth]
Jan 22 16:00:00 prod sshd[1475]: Disconnected from authenticating user root 113.128.15.170 port 50036 [preauth]
Jan 22 16:00:01 prod CRON[1477]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 22 16:00:01 prod CRON[1478]: (root) CMD (/bin/bash -l -c '/opt/scripts/import_coop_data_from_google_sheet.sh >> /tmp/cronoutput.txt 2>&1')
Jan 22 16:00:18 prod sshd[1499]: Received disconnect from 218.93.208.150 port 25505:11:  [preauth]
Jan 22 16:00:18 prod sshd[1499]: Disconnected from authenticating user root 218.93.208.150 port 25505 [preauth]
Jan 22 16:00:44 prod CRON[1477]: (CRON) info (No MTA installed, discarding output)
Jan 22 16:00:44 prod CRON[1477]: pam_unix(cron:session): session closed for user root
Jan 22 16:01:25 prod systemd[1]: apache2.service: Start operation timed out. Terminating.
Jan 22 16:01:25 prod sudo[1446]: pam_unix(sudo:session): session closed for user root
Jan 22 16:01:25 prod systemd[1]: apache2.service: Failed with result 'timeout'.
Jan 22 16:01:25 prod systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit apache2.service has failed.
-- 
-- The result is RESULT.
Jan 22 16:02:26 prod sshd[1525]: Received disconnect from 221.181.185.135 port 57424:11:  [preauth]
Jan 22 16:02:26 prod sshd[1525]: Disconnected from authenticating user root 221.181.185.135 port 57424 [preauth]
Jan 22 16:02:28 prod sshd[1528]: Invalid user drcomadmin from 207.244.247.57 port 45316
Jan 22 16:02:28 prod sshd[1528]: Received disconnect from 207.244.247.57 port 45316:11: Bye Bye [preauth]
Jan 22 16:02:28 prod sshd[1528]: Disconnected from invalid user drcomadmin 207.244.247.57 port 45316 [preauth]
Jan 22 16:03:07 prod sudo[1531]: davea : TTY=pts/0 ; PWD=/home/davea ; USER=root ; COMMAND=/bin/systemctl status apache2.service
Jan 22 16:03:07 prod sudo[1531]: pam_unix(sudo:session): session opened for user root by davea(uid=0)
Jan 22 16:03:09 prod sudo[1531]: pam_unix(sudo:session): session closed for user root
Jan 22 16:03:28 prod sudo[1535]: davea : TTY=pts/0 ; PWD=/home/davea ; USER=root ; COMMAND=/bin/systemctl status apache2.service
Jan 22 16:03:28 prod sudo[1535]: pam_unix(sudo:session): session opened for user root by davea(uid=0)
Jan 22 16:03:28 prod sudo[1535]: pam_unix(sudo:session): session closed for user root
Jan 22 16:03:47 prod sudo[1538]: davea : TTY=pts/0 ; PWD=/home/davea ; USER=root ; COMMAND=/bin/journalctl -xe
Jan 22 16:03:47 prod sudo[1538]: pam_unix(sudo:session): session opened for user root by davea(uid=0)

しかし、奇妙なことに、「sudo apachectl restart」を実行すると、Apacheが表示され、対話できます。

$ sudo apachectl restart
httpd not running, trying to start

どうなりますか?以下は私のサービス設定ファイルです...

$ sudo cat /lib/systemd/system/apache2.service
[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

ベストアンサー1

理論的には、システムにサービスとして設定されているため、サービスを再起動するために実行可能プログラムを実行しても効果はありません。 "systemctl restart apache2"を使用する必要があります。停止するには、「systemctl stop apache2」と入力して「systemctl start apache2」から始めてください。

http://manpages.ubuntu.com/manpages/bionic/man5/systemd.service.5.html

おすすめ記事