Обсуждение: Postmaster service code

Поиск
Список
Период
Сортировка

Postmaster service code

От
"Dave Page"
Дата:
Hi all,

The to-do list has "rony?" listed against the item to make the
postmaster a proper service. I'm not sure who rony is, and searching the
archives isn't giving any hits - anyway, I expect to have a day or so
free and having just 'serviceised' pg_autovacuum figured I could
probably do the same to the postmaster quite easily.

Anyone got any objections, already working on it or have any existing
code/comments before I start? I would aim to do something similar to
what I did with pg_autovacuum, such that the code can run either as a
normal application or a service.

Regards, Dave.



Re: Postmaster service code

От
"Laurent Ballester"
Дата:
Hello Dave,

Claudio sent May 3, a win32 service for review on patches mailing list.

I am the feeling he already mades the job.

Regards, Laurent

----- Original Message -----
From: "Dave Page" <dpage@vale-housing.co.uk>
To: <pgsql-hackers-win32@postgresql.org>
Sent: Sunday, May 09, 2004 10:57 AM
Subject: [pgsql-hackers-win32] Postmaster service code


Hi all,

The to-do list has "rony?" listed against the item to make the
postmaster a proper service. I'm not sure who rony is, and searching the
archives isn't giving any hits - anyway, I expect to have a day or so
free and having just 'serviceised' pg_autovacuum figured I could
probably do the same to the postmaster quite easily.

Anyone got any objections, already working on it or have any existing
code/comments before I start? I would aim to do something similar to
what I did with pg_autovacuum, such that the code can run either as a
normal application or a service.

Regards, Dave.



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Re: Postmaster service code

От
"Dave Page"
Дата:

> -----Original Message-----
> From: Laurent Ballester [mailto:postgresql.ballester@wanadoo.fr]
> Sent: 09 May 2004 10:11
> To: Dave Page; pgsql-hackers-win32@postgresql.org
> Subject: Re: [pgsql-hackers-win32] Postmaster service code
>
> Hello Dave,
>
> Claudio sent May 3, a win32 service for review on patches
> mailing list.
>
> I am the feeling he already mades the job.

Oh, ok thanks - I'll have to find something else to keep me busy then
:-)

Regards, Dave.

Re: Postmaster service code

От
"Darko Prenosil"
Дата:
Yes, he did. I included it into "main" and tried. There is alo report about
that on the list. Service code is working fine.
The problems are service error messages (same for the autovacuum ?).

Regards !

----- Original Message -----
From: "Laurent Ballester" <postgresql.ballester@wanadoo.fr>
To: "Dave Page" <dpage@vale-housing.co.uk>;
<pgsql-hackers-win32@postgresql.org>
Sent: Sunday, May 09, 2004 11:11 AM
Subject: Re: [pgsql-hackers-win32] Postmaster service code


> Hello Dave,
>
> Claudio sent May 3, a win32 service for review on patches mailing list.
>
> I am the feeling he already mades the job.
>
> Regards, Laurent
>
> ----- Original Message -----
> From: "Dave Page" <dpage@vale-housing.co.uk>
> To: <pgsql-hackers-win32@postgresql.org>
> Sent: Sunday, May 09, 2004 10:57 AM
> Subject: [pgsql-hackers-win32] Postmaster service code
>
>
> Hi all,
>
> The to-do list has "rony?" listed against the item to make the
> postmaster a proper service. I'm not sure who rony is, and searching the
> archives isn't giving any hits - anyway, I expect to have a day or so
> free and having just 'serviceised' pg_autovacuum figured I could
> probably do the same to the postmaster quite easily.
>
> Anyone got any objections, already working on it or have any existing
> code/comments before I start? I would aim to do something similar to
> what I did with pg_autovacuum, such that the code can run either as a
> normal application or a service.
>
> Regards, Dave.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>


Re: Postmaster service code

