Note |
---|
This page is outdated and no longer receives updates! |
This is meant to be a page to describe how to monitor your different instances of OpenMRS (and perhaps other hardware or software) to ensure it's up and running.
...
For those interested in how this line works:
status=$(IFS='
...
';r=($(curl
...
-Is
...
--connect-timeout
...
${timeout}
...
"${url}"
...
||
...
echo
...
1
...
500));echo
...
${r[1]});
I'll break it down…working from the inside out:
curl
...
-Is
...
--connect-timeout
...
${timeout}
...
"${url}"
uses the curl command to fetch the URL, waiting up to TIMEOUT seconds for it to respond. Option -I makes it return HTTP headers and -s silences output like a progress bar. The HTTP output starts with something like "HTTP/1.1 200 OK", where the second word is the status code that we want.
||
...
echo
...
1
...
500
follows the curl command, using the scripting "or" operator (||) to return "1 500" if the curl command comes up empty. The "1" is a dummy value, since we want "500" as the second word in this output to mimic a HTTP internal server error code 500. The above is wrapped in a $() to execute the command and its output is assigned to the variable r. The preceding IFS=' ' sets the input field separator to split the subsequent command's output on spaces -- in other words, thanks to the IFS=' ', the output of the curl command is broken apart into separate words. Finally, the echo ${r[1]} command at the end takes the value of variable r (our curl output, broken into words), retrieves the second word (we geeks start numbering at zero, so "1" is the second word), and echoes it into the status variable. When the line is done executing, we either have the HTTP status code (200 is good, 500 is bad) in the status variable.
...