Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always - Mailing list pgsql-cygwin

From s0lao@netscape.net (S. L.)
Subject Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always
Date
Msg-id 5F53BE9F.5E466D9D.00013D13@netscape.net
Whole thread Raw
Responses Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always
List pgsql-cygwin
Frank,

[...]
>    End result:  the best I could come up with was creating another NT
>service whose sole purpose in life was to run in the 'postgres' user
>context and delete the postmaster.pid and \tmp\.s.PGSQL* lock files, and
>then making the 'postmaster' service depend on that service.  This way,
>'postmaster' won't start until AFTER the postmaster.pid file has been
>deleted (if it exists).
>
>    Please note a few caveats though.  Do not try creating a shell script
>or .BATch file which you then setup as an NT service via cygrunsrv.  At
>least when I tried, doing so led to the service firing up, executing the
>script, and--and this next part is really important--SHUTTING DOWN
>AGAIN.  The problem here is that if you have 'postmaster' depend on this
>service, it will never fire up, as the startup sequence will go
>
>    * system startup sequence
>    * NT service to delete postmaster.pid service starts up,
>      executes, and shuts down
>    * 'postmaster' attempts to startup, but finding the above
>      service shutdown, fails since it depends on this service.
>
[...]
>In other words,
>
>  1.    I created a simple .BATch file to delete the necessary files
>    (note this is a .BATch file, not a Cygwin BASH shell script,
>    so paths are set accordingly):
>
>    __________________________________________________
>    @echo off
>    del c:\cygwin\tmp\.s.PGSQL*
>    del c:\cygwin\usr\share\postgresql\data\postmaster.pid
>    __________________________________________________
>
>  2.    I then created an NT service via FireDaemon named
>    'cygwin-start' which launched this .BATch file as a console
>    app, running it hidden, etc.
>
>  3.    Using the Cygwin BASH shell, I shutdown and removed the
>    'postmaster' service, then rebuilt the service with a
>    modified command to make 'postmaster' depend on my new
>    FireDaemon-created service, as follows:
>
>    __________________________________________________
>    $ net stop postmaster
>    $ cygrunsrv --remove postmaster
>    $ cygrunsrv --install postmaster --path /usr/bin/postmaster --args "-D
>/usr/share/postgresql/data -i" --dep ipc-daemon --dep cygwin-start
>--termsig INT --user postgres --shutdown
>    __________________________________________________
>
>
>Voila!  It's not pretty, but it works.  And unlike shutdown
>scripts--also not inherent in Windows NT/2000/XP--this handles the case
>of power outages and sudden power failure where 'postmaster' doesn't
>even get a chance to properly shutdown.  (As for the administrative view
>of these situations, I'll leave that to the reader to determine their
>needs.)
>
>    Please note this still doesn't answer the question why the
>postmaster.pid file is left behind sometimes on Windows
>shutdown/restart.  But for those needing their Cygwin PostgreSQL
>database up and running on startup without issue, this is just one
>possible scenario.
>
>P.S.    If I can figure out a way to use cygrunsrv to create a service
>    that runs a script and then remains active (so 'postmaster'
>    will load), I'll post here.  Thus far, howerver, basic attempts
>    like creating a service that points to a shell script fire up,
>    execute the script, and then immediately shutdown.  Possibly
>    having a script that launches another shell that runs the script
>    would work, as the shell would still be 'running'.  But haven't
>    tried yet, so don't know.
>

Sorry, I've no NT/W2K/XP machine to test but:

#!/bin/sh
while :
do
if [ "$xfirst" != "1" ]
then
echo first >/tmp/pgdependservice.log
xfirst=1
rm /tmp/.s.PGSQL*
rm /usr/share/postgresql/data/postmaster.pid
sleep 15
else
echo going... >>/tmp/pgdependservice.log
sleep 15
fi
done

wouldn't do it ?

SLao

__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

Get AOL Instant Messenger 5.1 free of charge.  Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455

pgsql-cygwin by date:

Previous
From: Jason Tishler
Date:
Subject: Fwd: Re: PostgreSQL 7.3.2 running as NT service under Windows XP
Next
From: Frank Seesink
Date:
Subject: Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always