When restarting Apache after cleaning log directories, the service fails with the following error:
[root@localhost apache]# /etc/init.d/*_apache restart
Stopping *_apache: [FAILED]
Starting *_apache: (98)Address already in use: make_sock: could not bind to address [::]:99
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:99
no listening sockets available, shutting down
Unable to open logs
[FAILED]
The root cause becomes clear when examining the logs directory:
[root@localhost logs]# pwd
/usr/local/*/service/apache/logs
[root@localhost logs]# ll
total 28
-rw-r--r-- 1 root root 385 Mar 13 16:31 access_log
-rw-r--r-- 1 root root 1083 Mar 13 16:31 error_log
-rw-r--r-- 1 root root 6 Mar 13 16:12 httpd.pid
-rw-r--r-- 1 root root 3878 Mar 13 16:31 mail_access_log
-rw-r--r-- 1 root root 2273 Mar 13 16:31 mail_access_log_ip
-rw-r--r-- 1 root root 0 Mar 13 16:12 mail_error_log
-rw-r--r-- 1 root root 4771 Mar 13 16:31 mail_error_log_ip
[root@localhost logs]#
After deleting log files, the httpd.pid file was also removed. Without this file, Apache loses track of the master process ID, preventing clean shutdown and restart.
First, idenitfy the running Apache master process:
[root@localhost logs]# ps -ef|grep 'apache'
root 18369 1 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18371 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18372 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18373 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18374 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18375 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18384 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18386 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18387 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18388 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
9004 18389 18369 0 16:31 ? 00:00:00 /usr/local/*/service/apache/bin/httpd
root 18639 12792 0 16:41 pts/0 00:00:00 grep apache
[root@localhost logs]#
The master process ID is 18369 (PID 1). Recreate the PID file with this value:
echo "18369" > httpd.pid
Now restart Apache to restore normal operation.