От
"Laurent Ballester"
Дата:
Yes, we need to create and register a tiny DLL to avoid to have error
message joined to our log message such as describe Dave in it's previous
mail.

By studing the works made by Claudio, a simple way to achieve this work it
to create a message wich contains only %1 like the mc file i'am attached
with this post, and to modify a little bit the write_eventlog function he
made (4 parameters of ReportEvent have to change to 0 with  0x00000001L or
PGWIN32_EVENTLOG_MSG in my sample).

To obtain a DLL, we need Microsoft MC Compiler to create a RC file and after
we can finish the compilation with Msys tools.

for Visual Studio users :

mc EventLogMsg.mc   # produce one rc file and one .h file
rc -r -fo EventLogMsg.res EventLogMsg.rc
link -dd -noentry -out:EventLogMsg.dll EventLogMsg.res

for Msys :
After obtain a .RC file with MC compiler
windres -o EventLogMsg.o EventLogMsg.rc
dllwrap --dllname=EventLogMsg.dll --driver-name=gcc EventLogMsg.o

To finish, we have to register the DLL in
HKEY_LOCAL_MACHINE\system\CurrentControlSet\Services\EventLog\Application
Create a entry name PostGreSQL, add a key EventMessageFile set it with the
full path of the DLL
two issues : made this job by setup program or by write_eventlog() itself.

Do you know, where will be the right place to put these files and
update/create a Makefile

Regards, Laurent


Вложения

Re: Postmaster service code

От
"Magnus Hagander"
Дата:
>Yes, we need to create and register a tiny DLL to avoid to have error
>message joined to our log message such as describe Dave in
>it's previous mail.
>
>By studing the works made by Claudio, a simple way to achieve
>this work it
>to create a message wich contains only %1 like the mc file
>i'am attached
>with this post, and to modify a little bit the write_eventlog
>function he
>made (4 parameters of ReportEvent have to change to 0 with
>0x00000001L or
>PGWIN32_EVENTLOG_MSG in my sample).

Yes, this is exactly what I had in mind whien I did the eventlogging
code. Except can't you keep using msgid 0? Or is it prohibited? (I
thought I had used 0 in a previous project, but my memory may be a bit
off)
If we can go with 0 I think we should - it seems more appropriate,
especialy in case we evern want to map error codes to eventids.


>To obtain a DLL, we need Microsoft MC Compiler to create a RC
>file and after
>we can finish the compilation with Msys tools.

Question: Doesn't MC also generate a .bin-file? IIRC, the .RC file is
just a reference to the .BIN?

If not, then it's an easy go - I suggest we put both the .RC and the .MC
file in, so things will still build fully from mingw. If not, I don't
know what the deal is about binary files - could we stuff a
pre-generated .BIN file in CVS? [I know cvs can, but is that acceptable
in postgresql?]


>To finish, we have to register the DLL in
>HKEY_LOCAL_MACHINE\system\CurrentControlSet\Services\EventLog\A
>pplication
>Create a entry name PostGreSQL, add a key EventMessageFile set
>it with the
>full path of the DLL
>two issues : made this job by setup program or by
>write_eventlog() itself.

write_eventlog() cannot do this, since the postmaster will run as a
non-administrator, and thus not have permissions under that key.
The installation program should normally do this.

I would suggest implementing the DllRegisterServer() and
DllUnRegisterServer() entrypoint in a small C file that is compiled into
the DLL. That way, a user can just run "regsvr32 pgevent.dll" (or
whatever it's called).
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm
/cmf_d2l_3cmq.asp


>Do you know, where will be the right place to put these files and
>update/create a Makefile

I would suggest creating "bin/pgevent". Comments?

//mha

Re: Postmaster service code

От
"Laurent Ballester"
Дата:
>Yes, this is exactly what I had in mind whien I did the eventlogging
>code. Except can't you keep using msgid 0? Or is it prohibited? (I
>thought I had used 0 in a previous project, but my memory may be a bit
>off)
>If we can go with 0 I think we should - it seems more appropriate,
>especialy in case we evern want to map error codes to eventids.

