plan for running postmaster directly as NT service

Поиск
Список
Период
Сортировка
От Fred Yankowski
Тема plan for running postmaster directly as NT service
Дата
Msg-id 20010127084946.A18499@enteract.com
обсуждение исходный текст
Ответы Re: plan for running postmaster directly as NT service  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
I'm using PostgreSQL on WinNT to support (along with Zope) several
websites.  I've currently got postmaster running as an NT service by
wrapping it with the 'invoker' utility, but I'd prefer to have it run
directly as a service so that it can be stopped cleanly.  I now know
the basics of how to extend a program to make it run directly as an NT
service, as I've enhanced the Cygipc (Cygwin) 'ipc-daemon' process to
do just that (and I've submitted the patch to the current maintainer
of Cygipc).  So now I'd like to do the same for postgres/postmaster,
but I want you all to vet this plan before I invest much more time.

For me, the fundamental question is:  If I create a patch that
implements this function, what will it take to get it into the main
CVS version?  Will some established PostgreSQL developer offer to
review/champion/mentor my work?

Expected plan of operation:

1) Administrator runs 'postgres --install-as-service'.  Program  installs NT registry entries and calls Windows APIs to
registerthe  service, leaving it ready for 'automatic' startup, but not starting  the service.  The ImagePath key value
usesexactly the full path  of the 'postgres' program that did the install.  After installing  the service the program
returnsimmediately.
 

2) When starting the service from, say, the Services Control Panel,  postgres is invoked with a new '--service'
command-lineflag.  When  the postgres program starts running it looks for this option  right away (much like '-boot')
and,finding it, starts up in  postmaster mode and passes on the --services flag, causing the  postmaster code to do the
necessarymagic to start up as an NT  service.  This does not involve any additional forks; the process  splits into a
supervisorythread and a main thread that runs the  existing main work loop.
 

3) When the service is stopped, the supervisory service thread sends some  kind of event/signal/semaphore/... to the
mainwork thread, causing  that thread to shut down as if 'pg_ctl -m fast stop' had been  called [is this a good
choice?].

4) Administrator runs 'postgres --remove-as-service'.  The program  removes the registry data for the service and calls
APIsto  completely remove the service.  It shuts down the service first if  it's already running.  Then it quits.
 

Design questions:

a) The 'install' and 'remove' code is quite bulky, although simple.
Is it OK to create a new source file for it, rather than working it
into some existing file?

b) How can the service log error messages?  Is there any syslog type
facility?  If not, is it OK to include a new output interface that
would log to the NT event log?  Or is there some better scheme?

c) What is a good way for the supervisory thread to communicate with
the main thread and shut it down cleanly?  (I haven't studied the
code to find the main wait/select loop yet.  Sorry.)

d) How can we insure that the ipc-daemon service starts before the
postgres/postmaster service?  I believe that NT has some facility that
allows one service to request start-up of another service, but I have
no idea how to make that happen.

Your feedback on this plan is more than welcome.  I'm willing to put
time into getting this working, but only if I get some support from you
all.

-- 
Fred Yankowski           fred@OntoSys.com      tel: +1.630.879.1312
Principal Consultant     www.OntoSys.com       fax: +1.630.879.1370
OntoSys, Inc             38W242 Deerpath Rd, Batavia, IL 60510, USA


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: wrong query plan in 7.1beta3
Следующее
От: Kovacs Zoltan
Дата:
Сообщение: Re: wrong query plan in 7.1beta3