Re: Checking that Pg is running from a shell script - Mailing list pgsql-general

From Vincent Stoessel
Subject Re: Checking that Pg is running from a shell script
Date
Msg-id 3D060224.6020707@xaymaca.com
Whole thread Raw
In response to Checking that Pg is running from a shell script  (Fran Fabrizio <ffabrizio@mmrd.com>)
List pgsql-general
This is very cool, thanks!

Ericson Smith wrote:
> Hi,
>
> We use this small attached perl script to directly check the port on 2
> running DB servers and write the status to a file. Our webserver farm
> then checks this file every time we need to use the DB.
>
> In our case, we just serve up static content if there is no database,
> otherwise we continue our work.
>
> This script will also timeout after 10 seconds, so it wont wait forever
> checking a dead PG port.
>
> - Ericson Smith
> info@w3matter.com
> http://www.swapyourcrap.com
>
> On Mon, 2002-06-10 at 15:33, Vincent Stoessel wrote:
>
>>Can pg_ctl across the network? I'd like my middleware server to know
>>if my postgres db is up and running OK. I guess I could just make a
>>db connection but I was hoping for a more elegant solution.
>>Thanks.
>>
>>Fran Fabrizio wrote:
>>
>>>Lamar Owen wrote:
>>>
>>>
>>>>On Monday 10 June 2002 10:29 am, Fran Fabrizio wrote:
>>>>
>>>>
>>>>
>>>>>What's the best way to ensure that Pg is running from a shell script?
>>>>>I'm crafting a few RPMs for my projects, one of which will attempt to
>>>>>load data into a database, but I want to check that it's running first
>>>>>before I try this
>>>>>
>>>>
>>>>See the man page for pg_ctl.  There is, IIRC, a status option, but you
>>>>have to know the location of PGDATA (which, in a vanilla RPM install
>>>>is /var/lib/pgsql/data).
>>>>
>>>>
>>>
>>>Thanks all, the pg_ctl -D /var/lib/pgsql/data status should be
>>>sufficient for my needs.
>>>
>>>-Fran
>>>
>>>
>>>---------------------------(end of broadcast)---------------------------
>>>TIP 6: Have you searched our list archives?
>>>
>>>http://archives.postgresql.org
>>
>>
>>
>>--
>>Vincent Stoessel
>>Linux Systems Developer
>>vincent xaymaca.com
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>
>
> ------------------------------------------------------------------------
>
> #!/usr/bin/perl
> use IO::Socket;
>
> $SIG{ALRM} = \&fail;
> alarm 10;
>
> $remote  = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"192.168.1.1", PeerPort=>"5432");
> $remote2 = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"192.168.1.2", PeerPort=>"5432");
> unless($remote) { &fail; }
> close($remote);
>
> unless($remote2) { &fail; }
> close($remote2);
>
> open(FP,">/httpd/htdocs/status2.db");
> print FP "OK";
> close(FP);
>
> open(FP,">/httpd/htdocs/status.db");
> print FP "OK";
> close(FP);
>
> sub fail
> {
>   if(!$remote)
>   {
>         open(FP,">/httpd/htdocs/status.db");
>         print FP "FAIL";
>         close(FP);
>         $msg = "OLD Database Failed!";
>         `echo "$msg" | mail development@did-it.com`;
>   }
>
>   if(!$remote2)
>   {
>         open(FP,">/httpd/htdocs/status2.db");
>         print FP "FAIL";
>         close(FP);
>         $msg = "NEW Database Failes!";
>         `echo "$msg" | mail development@did-it.com`;
>   }
>
>   exit(0);
> }
>
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



--
Vincent Stoessel
Linux Systems Developer
vincent xaymaca.com


pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: indexes are not used
Next
From: Chris Gamache
Date:
Subject: "ERROR:" Messages