Yes we can of course.  I modify the mc file.

>To obtain a DLL, we need Microsoft MC Compiler to create a RC
>file and after
>we can finish the compilation with Msys tools.

Question: Doesn't MC also generate a .bin-file? IIRC, the .RC file is
just a reference to the .BIN?

Correct, the file was missing in my post !

If not, then it's an easy go - I suggest we put both the .RC and the .MC
file in, so things will still build fully from mingw. If not, I don't
know what the deal is about binary files - could we stuff a
pre-generated .BIN file in CVS? [I know cvs can, but is that acceptable
in postgresql?]


>To finish, we have to register the DLL in
>HKEY_LOCAL_MACHINE\system\CurrentControlSet\Services\EventLog\A
>pplication
>Create a entry name PostGreSQL, add a key EventMessageFile set
>it with the
>full path of the DLL
>two issues : made this job by setup program or by
>write_eventlog() itself.

write_eventlog() cannot do this, since the postmaster will run as a
non-administrator, and thus not have permissions under that key.
The installation program should normally do this.

I would suggest implementing the DllRegisterServer() and
DllUnRegisterServer() entrypoint in a small C file that is compiled into
the DLL. That way, a user can just run "regsvr32 pgevent.dll" (or
whatever it's called).
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm
/cmf_d2l_3cmq.asp

If everybody is OK, I will make this extension during the week.

>Do you know, where will be the right place to put these files and
>update/create a Makefile

> I would suggest creating "bin/pgevent". Comments?

It's ok for me

Regards, Laurent

Вложения

Re: Postmaster service code

От
"Dave Page"
Дата:

> -----Original Message-----
> From: Magnus Hagander [mailto:mha@sollentuna.net]
> Sent: 09 May 2004 18:41
> To: Laurent Ballester; Darko Prenosil; Dave Page;
> pgsql-hackers-win32@postgresql.org
> Subject: RE: [pgsql-hackers-win32] Postmaster service code
>
> I would suggest implementing the DllRegisterServer() and
> DllUnRegisterServer() entrypoint in a small C file that is
> compiled into the DLL. That way, a user can just run
> "regsvr32 pgevent.dll" (or whatever it's called).
> See
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/com/htm
> /cmf_d2l_3cmq.asp

I wonder if this should also be added to the service install code so at
least it is done automatically when that is run. I used the following in
the autovacuum daemon:

        /*
         * Set the Event source for the application log
        */
        sprintf(szKey,
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\PostgreSQL
Auto Vacuum");
        if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hk, NULL)) return -5;

        sprintf(szMsgDLL, "pgmessages.dll");
        if (RegSetValueEx(hk, "EventMessageFile", 0, REG_EXPAND_SZ,
(LPBYTE)szMsgDLL, (DWORD)strlen(szMsgDLL)+1)) return -6;

And to remove it again


        /*
         * Remove the Event source from the application log
        */
        sprintf(szKey,
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application");
        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_ALL_ACCESS,
&hk)) return -4;
        if (RegDeleteKey(hk, "PostgreSQL Auto Vacuum")) return -5;

> >Do you know, where will be the right place to put these files and
> >update/create a Makefile
>
> I would suggest creating "bin/pgevent". Comments?

Sounds OK to me.

Regards, Dave.

Re: Postmaster service code

От
"Dave Page"
Дата:

> -----Original Message-----
> From: Laurent Ballester [mailto:postgresql.ballester@wanadoo.fr]
> Sent: 09 May 2004 11:49
> To: Darko Prenosil; Dave Page; pgsql-hackers-win32@postgresql.org
> Subject: Re: [pgsql-hackers-win32] Postmaster service code
>
> mc EventLogMsg.mc   # produce one rc file and one .h file
> rc -r -fo EventLogMsg.res EventLogMsg.rc
> link -dd -noentry -out:EventLogMsg.dll EventLogMsg.res
>
> for Msys :
> After obtain a .RC file with MC compiler

