When will monit actually start or restart a service - monit

Can someone please let me know on what basis monit decides that its time to restart an application? For instance, if I want monit to monitor my web application, what information should I provide to monit based on which it will restart?
thanks
Update:
I was able to kind of make it work using the following monit config
check host altamides with address web.dev1.ams
if failed port 80 with protocol http
then alert
However, I was wondering if I can use any absolute URL of my application. Something like http://foo:5453/test/url/1.html/
Can someone help me on that please?

Monit by himself will not restart any service, but you can provide to it the rules you want to perform it, you can do something like
check process couchdb with pidfile /usr/local/var/run/couchdb/couchdb.pid
start program = "/etc/init.d/couchdb start"
stop program = "/etc/init.d/couchdb stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if memory usage > 70% MB for 5 cycles then restart
check host mmonit.com with address mmonit.com
if failed port 80 protocol http then alert
if failed port 443 protocol https then alert

I figured the answer from monit help page
if failed
port 80
protocol http
request "/data/show?a=b&c=d"
then restart

Related

getting lots of 408 status code in apache access log after migration from http to https

We are getting lots of 408 status code in apache access log and these are coming after migration from http to https .
Our web server is behind loadbalancer and we are using keepalive on and keepalivetimeout value is 15 sec.
Can someone please help to resolve this.
Same problem here, after migration from http to https. Do not panic, it is not a bug but a client feature ;)
I suppose that you find these log entries only in the logs of the default (or alphabetically first) apache ssl conf and that you have a low timeout (<20).
As of my tests these are clients establishing pre-connected/speculative sockets to your web server for fast next page/resource load.
Since they only establish the initial socket connection or handshake ( 150 bytes or few thousands) the connect to the ip and do not specify a vhost name, and got logged in the default/firs apache conf log.
After few secs from the initial connection they drop the socket if not needed or the use is for faster further request.
If your timeout is lower than these few secs you get the 408 if is higher apache doesn't bother.
So either you ignore them / add a different default conf for apache, or you rise the timeout having more apache processes busy waiting from the client to drop or use the socket.
see https://bugs.chromium.org/p/chromium/issues/detail?id=85229 for some related discussions

How do I free port 80? [duplicate]

