Thread: win32 service proposal

win32 service proposal

From
Claudio Natoli
Date:
[For review only. Not for committing.]

Decided to take a crack at this in the interests of knocking over the
remaining TODO win32 items asap.

Would appreciate any comments on the code, particularly from win32 people.
An obvious missing feature is allowing the service to be registered under a
user account, something we certainly need to allow (with this service
running under SYSTEM, I've already tripped over some permission issues in
the regression tests).

A consensus also needs to reached on whether or not to include this in the
postmaster:  Do we want the win32 service in the postmaster, or a
stand-alone exe? (currently hooks into the main.c with a one-liner, but
trivial to wrap as a stand-alone exe).

Spoke about this off-list with Magnus; he's strongly for stand-alone; I'm
fence-sitting. We see that clearly there are some niceties to having this in
the postmaster (one less exe to build/configure; same install set for
win/*nix; etc), but the downsides include minor impact on the core code and
the fact that a user will see two postmaster processes running... the latter
I find particularly obnoxious (using a thread to handle the service or
PostmasterMain would alleviate this, but would require more work to be able
to catch postmaster shutdowns, meaning impact to core code, and unexpected
terminations would leave the user at the mercy of the Service Manager).

Cheers,
Claudio



---
Certain disclaimers and policies apply to all email sent from Memetrics.
For the full text of these disclaimers and policies see
<a
href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
ailpolicy.html</a>



Attachment

Re: win32 service proposal

From
"Magnus Hagander"
Date:
> Spoke about this off-list with Magnus; he's strongly for
> stand-alone; I'm fence-sitting. We see that clearly there are
> some niceties to having this in the postmaster (one less exe
> to build/configure; same install set for win/*nix; etc), but
> the downsides include minor impact on the core code and the
> fact that a user will see two postmaster processes running...
> the latter I find particularly obnoxious (using a thread to
> handle the service or PostmasterMain would alleviate this,
> but would require more work to be able to catch postmaster
> shutdowns, meaning impact to core code, and unexpected
> terminations would leave the user at the mercy of the Service
> Manager).

Hmm, did I come across as stringly for stand-alone? That was not my
intention :-)

I'm definitly leaning in that direction, but I wouldn't say I'm strongly
for it.

Apart from that, those are the points I see. It's just a matter of
weighting them.

//Magnus


Re: win32 service proposal

From
"Darko Prenosil"
Date:
I played a bit with that code. According to Microsoft samples for service
managers, errors and events should be logged to eventlog. so I added a
function (almost copy of sample service code), it's a messy, but it was
enough to see what is happening with the service.
After testing it, I have noticed two confusing things:


1.
I'll try to describe what happens in few steps:
a.) register service using: C:\msys\1.0\local\pgsql\bin\postmaster /register
postgres -D C:/msys/1.0/local/pgsql/data
b.) start service manager
c.) start the service (it starts fine)
d.) unregister service using: C:\msys\1.0\local\pgsql\bin\postmaster
/unregister postgres

After that postgres "status type" in service manager changes to "disabled",
and I'm unable to do anything with service.
The only way is restarting NT. It seems that this happens no matter service
is started or stopped, enough is that service manager is started and cursor
is positioned on "postgres" service. Is this some kind of Win bug ?

2.
When invalid parameter for postmaster is set, for example: -D
C:/msys/1.0/local/pgsql/dataX, CreateProcess returns true, but postmaster
exit with FATAL. How can we detect this situation and send the postmaster
error string into log ?

Here is changed "main.c" that I played with.


Regards !


----- Original Message -----
From: "Claudio Natoli" <claudio.natoli@memetrics.com>
To: <pgsql-patches@postgresql.org>
Sent: Monday, May 03, 2004 12:01 PM
Subject: [PATCHES] win32 service proposal


>
> [For review only. Not for committing.]
>
> Decided to take a crack at this in the interests of knocking over the
> remaining TODO win32 items asap.
>
> Would appreciate any comments on the code, particularly from win32 people.
> An obvious missing feature is allowing the service to be registered under
a
> user account, something we certainly need to allow (with this service
> running under SYSTEM, I've already tripped over some permission issues in
> the regression tests).
>
> A consensus also needs to reached on whether or not to include this in the
> postmaster:  Do we want the win32 service in the postmaster, or a
> stand-alone exe? (currently hooks into the main.c with a one-liner, but
> trivial to wrap as a stand-alone exe).
>
> Spoke about this off-list with Magnus; he's strongly for stand-alone; I'm
> fence-sitting. We see that clearly there are some niceties to having this
in
> the postmaster (one less exe to build/configure; same install set for
> win/*nix; etc), but the downsides include minor impact on the core code
and
> the fact that a user will see two postmaster processes running... the
latter
> I find particularly obnoxious (using a thread to handle the service or
> PostmasterMain would alleviate this, but would require more work to be
able
> to catch postmaster shutdowns, meaning impact to core code, and unexpected
> terminations would leave the user at the mercy of the Service Manager).
>
> Cheers,
> Claudio
>
>
>
> ---
> Certain disclaimers and policies apply to all email sent from Memetrics.
> For the full text of these disclaimers and policies see
> <a
>
href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
> ailpolicy.html</a>
>
>
>


----------------------------------------------------------------------------
----


>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>


Attachment

Re: win32 service proposal

From
"Magnus Hagander"
Date:
> I played a bit with that code. According to Microsoft samples
> for service managers, errors and events should be logged to
> eventlog. so I added a function (almost copy of sample
> service code), it's a messy, but it was enough to see what is
> happening with the service.

Consider using ereport() if it's available at that time - then it'll go
to the correct place. Otherwise, look at the code in
backend/utils/error/elog.c, and the write_eventlog() function. Might
want to make that one non-static and call that one. That way we're sure
the messages end up in the same category in the eventlog.


> 1.
> I'll try to describe what happens in few steps:
> a.) register service using:
> C:\msys\1.0\local\pgsql\bin\postmaster /register postgres -D
> C:/msys/1.0/local/pgsql/data
> b.) start service manager
> c.) start the service (it starts fine)
> d.) unregister service using: C:\msys\1.0\local\pgsql\bin\postmaster
> /unregister postgres
>
> After that postgres "status type" in service manager changes
> to "disabled", and I'm unable to do anything with service.

Yes, this is normal if you unregister a service *while it is running*.

> The only way is restarting NT. It seems that this happens no
> matter service is started or stopped, enough is that service
> manager is started and cursor is positioned on "postgres"
> service. Is this some kind of Win bug ?

It shuold not happen when it's not started. In that case, it should be
enough to restart the services MMC snapin. Or if you're on NT4, you need
to restart the control panel (uh, maybe even logout/in). But you
shouldn't need a reboot.



> 2.
> When invalid parameter for postmaster is set, for example: -D
> C:/msys/1.0/local/pgsql/dataX, CreateProcess returns true,
> but postmaster exit with FATAL. How can we detect this
> situation and send the postmaster error string into log ?

postgresql.conf, set log_destination to eventlog. That should put it in
a place you can see it.


//Magnus


Re: win32 service proposal

From
Darko Prenosil
Date:
On Tuesday 04 May 2004 13:47, Magnus Hagander wrote:
> > I played a bit with that code. According to Microsoft samples
> > for service managers, errors and events should be logged to
> > eventlog. so I added a function (almost copy of sample
> > service code), it's a messy, but it was enough to see what is
> > happening with the service.
>
> Consider using ereport() if it's available at that time - then it'll go
> to the correct place. Otherwise, look at the code in
> backend/utils/error/elog.c, and the write_eventlog() function. Might
> want to make that one non-static and call that one. That way we're sure
> the messages end up in the same category in the eventlog.
>

Ooops, I was not aware that this already exists !!!
I'll try to do as You suggested !

> > 1.
> > I'll try to describe what happens in few steps:
> > a.) register service using:
> > C:\msys\1.0\local\pgsql\bin\postmaster /register postgres -D
> > C:/msys/1.0/local/pgsql/data
> > b.) start service manager
> > c.) start the service (it starts fine)
> > d.) unregister service using: C:\msys\1.0\local\pgsql\bin\postmaster
> > /unregister postgres
> >
> > After that postgres "status type" in service manager changes
> > to "disabled", and I'm unable to do anything with service.
>
> Yes, this is normal if you unregister a service *while it is running*.
>
> > The only way is restarting NT. It seems that this happens no
> > matter service is started or stopped, enough is that service
> > manager is started and cursor is positioned on "postgres"
> > service. Is this some kind of Win bug ?
>
> It shuold not happen when it's not started. In that case, it should be
> enough to restart the services MMC snapin. Or if you're on NT4, you need
> to restart the control panel (uh, maybe even logout/in). But you
> shouldn't need a reboot.
>

No, it is not running, just cursor positioned on "postgresql" service in
service manager, and yes, You are right - logoff was enough.


> > 2.
> > When invalid parameter for postmaster is set, for example: -D
> > C:/msys/1.0/local/pgsql/dataX, CreateProcess returns true,
> > but postmaster exit with FATAL. How can we detect this
> > situation and send the postmaster error string into log ?
>
> postgresql.conf, set log_destination to eventlog. That should put it in
> a place you can see it.
>
>
> //Magnus
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly