SOLVED /usr/local/cpanel/scripts/restartsrv_httpd doesn't restart Apache

PeteS

Well-Known Member
Jun 8, 2017
189
35
28
Oregon
cPanel Access Level
Root Administrator
/usr/local/cpanel/scripts/restartsrv_httpd does not restart Apache (nor does /usr/local/cpanel/scripts/restartsrv_apache). It has been that way for some time, apparently. I discovered this when I noticed that the Engintron plugin's Apache restart didn't work, so I pursured as a bug with them first. It calls this script, which appears to be correct, so I tried on CLI and it doesn't restart it, per systemctl status httpd.service

I can restart from WHM (what does WHM call?), and on CLI via systemctl restart httpd.service.

Can anyone else confirm this or help with it?

-Pete
 

cPanelLauren

Technical Support Community Manager
Staff member
Nov 14, 2017
11,472
1,033
313
Houston
What occurs when you run this script through CLI? It definitely performs a graceful restart of apache on my system so I'm not able to replicate this behavior:

Code:
[[email protected] ~]# /scripts/restartsrv_httpd
Waiting for “httpd” to restart gracefully …waiting for “httpd” to initialize ………finished.

Service Status
    httpd (/usr/sbin/httpd -k start) is running as root with PID 2083 (systemd+/proc check method).

Startup Log
    May 03 13:00:05 server.myhostname.us systemd[1]: Starting Apache web server managed by cPanel EasyApache...
    May 03 13:00:07 server.myhostname.us systemd[1]: Can't open PID file /run/apache2/httpd.pid (yet?) after start: No such file or directory
    May 03 13:00:07 server.myhostname.us systemd[1]: Started Apache web server managed by cPanel EasyApache.

Log Messages
    [Mon May 04 13:37:27.116322 2020] [mpm_event:notice] [pid 2083:tid 46996269315136] AH00489: Apache/2.4.43 (cPanel) OpenSSL/1.1.1g mod_bwlimited/1.4 configured -- resuming normal operations
<SNIPPED>

httpd restarted successfully.
[[email protected] ~]#
If you want a hard restart of apache:

Code:
 /scripts/restartsrv_httpd --stop
Code:
/scripts/restartsrv_httpd --start
or alternatively:
Code:
/scripts/restartsrv_httpd --restart --hard
After a hard restart:
Code:
# apachectl status
               Apache Server Status for localhost (via 127.0.0.1)

   Server Version: Apache/2.4.43 (cPanel) OpenSSL/1.1.1g mod_bwlimited/1.4

   Server MPM: event

   Server Built: Apr 27 2020 15:46:38

   --------------------------------------------------------------------------

   Current Time: Monday, 04-May-2020 14:40:58 CDT

   Restart Time: Monday, 04-May-2020 14:40:52 CDT
The help information in the script explains what restart is performed by default:

Code:
[[email protected] ~]# /scripts/restartsrv_httpd --help
/scripts/restartsrv_httpd - manage service httpd

Usage: /scripts/restartsrv_httpd [ACTION] [OPTIONS]

The default action is to restart the httpd service.

The script returns 0 in case of success,
and a positive integer in case of an error.

Note: Error output is displayed on STDERR.

Available actions:
   --help           Display this help message.
   --restart        Restart the service (via a soft restart, if available). [default action]
   --hard           Perform a hard restart (skip the soft restart).
                    This is the default action if soft restarts aren't supported for the service.
   --graceful       Attempt a graceful restart of the service, if the service supports this action.
   --reload         Reload the service, if the service supports this action.
   --stop           Stop the service.
   --status         Return the current service status via the exit code.

Available options:
   --notconfigured-ok    Services that are not configured will exit with a non-fatal return code
                             (this does not mean they'll carry out the requested action, ie start)

Sample usages:
# Restart the service (using a "soft" or "graceful" restart when supported)
> /scripts/restartsrv_httpd
> /scripts/restartsrv_httpd --restart
# Stop the service.
> /scripts/restartsrv_httpd --stop
# Perform a hard restart.
> /scripts/restartsrv_httpd --restart --hard
 

PeteS

Well-Known Member
Jun 8, 2017
189
35
28
Oregon
cPanel Access Level
Root Administrator
It appears to restart, giving the output expected as you post (with variations appropriate to my server), but when I check the uptime/PID, nothing has changed.

What gets called in WHM?

WHM and systemctl restart httpd.service work as expected (new PID and uptime).

-Pete
 

PeteS

Well-Known Member
Jun 8, 2017
189
35
28
Oregon
cPanel Access Level
Root Administrator
Ah, so it is! Thanks for clarifying.

Systemctl restart defaults to a hard restart.

Am I correct that WHM restarts apache with --hard since there is no option for graceful (as there is with reboot)? You can mark SOLVED after your response.

Thanks, again!

-Pete