Thread: Re: PGSVC : PostgreSQL Windows Service Manager

Re: PGSVC : PostgreSQL Windows Service Manager

From
"Magnus Hagander"
Date:
>I found the Win32 Native status page and compiled PostgreSQL.
>Then I ported
>a few databases, which seem to work fine except for minor
>quirks. This got
>me so very happy!!

Great to hear!


>So ... I wrote a small service manager. It starts, stops and recovers
>postmaster -- even on shutdown and startup. I've tested in on
>WinXP. It also
>installs and uninstalls the service. I realize that this was
>on the "TODO"
>list, so I hope I didn't step on anyone's toes. Honestly, I
>was just going
>to horde this little app for myself, but ... in the name of
>open source!

This looks like a good start. However, for this to be included in the
main distribution, it cannot rely on Borland C++ builder - it has to
compile with mingw. Since there is no other C++ code in postgresql, just
plain C, I'd say try to stick to that if possible. (I don't see much
C++ism in there, so this should probably be easy)

Also, please note that GPL code is not compatible with the current
postgresql license - check the archives for multiple discussions on
including GPL code.


>Major missing component: I cannot redirect standard output/error on the
>postmaster "child process" in Windows ... I spent way too many
>hours with no
>results, and many different techniques. When I fix this, PGSVC will be
>feature complete. If there's no way to redirect stdout/stderr,
>then I'd like
>to suggest that Win32 code be added to the PGSQL CVS. The code
>should send
>stdout/stderr to a named pipe (just the way signals are rewritten for
>Win32). I would not recommend using the Windows Event Log,
>because I've seen
>PGSQL logs get to be several megs large when using a high
>debug level. That
>would be a real hassle to to use the crappy WinEventLog
>interface ... imho.

It should be quite possible to redirect these pipes using the data in
STARTUPINFO. I'm not sure how that will handle subprocesses executed
from the postmaster though, perhaps there is where your problem is?

As for using the eventlog - I think that depends a lot on the
environment. When debugging it's probably not the right thing (though I
would argue you could/should launch it from the commandline when you do
debugging).

But definitly, having both options would be good.

(Oh, and I quite like the eventlog interface. Especially how it
integrates with existing management and monitoring tools)



//Magnus

Re: PGSVC : PostgreSQL Windows Service Manager

From
"Keith Woodell"
Date:
Magnus,

> main distribution, it cannot rely on Borland C++ builder - it has to
> compile with mingw. Since there is no other C++ code in postgresql, j...

Actually, there's no C++; naming it was a due to old habits. It should be
compliant. Borland CBuilder comes with MinGW and gcc, which compiled it fine
(although the binary on the site is Borland). Maybe we have different
versions of MinGW? Can you send your output? I will fix and retry. I also
have a separate MinGW install, to build PGSQL, and I will try that.

> Also, please note that GPL code is not compatible with the current
> postgresql license - check the archives for multiple discussions...

Please tell me which license to pick. I know it will be hard for you to
allow me to relinquish my own control, but I'm fine with that. Tell me which
one to pick, and I'll be happy to switch the license. :) For me, to you all,
it's free, whatever, beer, money, however that goes ... I don't have an
opinion! It's all free to me!

> It should be quite possible to redirect these pipes using the data in
> STARTUPINFO. I'm not sure how that will handle subprocesses execu...

I redirected with STARTUPINFO by many methods (including Microsoft's
example), and it positively could not find the sugar to redirect. The pipes
were open, I could "read" (no data, however), then they would close with
this error: "The pipe has ended." I tried with and without inheritance. I
can try to link PGSQL with a link switch called "-mwindows" (which
apparently disables the "DOS command window"), but I have no idea where? On
the linker, I presume, but I'm not that well versed. Maybe the "console" is
a "superprocess" to the "postmaster.exe"? Just a thought ... ?

As for subprocesses, I'm not that well versed. I'd prefer to redirect
stdout/stderr, if only to save my hairline. :)

> As for using the eventlog - I think that depends a lot on the
> environment. When debugging it's probably not the right thing (thoug...

I'm not picky; more is better!

Thanks for your input.

-Keith Woodell
System Administrator
Natural Heritage New Mexico
505-277-3822 ext 232, 505-277-3844 (fax)

Please report NHNM technical support issues at http://admin.heritage.unm.edu


Re: PGSVC : PostgreSQL Windows Service Manager

From
"Magnus Hagander"
Date:
> > main distribution, it cannot rely on Borland C++ builder -
> it has to
> > compile with mingw. Since there is no other C++ code in postgresql,
> > j...
>
> Actually, there's no C++; naming it was a due to old habits.
> It should be compliant. Borland CBuilder comes with MinGW and
> gcc, which compiled it fine (although the binary on the site
> is Borland). Maybe we have different versions of MinGW? Can
> you send your output? I will fix and retry. I also have a
> separate MinGW install, to build PGSQL, and I will try that.

Haven't tried compiling it yet. But for start, there is //-comments,
which I don't think will pass a C compiler. Again, haven't specifically
tested.

Also, if we are going with an outside "service wrapper", consider
putting the install and uninstall functions into this one as parameters
"-install" etc. One less binary to worry about.

I don't have your code around right now, so I don't remember if you had
already handled the "multiple instances on the same machine" issue. If
not, that would also be a nice feature :-)


> > Also, please note that GPL code is not compatible with the current
> > postgresql license - check the archives for multiple discussions...
>
> Please tell me which license to pick. I know it will be hard
> for you to allow me to relinquish my own control, but I'm
> fine with that. Tell me which one to pick, and I'll be happy
> to switch the license. :) For me, to you all, it's free,
> whatever, beer, money, however that goes ... I don't have an
> opinion! It's all free to me!

The rest of the backend is BSD, so that would be most suitable.


> > It should be quite possible to redirect these pipes using
> the data in
> > STARTUPINFO. I'm not sure how that will handle subprocesses execu...
>
> I redirected with STARTUPINFO by many methods (including
> Microsoft's example), and it positively could not find the
> sugar to redirect. The pipes were open, I could "read" (no
> data, however), then they would close with this error: "The
> pipe has ended." I tried with and without inheritance. I can
> try to link PGSQL with a link switch called "-mwindows"
> (which apparently disables the "DOS command window"), but I
> have no idea where? On the linker, I presume, but I'm not
> that well versed. Maybe the "console" is a "superprocess" to
> the "postmaster.exe"? Just a thought ... ?
>
> As for subprocesses, I'm not that well versed. I'd prefer to
> redirect stdout/stderr, if only to save my hairline. :)

Oh yes, but to catch the data, you need to get it from both the main
postmaster and from subprocesses.

'fraid I don't know much more about this - needs further research.


//Magnus

Re: PGSVC : PostgreSQL Windows Service Manager

From
"Merlin Moncure"
Date:
> Haven't tried compiling it yet. But for start, there is //-comments,
> which I don't think will pass a C compiler. Again, haven't
specifically
> tested.

C99 does :)...but I think PostgreSQL sources are supposed to be C89
compatible.

Merlin