[Mono-list] Service or daemon with Mono?

Danny dgortonii at gmail.com
Tue Jul 14 17:00:57 EDT 2009


Thanks alot.  Indeed it does look pretty vanilla in term of the remoting 
usage, but one difference IS the SingleCall.  I'll take a closer look 
when I can get back to that ticket.

Thanks again,
Danny

Amc Gmail wrote:
> Hmmm... hard to say, i did remoting part 4+ years ago :) in .net 1.1 era :)
> It sees to be I am not doing anything special, but keep in mind i am using mode="SingleCall"
> 
> Here is more details:
> 
>     <system.runtime.remoting>
>         <application>
>             <service>
>                 <wellknown type="Rmt.RmtBridge, Rmt" objectUri="Rmt" 
>                 mode="SingleCall" 
>                 />
>             </service>
>             <channels>
>                 <channel ref="tcp" name="RmtChannel" port="12345">
>                 </channel>
>             </channels>
>         </application>
>     </system.runtime.remoting>
> 
> And all remoting types/methods are in one class:
> 
> namespace Rmt {
>     public class RmtBridge : MarshalByRefObject {...}
> }
> 
> Service has multiple threads and some of them are control threads which i am using to kill real worker threads if they are hang. Control thread code look like:
> 
>         public override void ControlThreadLoop() {
> 
>             // Configure remoting
>             bool isInitOk = InitRemoting();
>             if (IsStop()) return;   // exit signaled
>             if (!isInitOk) {
>                 // Fail to init remoting - log exception and continue 
>                 ..... error EventLog here...
>             }
> 
>             while (!IsStop()) {
>                     .... create worker thread and monitor it health ....
>             }
>         }
> 
>         // Try to configure remoting, return true on success
>         private bool InitRemoting() {
>             for (int j = 0; !IsStop() && j < INIT_ATTEMPT_COUNT; j++) {
>                 try {
>                     RemotingConfiguration.Configure(
>                         System.IO.Path.Combine(
>                         AppDomain.CurrentDomain.BaseDirectory, 
>                         AppDomain.CurrentDomain.FriendlyName + ".config"
>                         ));
>                     return true;    // success
>                 }
>                 catch(Exception e) {
>                     ..... warning EventLog here...
>                 }
> 
>                 // sleep before next attempt
>                 IdleSleep(IDLE_SLEEP_TIME);
>             }
> 
>             return false;   // not initialized
>         }
>     }
> 
> sorry for that long e-mail, hope it helps (not sure about that, but trying my best :)
> -- amc
> 
> 
> ----- Original Message -----
> From: "Danny" <dgortonii at gmail.com>
> To: "Amc Gmail" <amc1999 at gmail.com>
> Cc: "jos_" <junk at sonhult.se>, mono-list at lists.ximian.com
> Sent: Tuesday, July 14, 2009 3:47:17 PM GMT -05:00 US/Canada Eastern
> Subject: Re: [Mono-list] Service or daemon with Mono?
> 
> I'd like to second that.  I use the same techniques with good results. 
> However, *occasionally* I have problems with my remoting listener 
> holding open the TCP socket after shutdown (in which I unregister the 
> marshalled object(s)).
> 
> If you don't mind me asking, do you do anything specific or special to 
> clean up your remoting channel?
> 
> Amc Gmail wrote:
>> We don't have any problems with .NET service running under Mono. 
>> It's based on ServiceBase, uses EventLog and .NET Remoting without any problems.
>> All you need to do is to create init.d script to start/stop mono-service during startup/shutdown
>> -- amc
>>
>> ----- Original Message -----
>> From: "jos_" <junk at sonhult.se>
>> To: mono-list at lists.ximian.com
>> Sent: Tuesday, July 14, 2009 8:45:07 AM GMT -05:00 US/Canada Eastern
>> Subject: [Mono-list]  Service or daemon with Mono?
>>
>>
>> Hello,
>>
>> What is the recommended way to write a service-like software in Mono?
>>
>> My first guess would be to use the normal class ServiceBase existing in Mono
>> (and .NET of course). But there seems to be little information on how this
>> works with Mono, and from what I've read it is not considered stable (?).
>>
>> 1. Is it better to just create a normal app, turn on automatic login and run
>> it at login?
>> 2. Is it possible to create a daemon using Mono?
>> 3. Is there any documentation on how to "install" the "service" if developed
>> in Mono using ServiceBase (or any other method)?
>>
>> In short: I'm looking for a way to build the Linux equivalent for a service
>> using Mono, and install it on a Linux-dist =)
>>
>> Thanks in advance!
>> / Jonas
> 


More information about the Mono-list mailing list