I installed XAMPP 1.6.8 and for some reason it didn't work. Later realized port 80 is not free or not listening. How can I release it or make it free?
Thanks a lot!
I found out that what was taking over port 80 is http api service. I wrote in cmd:
net stop http
Asked me "The following services will be stopped, do you want to continue?" Pressed y
It stopped a number of services actually.
Then wrote localhost and wallah, Apache is up and running on port 80.
Important: Skype uses port 80 by default, you can change this in skype options > advanced > connection - and uncheck "use port 80"
netstat -ano
That will show you the PID of the process that is listening on port 80.
After that, open the Task Manager -> Processes tab. From the View -> Select Columns menu, enable the PID column, and you will see the name of the process listening on port 80.
I had this problem previously,
if you see the Task manager(after enabling the view for PID), you will find PID=4 is "port 80 in use by NT Kernel & System; "
Just go to
Control Panel
Programs
Turn Windows features on/off
check if the World wide web services under IIS is checked
If so, Uncheck and netstat(or TCPVIEW) again to see if 80 is free.
netstat -a -b
Should tell you what program is bound to port 80
use netstat -bano in an elevated command prompt to see what apps are listening on which ports.
But Usually following applications uses port 80 in windows.
IIS
World Wide Web Publishing service
IIS Admin Service
SQL Server Reporting services
Web Deployment Agent Service
Stop above applications if running and check!!!
Use TcpView to find the process that listens to the port and close the process.
Other option to try is to stop SQL Server Reporting Services.
You can use net stop http it will display which process is using. Moslty world wide web services are using
Try
netstat -anb -p tcp
that show ports and processes
I was trying to install nginx from here - http://nginx.org/en/docs/windows.html
Going to http://localhost/ will show something, at least a proper "not found" message
This is because 80 is the default port, and it was taken by other processes.
Now run below command:
net stop http
// Above command stopped below services
// - SSDP Discovery
// - Print Spooler
// - BranchCache
// - Function Discovery Resource Publication
// - Function Discovery Provider Host
Now, going to http://localhost/ will fail with a broken link page message.
Main process was BranchCache
This process, after stopped, will restart in a few seconds.
So we need to run other commands we need soon, an example below:
// this will stop
net stop http
// immeidately run other command you want to
start nginx
Now, going to http://localhost/ gave me:
Welcome to nginx!
Hope that helps.
Type in "netstat -ano" into your command line. I saw that it was showing something for Local Address port 0.0.0.0:80.
My issue was because I had SQL Server Reporting Services on Port 80. So I followed these instructions and changed the port # from 80 to 81:
http://seankilleen.com/2012/11/how-to-stop-sql-server-reporting-services-from-using-port-80-on-your-server-field-notes/
Here is a picture of my command line AFTER I changed the port number for SQL Server Reporting Services:
If you are still having the same issue, read this forum:
http://forum.wampserver.com/read.php?2,66196,66233#REPLY
This is just a guess, but since port 80 is the conventional port for HTTP, you may have a webserver running on your system. Is IIS active?
If you are running IIS you may have the web farm service running. That was what was killing my xampp.
Skype likes to use port 80 and blocks IIS. That was my prob.
I also had the same problem. net stop http didn't help and World wide web services option under IIS in Windows Control Panel was unchecked. So in XAMPP control panel I just checked the Svc checkbox near Apache start button (Install Apache as service) and rebooted Windows. And now each time Windows starts Apache is started automatically and occupies port 80 before any other service does. Worked for me!
Known Windows Services That Listen on Port 80
From Services Manager (run: services.msc), stop and disable these Windows Services which are known to bind to port 80.
Double click Service, and change ‘Startup Type’ to ‘Disabled’…
SQL Server Reporting Services (ReportServer)
Web Deployment Agent Service (MsDepSvc)
BranchCache (PeerDistSvc)
Sync Share Service (SyncShareSvc)
World Wide Web Publishing Service (W3SVC)
Internet Information Server (WAS, IISADMIN)
skype also using port 80 as default setting and you can uncheck it.
You might, or might not, have some of these Services installed and running.
In my case "SQL Server Reporting Services" was opening port 80.
Identify the real process programmatically
(when the process ID is shown as 4)
The answers here, as usual, expect a level of interactivity.
The problem is when something is listening through HTTP.sys; then, the PID is always 4 and, as most people find, you need some tool to find the real owner.
Here's how to identify the offending process programmatically. No TcpView, etc (as good as those tools are). Does rely on netsh; but then, the problem is usually related to HTTP.sys.
$Uri = "http://127.0.0.1:8989" # for example
# Shows processes that have registered URLs with HTTP.sys
$QueueText = netsh http show servicestate view=requestq verbose=yes | Out-String
# Break into text chunks; discard the header
$Queues = $QueueText -split '(?<=\n)(?=Request queue name)' | Select-Object -Skip 1
# Find the chunk for the request queue listening on your URI
$Queue = #($Queues) -match [regex]::Escape($Uri -replace '/$')
if ($Queue.Count -eq 1)
{
# Will be null if could not pick out exactly one PID
$ProcessId = [string]$Queue -replace '(?s).*Process IDs:\s+' -replace '(?s)\s.*' -as [int]
if ($ProcessId)
{
Write-Verbose "Identified process $ProcessId as the HTTP listener. Killing..."
Stop-Process -Id $ProcessId -Confirm
}
}
Originally posted here: https://stackoverflow.com/a/65852847/6274530
I faced the same issue and fixed it by making a small change in the httpd.conf file which can be obtained by clicking the config button along with the Apache option.
The change I made was to replace listen 80 with listen 8080.
For me, this problem began when I hosted a VPN-connection on my Windows 8 computer.
Simply deleting the connection from "Control Panel\Network and Internet\Network Connections" solved the problem.

XAMPP,Apache - Error: Apache shutdown unexpectedly

