[Mono-list] Re: mono-service

Elliott Draper el at eldiablo.co.uk
Tue Nov 1 11:35:49 EST 2005


Bradley, Peter wrote:

>Sorry Elliott,
>
>I'm not sure what you're saying here.  Given the documentation I quoted, are you saying that under Mono it is necessary to use:
>
>RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
>
>if I want to use the same code on both Mono and Windows?
>  
>
I'm not saying it's *necessary*, simply that it seems the easiest and 
most portable solution to me. It's one line of code, and then it should 
work under both Mono and .Net without issue. You can move the service 
around to your heart's content - so long as the "application.exe.config" 
resides in the same directory as the executable, it'll work.

>Or are you saying the documentation is wrong and that a simple absolute path will do the trick - despite what the books say ;) - under both systems?
>  
>
Well I'd hate to go out and say "it's wrong", but certainly some of the 
advice seems a little funky, and like Rob mentioned in his post, the 
putting of the remoting config into "system32" seems a little weird. 
Could it just be that these are books referring to the .Net framework 
v1.0, and maybe these are things that have been revised in v1.1 perhaps?

>I haven't tried using an absolute path for the app.config file of a Windows service (as opposed to a server or an ordinary executable), for the reasons I gave: but if you're convinced it works then I'll give it a go.
>  
>
I'd give the above line a shot; it's one line of code, where's the harm 
in that? ;-)

>Cheers
>
>
>Peter
>  
>
-= El =-

>-----Original Message-----
>From: Elliott Draper [mailto:el at eldiablo.co.uk] 
>Sent: 01 November 2005 13:49
>To: Bradley, Peter
>Cc: mono-list at lists.ximian.com
>Subject: Re: [Mono-list] Re: mono-service
>
>Bradley, Peter wrote:
>
>  
>
>>I wonder if I might be forgiven for responding to myself in order to ask one (hopefully final) question about mono-service?
>>
>>Following the discussion here, I checked out some Windows services I've written and everything seems fine except for one thing.  The services I write are to host remote objects.  As a matter of policy we configure .NET remoting using configuration files.  Therefore host services contain a call to RemotingConfiguration.Configure("config.file.name").
>>
>>Under Windows, the config file must be copied to the WINDOWS\System32 (or WINNT\System32) directory for it to be found by the service.  Where should the config file be located under Mono in order for the daemon to find it?
>> 
>>
>>    
>>
>You don't have to place the config files in System32 for them to be 
>found, you can give a full path to the call to 
>RemotingConfiguration.Configure. I find the easiest way is to stick your 
>remoting config in with any other configuration you might have within an 
>application configuration file ("$assemblyname.config"). Are you 
>familiar with these? Just in case...
>    If using Visual Studio, you can add a new "Application Configuration 
>file" to your project (app.config), and place all config in there. At 
>compile time, a built-in build event will take care of copying this file 
>to your "bin" directory, and re-naming it "$assemblyname.config", for 
>example, "myservice.exe.config".
>    If your not using Visual Studio, then you can manage the config file 
>however you want, however it needs to end up in the same directory as 
>your executable, named the same as your executable but with ".config" on 
>the end, e.g. "myservice.exe.config". I tend to have an App.config in 
>the root of my executables project, and I get NAnt to copy the file over 
>to my "bin" directory and re-name it at compile time, just like VS.
>
>Either way, once you have your correctly named configuration file 
>residing within the same directory as your executable, your call to 
>RemotingConfiguration.Configure becomes nice and easy:
>
>    
>RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
>
>This grabs the full path of the configuration file from the current app 
>domain, and should load your remoting configuration without problems. 
>You can then move the service around without issue, providing that the 
>config file stays with the executable ;-)
>
>AFAIK this works just as well on Mono as it does on .Net.
>
>  
>
>>Thanks for your patience.
>>
>>
>>Peter
>> 
>>
>>    
>>
>Hope that helps!
>
>-= El =-
>
>  
>
>>-----Original Message-----
>>From: Jörg Rosenkranz [mailto:joergr at voelcker.com] 
>>Sent: 01 November 2005 12:52
>>To: Bradley, Peter; Robert Jordan; mono-list at lists.ximian.com
>>Subject: RE: [Mono-list] Re: mono-service
>>
>>Hi Peter,
>>
>> 
>>
>>    
>>
>>>-----Original Message-----
>>>From: mono-list-bounces at lists.ximian.com 
>>>[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of 
>>>Bradley, Peter
>>>Sent: Tuesday, November 01, 2005 1:26 PM
>>>
>>>My post was not intended as a criticism of the man page, and I'm very
>>>sorry if it appeared to be so.  Perhaps I should have been 
>>>clearer, but
>>>what I was really saying that what (I think) is needed is a HowTo.
>>>   
>>>
>>>      
>>>
>>Yes I think this is true. There needs to be something in the Wiki.
>>
>>To answer some of your questions:
>>
>> 
>>
>>    
>>
>>>Does the process to be run as a daemon have to inherit from
>>>System.ServiceProcess.ServiceBase?  Does it guarantee that the
>>>OnStart(), OnStop(), OnPause(), and OnContinue() methods get called as
>>>appropriate?  
>>>   
>>>
>>>      
>>>
>>The service has to be implemented according to the MS docs:
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemserviceprocessservicebaseclasstopic.asp
>>and
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemserviceprocessservicebaseclassruntopic1.asp
>>
>>Short: It needs to be inherited from ServiceBase and it needs to call 
>>ServiceBase.Run in it's Main method.
>>
>> 
>>
>>    
>>
>>>What does one have to do make the service start 
>>>up at boot
>>>time and run without a user logged in?  (Your script is a 
>>>great help in
>>>that regard.  Thanks).  What user does the service run as?  
>>>   
>>>
>>>      
>>>
>>It runs as the user you are starting mono-service with. You
>>are responsible for switching the user in the start script.
>>Examples of start scripts should be in the Wiki/Doc/etc. too.
>>Maybe that's tootoo distribution specific to put it into SVN?
>>
>> 
>>
>>    
>>
>>>What changes
>>>(if any) are required to assemblies written as Windows 
>>>services to make
>>>sure they can run as daemons?
>>>   
>>>
>>>      
>>>
>>There are no changes needed if the assemblies are written
>>with the normal portability rules in mind. Mono-service 
>>should mimic the behaviour of MS' implementation as close 
>>as possible.
>>
>> 
>>
>>    
>>
>>>The OP obviously has trouble getting the OnStart() method 
>>>running.  The
>>>reason why might be contained in the answers to the questions I make
>>>above.
>>>   
>>>
>>>      
>>>
>>Yes :-)
>>
>> 
>>
>>    
>>
>>>I'm perfectly happy to put my money where my mouth is as far as
>>>producing a HowTo is concerned.  Once I've got a daemon 
>>>running, I'll be
>>>only too happy to explain how it was done.  But I may need my hand
>>>holding a little in the meantime :)
>>>   
>>>
>>>      
>>>
>>The man page is very basic and contains only information about 
>>handling of services. There should be an article about implementation
>>of services too. I would be happy if you write a howto down.
>>Please ask if you have any questions.
>>
>>Joerg.
>>_______________________________________________
>>Mono-list maillist  -  Mono-list at lists.ximian.com
>>http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>_______________________________________________
>>Mono-list maillist  -  Mono-list at lists.ximian.com
>>http://lists.ximian.com/mailman/listinfo/mono-list
>> 
>>
>>    
>>
>
>
>  
>



More information about the Mono-list mailing list