[Mono-devel-list] System.ServiceProcess (RE: [Mono-list] services and daemons)

Moore, Paul Paul.Moore06 at ca.com
Mon Aug 18 12:36:36 EDT 2003


I think there is a simpler implementation. We don't need to emulate the windows service infrastructure at all. We just need to make sure that the same code runs in both places - and that in the linux world it feels like a normal linux daemon. I would suggest doing the following

User creates an app using ServiceProcessBase etc (Using mono implmenation - see later). Say its call daemon.exe

The user then does "mono daemon.exe". This command runs and completes. Daemon.exe is running in the background (under what uid ? Hmm). User code starts via call to OnStart
This command can be put in an SXX start script or wherever

To stop the 'service' the user does "mono daemon.exe -s". This stops the app (runs the onstop method). Can be put in a Sxxx stop script

To run in the foreground (for testing or debugging) the user does "mono daemon.exe -d". From the user (coders) viewpoint this is transparent 

This reproduces the simple way that most unix daemons run (ignoring inetd). And the user code is transportable from unix to windows and back again

How to do it.

The Main function calls ServiceProcess.Run (like in windows implementation). This forks the whole image, the forker writes a pid file and exits.
The forkee then calls OnStart. Does fork work? - it seems to.

To shutdown. A static constructor for the ServiceProcess class reads the command line see the -s and signals the pid in the pid file. Question. What happens if I send a SIGINT to a mono app - not tried. It should generate an exception. We catch this exception and do the OnStop call. If the signal method doesn't work then have the daemon wait on a tcp remoting channel for a stop call - write the socket number to the pid file instead of the pid. OK just tested SIGINT and the app silently terminates - end of plan a. It really should generate an exception don't you think?

No support for pause and resume - but then unix doesn't really have that concept (I know it does but nobody uses it for real daemons). No Power events, ...



-----Original Message-----
From: A Rafael D Teixeira [mailto:rafaelteixeirabr at hotmail.com] 
Sent: Tuesday, August 05, 2003 5:27 PM
To: duncan at ximian.com; Moore, Paul
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-devel-list] System.ServiceProcess (RE: [Mono-list] services and daemons)


>From my brief discussion with Miguel, I think the plan was to write one
>'Mono Service launcher' thing

We tentatively call it monod or monoserver.

>and install that to the SysV runlevel
>system. This service launcher would then be hooked up with the classes
>in the System.ServiceProcess namespace.

That is the plan.

>Nothing is set in stone at all, so I'm bringing this conversation to the
>mono-devel mailing list. Has anyone else given any thought to the
>implementation of the System.ServiceProcess namespace?

Yes, I started that skeleton to be able to write MonoQLE [Indeed I created 
MonoQLEServer in VS.NET as a service project and created all the skeleton 
for the library classes needed for it to compile on Mono/Linux], but had 
little time to make more than that. I hope to further develop it soon, but 
don't hold your breath. Anyone that wants to work on it, please do it!!!

Happy 'services',

Rafael Teixeira
Brazilian Polymath
Mono Hacker since 16 Jul 2001

_________________________________________________________________
MSN Messenger: instale grátis e converse com seus amigos. 
http://messenger.msn.com.br





More information about the Mono-devel-list mailing list