1

Whenever I try to start/restart my apache2 service using systemctl I get an error about it already running but not maching my pid file.

● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Mon 2017-01-09 21:42:38 EST; 16s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18354 ExecStop=/etc/init.d/apache2 stop (code=exited, status=1/FAILURE)
  Process: 18337 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)

Jan 09 21:42:38 username apache2[18337]: Action 'start' failed.
Jan 09 21:42:38 username apache2[18337]: The Apache error log may have more information.
Jan 09 21:42:38 username apache2[18337]:  *
Jan 09 21:42:38 username apache2[18354]:  * Stopping Apache httpd web server apache2
Jan 09 21:42:38 username apache2[18354]:  *
Jan 09 21:42:38 username apache2[18354]:  * There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand.
Jan 09 21:42:38 username systemd[1]: apache2.service: Control process exited, code=exited status=1
Jan 09 21:42:38 username systemd[1]: Failed to start LSB: Apache2 web server.
Jan 09 21:42:38 username systemd[1]: apache2.service: Unit entered failed state.
Jan 09 21:42:38 username systemd[1]: apache2.service: Failed with result 'exit-code'.

running ps aux | grep apache2 shows that something is already running, but I can't kill them. As soon as I kill them, they re-spawn under a different pid.

root       8931  0.0  0.2 227232 23632 ?        Ss   21:30   0:00 apache2 -DFOREGROUND
username   9193  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9194  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9195  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9196  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND
username   9197  0.0  0.1 227264  9056 ?        S    21:30   0:00 apache2 -DFOREGROUND

The apache log under /var/log/apache2/errors.log is empty.

attaching to the first pid using sudo strace -p 8931, I get:

strace: Process 8931 attached
select(0, NULL, NULL, NULL, {0, 58750}) = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0})     = 0 (Timeout)
wait4(-1, 0x7ffc2296e9bc, WNOHANG|WSTOPPED, NULL) = 0
select(0, NULL, NULL, NULL, {1, 0}^Cstrace: Process 8931 detached

repeated over and over again

running sudo /usr/sbin/apachectl -k start gives the following error. I'm not sure what is using port 80 though.

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action '-k start' failed.
The Apache error log may have more information.

after running sudo netstat -lnpt I found out that I forgot about a docker container I was running ...

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
...
tcp6       0      0 :::80                   :::*                    LISTEN      8856/docker-proxy
...
waspinator
  • 558
  • 2
  • 12
  • 22
  • Did you try to kill (kill -9 8931)? Where 8931 is the pid of apache2 process running as root. It shouldn't re-spawn. – lg. Jan 10 '17 at 08:13

2 Answers2

2

Active: failed (Result: exit-code) since Mon 2017-01-09 21:42:38 EST; 16s ago

this means service not been started properly, try to start manually using "#/apacheHome/bin/apachectl -k start/stop" and check in logs.

Manoj K
  • 77
  • 4
1

Run

sudo netstat -tulpn | grep :80

and you will get output something like

tcp     0      0 0.0.0.0:80        0.0.0.0:*      LISTEN      1066/lighttpd

Note the PID of the process listening to the port, in my case it was 1066. Then run

sudo kill -9 1066

Remember to change the pid with the one that is listening to the port, It might not be the same as 1066

This worked for me.

chicks
  • 3,639
  • 10
  • 26
  • 36
Muhammad Ali
  • 111
  • 2