There's a problem of course - are there no foss tools that can replace
MC?

> windres -o EventLogMsg.o EventLogMsg.rc
> dllwrap --dllname=EventLogMsg.dll --driver-name=gcc EventLogMsg.o

Regards, Dave.

Re: Postmaster service code

От
"Magnus Hagander"
Дата:
> > mc EventLogMsg.mc   # produce one rc file and one .h file
> > rc -r -fo EventLogMsg.res EventLogMsg.rc link -dd -noentry
> > -out:EventLogMsg.dll EventLogMsg.res
> >
> > for Msys :
> > After obtain a .RC file with MC compiler
>
> There's a problem of course - are there no foss tools that
> can replace MC?

Apparantly, there is one as a part of this:
http://www.smorgasbordet.com/pellesc/

Haven't tried it, but it looks to be MS compatible.
I still think it would be nice to include the .BIN file in cvs if
possible, so another package isn't required to build it. But it's a nice
tool to have if we need to update it at a later time.

It may also be included in the free Visual C++ download you can get from
MS, don't know about that.

//Magnus

Re: Postmaster service code

От
Christian.Klemke@t-online.de (Christian Klemke)
Дата:
PMJI, but maybe you'll also want to take a look at the Open Watcom
Project (www.openwatcom.org).
The distribution includes two tools called RC.EXE ("Open Watcom C/C++
RC clone for 386) and WRC.EXE ("Open Watcom Windows Resource
Compiler").
I have to admit that I am not familiar with license peculiatities in
detail, but I'm sure one of you guys will be able to figure out if it
fits or not.

Regards,
Christian.


Magnus Hagander schrieb:
> > > mc EventLogMsg.mc   # produce one rc file and one .h
> file
> > > rc -r -fo EventLogMsg.res EventLogMsg.rc link -dd
> -noentry
> > > -out:EventLogMsg.dll EventLogMsg.res
> > >
> > > for Msys :
> > > After obtain a .RC file with MC compiler
> >
> > There's a problem of course - are there no foss tools
> that
> > can replace MC?
>
> Apparantly, there is one as a part of this:
> http://www.smorgasbordet.com/pellesc/
>
> Haven't tried it, but it looks to be MS compatible.
> I still think it would be nice to include the .BIN file
> in cvs if
> possible, so another package isn't required to build it.
> But it's a nice
> tool to have if we need to update it at a later time.
>
> It may also be included in the free Visual C++ download
> you can get from
> MS, don't know about that.
>
> //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
>

Re: Postmaster service code

От
"Laurent Ballester"
Дата:
Hello,

I have a question to be able to finish DllRegisterServer function. The
function must write full pathname of dll in registry. In a classical Windows
setup program, this path is chosen by end-user at runtime.
We discuss a few week (month ?) ago to store the path in registry too and
create env variable for backward compatibility with existent programs.

Did you remember what was the final decision ?

Regards, Laurent


Re: Postmaster service code

От
"Magnus Hagander"
Дата:
> I have a question to be able to finish DllRegisterServer
> function. The function must write full pathname of dll in
> registry. In a classical Windows setup program, this path is
> chosen by end-user at runtime.
> We discuss a few week (month ?) ago to store the path in
> registry too and create env variable for backward
> compatibility with existent programs.
>
> Did you remember what was the final decision ?

I think your best bet is to use GetModuleFileNameEx() and friends
(probably need to EnumProcessModules(), I can't remember if there is a
direct API call to give you the current DLL. Or you can save away the
HMODULE value in DllMain() in a global variable - that might be easier)
to find out the exact path of the DLL that regsvr32 is invoked on, and
write that path to the registry.

That way you are completely independent of where the DLL is installed,
as long as it's not moved. (And not being able to move a program/dll
after it has been installed is pretty normal)


//Magnus