I got the same error of shutdown unexpectedly. I tried everything.
I uninstalled skype.
I tried changing the ports to 81,444 / 81,443 / 88/443 / 80,443(default).
I went to services and tried killing required one.
I went to windows firewall and created the new inbound rule too.
I uninstalled old apache and installed new one too. This worked for 1 day.
I checked whether the port 80 is busy or not but none of the services is using port
80,443. I used netstat -a command to check all the list of port for Win-8.
I tried stopping windows http services by "NET STOP HTTP".
I unchecked "Internet Information Services" from program and features.
I checked "Resource Monitor" for port usage. Port 80 is being used by HTTP server only
but not responding to xampp control panel.
In all of the above cases, I made the changes and restarted the laptop every time to take the effect. But nothing has worked. Each time i got the same error i.e "XAMPP, Apache - Error: Apache shutdown unexpectedly".
Please give me the solution for this error. I am very much frustrated now. Please help me. Any help would be appreciable. Thank you in advance.
It would be good if you enable Apache Logs in debug mode.
LogLevel debug
Also you can get easily notified for syntax issues with help of below command.
httpd -t
For your skype, go to Tools -> Options -> Advanced -> connection. Disable the "Use port 80 and 443 for alternatives for incoming connections"
Sign Out and Close all Skype windows. Try restart your Apache again.

Apache Daemon trying to Ping on CentOS but not working (SELinux issue)

I have developped an application in php. One of its functions is to ping an external server.
However, when this action was fired nothing happened. I checked the SELinux log and generated a policy to allow apache daemon to ping (ping works fine if log in as apache user). After installing that policy, no error is shown on SELinux log, but on the httpd log appears a lot of times:
ping: recvmsg: Permission denied
I know it is a SELinux configuration problem (Socket connection maybe?) because if I disable it, it works nice, but this is not an option for me.
I have redirected the output of the ping command to a text file and, after firing the action, this is the result:
PING myhost (myip) 56(84) bytes of data.
--- myhost ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 13002ms
So I am kind of stuck at this point. Anyone can help me?
Thanks a lot.
After a fresh install it all worked. Don't mess with policies, kids.

Apache webserver error on startup [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I just switch to Apache webserver and I receive an error
(OS 10048)Only one usage of each socket address (protocol/network
address/port) is normally permitted. : make_sock: could not bind to
address 0.0.0.0:443 no listening sockets available, shutting down
Unable to open logs
That is what I have got after running httpd from commandline. I reset my apache documentRoot as well as server's listening port to one that is free to use already, I have no idea about this error with port 443, is it something about SSL ?
UPDATE
I am using XP
For Windows XP
netstat -ano
Find the process id that is using port 443, and kill it using task manager
For me it was IIS using the port.
Copying and pasting your exact error into google gave a couple of answers:
https://wiki.apache.org/httpd/CouldNotBindToAddress
Port 443 seems to already be in use. Possibly by your old server. One of the three covered errors in the official apache wiki above is:
Address is already in use
Something else is already using the port in question.
Run one of the following commands to check if a running process is
holding the port needed by apache open.
On Linux/Unix run
$> netstat -plant
$> # or
$> sudo lsof -i:80
On Windows run
$> netstat -ano
On Mac OS X / FreeBSD run
$> netstat -Wan |grep 80
$> # or, to get the pid
$> sudo lsof -i:80
Once you see these results, you can choose to kill the program in
question, or change the port that Apache uses.
If Apache (httpd, apache2, etc) is the application listening on these
ports, but you can't stop it using your normal procedure, someone may
have deleted the servers PidFile. The PidFile records the process ID
of the parent process and is how most scripts test to see if Apache is
running. You can manually stop the server by determining the PID of
the parent process and sending it a SIGTERM.
For me it was having multiple directives of Listen 443 in my /etc/apache2/ports.conf file. Even though netstat and/or ps showed nothing for 443, it was still trying to listen multiple times, which in turn threw that error.
It sounds like you already have apache running. Use nestat to figure out which process is using 443 and kill it.
netstat -tulpn | grep :443
Then
kill PROCESS_ID
Where PROCESS_ID is the number of the process that is shown when you the netstat command (example: kill 12345).
After that try starting apache again.
I found on my system (Win7) that Skype had taken over the port that Apache was trying to use. In the new version of Skype I haven't yet found the checkbox to uncheck so that Skype doesn't use it (there was one in a previous version). Quitting Skype enabled Apache to start.
port 443 is for SSL. Seems you miss the rights to use that privileged port. Privileged ports are those with numbers below 1024.
Which OS are you using?
Probably something else is already using port 443 and therefore Apache is unable to use it, do you want to use SSL actually ?