callow
callow

Reputation: 517

checking Marklogic connection by shell script

I need a shell script that checks Marklogic connection status.I would pass the connection uri to script and the script would check if the connection is working. What's a way of doing that?

Upvotes: 2

Views: 806

Answers (3)

Oscar Foley
Oscar Foley

Reputation: 7025

MarkLogic 6.x or lesser

Here is the function that I use. If it returns HTTP 20X (200) everything is ok. Otherwise server has problems.

function PingMarkLogic($server)
{
    $uri = "http://$($server):8001/cluster-status.xqy"
    $adminCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist "admin", $(ConvertTo-SecureString "admin" -Force -AsPlainText)
    try
    {
        $resp1 = Invoke-WebRequest -Uri $Uri -Method "GET" -Credential $adminCredential -ContentType "application/x-www-form-urlencoded" -ErrorAction SilentlyContinue
        return $resp1.StatusCode
    }
    catch [System.Net.WebException] 
    {
        return $resp1.StatusCode
    }

}

If you want to detect if it is installed but not configured (for example waiting for entering License) add -MaximumRedirection 0 to Invoke-WebRequest and look for HTTP 302 response as request to http://server:8001/cluster-status.xqy would be redirected giving a 302 and the redirection will return HTTP 200

MarkLogic 7.x or higher

There is a new default AppServer called HealthCheck in port 7997. It has the advantage that does not require credentials. More info here

The function then is easier

function PingMarkLogic($server)
{
    $uri = "http://$($server):7997"
    try
    {
        $resp1 = Invoke-WebRequest -Uri $Uri -Method "GET" -ContentType "application/x-www-form-urlencoded" -ErrorAction SilentlyContinue
        return $resp1.StatusCode
    }
    catch [System.Net.WebException] 
    {
        return $resp1.StatusCode
    }

}

Upvotes: 1

DALDEI
DALDEI

Reputation: 3732

In V7 xcc and app server URL's are incompatible. XCC uses xcc://user:name@host:port App servers use http://host:port

the xcc scheme wont be recognized by a pure HTTP client nor will it be recognized by marklogic's app server.

So first - you need to define what "running" means to you. In V7 there is a new 'HealthCheck" app which is primarily for use on AWS but has the side effect of being a builtin application on MarkLogic which can be accessed via HTTP with a get and returns "200 OK" if the marklogic server is both running and "healthy" ... You can change how it determines that, out of the box the definition of "healthy" is that the server is fully installed and has access to the security database.

The HealthCheck app runs on port 7997 ... so any program that can do a get to

http://server:7997

Can check if it returns "200 OK' or not

But to refine the answer, what do you mean by "connection" ... the standard definition of "connection" cannot be sent to an unrelated program by a URL as a "connection" is a currently active HTTP (TCP/IP) connection - that doesn't map to a URL ... its a property of the currently running program.

but if you mean "Is the server active" the above suggestion should work. If you mean "Is this particular marklogic app up and running" then you need to create a "status" or "healthcheck" or reuse one, but it shouldn't have side effects. You don't want your connection check to reuse say the "delete all documents" endpoint.

Upvotes: 1

grtjn
grtjn

Reputation: 20414

Do you want to know whether MarkLogic service is running, or whether a particular app server within MarkLogic is running? I guess I would send an HTTP request to one of the MarkLogic ports. If that responds, it is alive..

HTH!

Upvotes: 0

Related Questions