Thread: Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always

Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always

From
s0lao@netscape.net (S. L.)
Date:
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

Re: PostgreSQL 7.3.2 running as NT service under Windows XP not always

From
Frank Seesink
Date:
S. L. wrote:
...
> 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 ?

    That's a possibility, but it too has its limitations.  First (and quite
critical), where exactly would this script be positioned?  As I tried to
explain, NT/2000/XP does not appear to provide a clean mechanism by
which you can introduce commands/scripts during the startup/shutdown
sequence.  Second, it appears this is an infinite loop, sucking CPU time
all day long.  Not my personal idea of efficiency.

    The point is simply that NT/2000/XP does not appear to provide a clean
mechanism by which you can introduce commands/scripts during the
startup/shutdown sequence.  There are a variety of ways for getting
around this, but none are really 'clean'.  They all involve a hack, and
as I am trying to address the 'newbie' Cygwin/PostgreSQL user, I was
hoping to keep things from getting too *nix-y for those not completely
comfortable with such environments.

    I have no interest in debates over whether Cygwin users need to be good
Unix-types, or the whole "Winblows sucks" routine.  I simply wanted to
give docs to help newbies try to avoid or at least be aware of the
limitations/issues they might encounter running PostgreSQL in a Windows
world, in as objective a manner as I could.