Thread: NT service design choices

NT service design choices

From
Fred Yankowski
Date:
I've been working on getting PostgreSQL to run as an NT service.  So
far I've been adding code that builds into postgres.exe, and causes a
new top-level service-management postgres process to run that in turn
forks the normal 'postmaster' process.  This split is necessary
because of certain Cygwin constraints on use of signals and multiple
threads.

But the 'cgyrunsrv' application has recently become available,
providing a general wrapper capability for running any Cygwin process
as as service.  I'm strongly considering using this wrapper to run
PostgreSQL rather than continuing with the approach of integrating the
service-management code right into postgres itself.

So, the question I put to this community is:

*    Do you care whether we implement the NT-service mode of
    PostgreSQL via the cygrunsrv wrapper vs. integrated code?
    If so, why?

The way I see it, the main trade-offs are these:

    Integrated service-management code:
        +  Easy to add management features important to PostgreSQL
           (mostly done already).
    -  Makes postgres.exe larger.
    -- Adds new source code to pgsql that must be maintained, much
           of it specific to arcane NT-service management policies.
    -  Requires changes to main() function in postgres.exe.

    Separate cygrunsrv wrapper:
    ++ Might be possible to wrap postgres with no code changes to
       PostgreSQL at all.  (However, probably still need to ignore
       SIGHUP in postmaster and postgres backend processes).
    -  Need to implement features in cygrunsrv that are specific
       to only the PostgreSQL case so far.  (dependency on other
       services, specific signals to shutdown the application,
       logging all output to a file, clean shutdown in event of NT
       shutdown).
    +  Do not need to maintain the NT-service management code in
       PostgreSQL.
    -  Requires PostgreSQL administrator to get and configure the
       cygrunsrv application as well.

--
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

Re: [PORTS] NT service design choices

From
Tom Lane
Date:
Fred Yankowski <fred@ontosys.com> writes:
> But the 'cgyrunsrv' application has recently become available,
> providing a general wrapper capability for running any Cygwin process
> as as service.  I'm strongly considering using this wrapper to run
> PostgreSQL rather than continuing with the approach of integrating the
> service-management code right into postgres itself.

Sounds good to me.

>     -  Need to implement features in cygrunsrv that are specific
>        to only the PostgreSQL case so far.  (dependency on other
>        services, specific signals to shutdown the application,
>        logging all output to a file, clean shutdown in event of NT
>        shutdown).

The last three would seem to be generally useful additions to cygrunsrv
anyway.  I'm not sure what you mean by "dependency on other services".

            regards, tom lane

Re: [PORTS] NT service design choices

From
Fred Yankowski
Date:
On Mon, May 21, 2001 at 01:28:57PM -0400, Tom Lane wrote:
> The last three would seem to be generally useful additions to cygrunsrv
> anyway.

I think you're right, although to date the PostgreSQL service is the
first Cygwin service to need those features.

> I'm not sure what you mean by "dependency on other services".

The Cygwin port of PostgreSQL depends on having the 'ipc-daemon'
service already running when postmaster starts.  (In fact, it's needed
for initdb too, which is the #1 FAQ for pgsql-cygwin.)

--
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

Re: [PORTS] NT service design choices

From
Jason Tishler
Date:
Tom,

On Mon, May 21, 2001 at 01:28:57PM -0400, Tom Lane wrote:
> Fred Yankowski <fred@ontosys.com> writes:
> >     -  Need to implement features in cygrunsrv that are specific
> >        to only the PostgreSQL case so far.  (dependency on other
> >        services, specific signals to shutdown the application,
> >        logging all output to a file, clean shutdown in event of NT
> >        shutdown).
>
> The last three would seem to be generally useful additions to cygrunsrv
> anyway.  I'm not sure what you mean by "dependency on other services".

Windows NT/2000 has the concept of a Service Control Manager (SCM) which
is responsible for managing (e.g., starting, stopping, etc.) NT services
which are the equivalent of UNIX daemons.  When a service is installed,
it can indicate to the SCM that it is dependent on one or more services.

The SCM will use this information to start/stop services in the right
order on system startup/shutdown or to automatically start a dependency
if it is not currently running.  For example, the Cygwin PostgreSQL
(i.e., postmaster) service is dependent on cygipc's ipc-daemon service.

Jason

--
Jason Tishler
Director, Software Engineering       Phone: 732.264.8770 x235
Dot Hill Systems Corp.               Fax:   732.264.8798
82 Bethany Road, Suite 7             Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA                 WWW:   http://www.dothill.com

Re: [PORTS] NT service design choices

From
Tom Lane
Date:
Jason Tishler <Jason.Tishler@dothill.com> writes:
>> The last three would seem to be generally useful additions to cygrunsrv
>> anyway.  I'm not sure what you mean by "dependency on other services".

> The SCM will use this information to start/stop services in the right
> order on system startup/shutdown or to automatically start a dependency
> if it is not currently running.  For example, the Cygwin PostgreSQL
> (i.e., postmaster) service is dependent on cygipc's ipc-daemon service.

OK ... then that qualifies as a generically useful feature also,
I should think.  Surely that's not the only part of the Cygwin Unix
emulation that's run as a service?

            regards, tom lane

Re: [PORTS] NT service design choices

From
Jason Tishler
Date:
Tom,

On Mon, May 21, 2001 at 04:50:06PM -0400, Tom Lane wrote:
> Jason Tishler <Jason.Tishler@dothill.com> writes:
> >> The last three would seem to be generally useful additions to cygrunsrv
> >> anyway.  I'm not sure what you mean by "dependency on other services".
>
> > The SCM will use this information to start/stop services in the right
> > order on system startup/shutdown or to automatically start a dependency
> > if it is not currently running.  For example, the Cygwin PostgreSQL
> > (i.e., postmaster) service is dependent on cygipc's ipc-daemon service.
>
> OK ... then that qualifies as a generically useful feature also,
> I should think.

Agreed.

> Surely that's not the only part of the Cygwin Unix
> emulation that's run as a service?

So far inetd and sshd are the only UNIX daemons from the core Cygwin
packages that are typically run as services.  I'm sure now that cygrunsrv
has been contributed, there will be a slew of them to follow suit.

Jason

--
Jason Tishler
Director, Software Engineering       Phone: 732.264.8770 x235
Dot Hill Systems Corp.               Fax:   732.264.8798
82 Bethany Road, Suite 7             Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA                 WWW:   http://www.dothill.com