1

After a short period of monit running, I cannot then restart or stop apache, it says there is a conflict, something else using port 80. Apache still serves webpages fine and when I netstat -anp | grep 80 I still only see apache listening to :80.

when I start monit I get a 'not monitored' error for apache. I'm not sure if this is relevant to the problem, I am currently trying to resolve this.

Monit details below:

set httpd port 2812 and
#use address localhost  # only accept connection from localhost
allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server   and
allow *******:******      # require user '' with password ....
allow @monit           # allow users of group 'monit' to connect (rw)
allow @users readonly  # allow users of group 'users' to connect readonly

##monitor apache
check process apache with pidfile /var/run/httpd/httpd.pid
group apache
start program = "/etc/init.d/httpd start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

Output of monit -vv

 monit: Debug: Adding net allow '0.0.0.0/0.0.0.0'.
monit: Debug: Adding credentials for user '******'.
monit: Adding PAM group 'monit'.
monit: Adding PAM group 'users'.
Runtime constants:
 Control file       = /etc/monit.conf
 Log file           = /var/log/monit
 Pid file           = /var/run/monit.pid
 Debug              = True
 Log                = True
 Use syslog         = False
 Is Daemon          = True
 Use process engine = True
 Poll time          = 60 seconds with start delay 0 seconds
 Expect buffer      = 256 bytes
 Mail server(s)     = smtp.sendgrid.net:587(ssl) with timeout 30 seconds
 Mail from          = ******
 Mail subject       = monit alert --  $EVENT $SERVICE
 Mail message       = $EVENT Service $SERV..(truncated)
 Start monit httpd  = True
 httpd bind address = Any/All
 httpd portnumber   = 2812
 httpd signature    = True
 Use ssl encryption = False
 httpd auth. style  = Basic Authentication and Host/Net allow list
 Alert mail to      = *******
   Alert on         = All events

The service list contains the following entries:

Process Name          = apache
 Group                = apache
 Pid file             = /var/run/httpd/httpd.pid
 Monitoring mode      = active
 Start program        = '/etc/init.d/httpd start' timeout 30 second(s)
 Stop program         = '/etc/init.d/httpd stop' timeout 30 second(s)
 Existence            = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Pid                  = if changed 1 times within 1 cycle(s) then alert
 Ppid                 = if changed 1 times within 1 cycle(s) then alert
 Port                 = if failed 127.0.0.1:80 [HTTP via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Timeout              = If restarted 5 times within 5 cycle(s) then unmonitor

Process Name          = mysqld
 Group                = mysql
 Pid file             = /var/run/mysqld/mysqld.pid
 Monitoring mode      = active
 Start program        = '/etc/init.d/mysqld start' timeout 30 second(s)
 Stop program         = '/etc/init.d/mysqld stop' timeout 30 second(s)
 Existence            = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Pid                  = if changed 1 times within 1 cycle(s) then alert
 Ppid                 = if changed 1 times within 1 cycle(s) then alert
 Port                 = if failed 127.0.0.1:3306 [DEFAULT via TCP] with timeout 5 seconds 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
 Timeout              = If restarted 5 times within 5 cycle(s) then unmonitor

System Name           = system_ip-10-74-144-130.eu-west-1.compute.internal
 Monitoring mode      = active
Tofuwarrior
  • 229
  • 1
  • 3
  • 10

1 Answers1

0

The issue with not being able to connect is probably because the restart process isn't killing httpd properly so it never actually shuts down, which is why you get the error about port 80 being in use. I also suspect there might be something about Pid changing, as it will when httpd is started or restarted. The logs should give more information as to why it's failing.

However, httpd is usually solid as a daemon and I wouldn't force monit to restart it, just alert unless you have a critical state.

Simon Greenwood
  • 1,343
  • 9
  • 12
  • Thanks for the suggestion not to bother to restart, that actually works quite well. The pid is picked up directly from the pid file so is your query about the pid still valid? – Tofuwarrior Dec 19 '17 at 17:05
  • 1
    At a guess, the stop script was removing the pid file but not stopping the httpd process, and then creating a new pid before starting httpd correctly, so the pid file would change but the httpd process id it had saved would have failed so wouldn't exist. – Simon Greenwood Dec 19 '17 at 20:23