I've create a fairly simple System.ServiceProcess.ServiceBase on what I
think is the correct manner. But when I try to run it with
mono-service2 it seems as though nothing at all happens, not even any
error messages.
$ mono-service2 --no-daemon Whitemice.ZideNET.exe
- or -
$ mono-service2 Whitemice.ZideNET.exe
It does not even create the log file configured via log4net for the
Service object. If I run it via straight mono -
$ mono Whitemice.ZideNET.exe
$ cat ZideNET.log
DEBUG ZideNET.Service (null) - Main
DEBUG ZideNET.Service (null) - Service ctor
DEBUG ZideNET.Service (null) - Service ctor complete
DEBUG ZideNET.Service (null) - Starting 1 services....
- I get a log but, of course, the service doesn't actually start.
Is there a bug/issue or am I (very probably) missing something obvious?
I've never created a service before, but from the docs it looked pretty
straight-forward.
mono-core-2.0.1-18.1 / openSUSE 11
// Service.cs
//
// Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.ComponentModel;
using System.Threading;
using System.ServiceProcess;
using log4net;
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
namespace Whitemice.ZideNET
{
public class Service : System.ServiceProcess.ServiceBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(Whitemice.ZideNET.Service));
private System.ComponentModel.Container components;
private Whitemice.ZideNET.Listener listener;
private System.Threading.Thread listenerThread;
public Service()
{
log.Debug("Service ctor");
try {
listener = new Listener();
} catch (Exception e)
{
log.Fatal(e.Message);
}
log.Debug("Service ctor complete");
} // end ctor
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] services;
log.Debug("Main");
services = new System.ServiceProcess.ServiceBase[] { new Whitemice.ZideNET.Service() };
log.DebugFormat("Starting {0} services....", services.Length);
System.ServiceProcess.ServiceBase.Run(services);
} // end Main
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "ZideNET";
} // end InitializeComponent
protected override void OnStart(string[] args)
{
log.Debug("Service OnStart");
listener.Run = true;
listenerThread = new Thread(new ThreadStart(listener.Start));
listenerThread.Start();
} // end OnStart
protected override void OnStop()
{
log.Debug("Service OnStop");
listenerThread.Abort();
listener = null;
} // end OnStop
protected override void OnContinue()
{
log.Debug("Service OnContinue");;
} // end OnContinue
protected override void OnPause()
{
log.Debug("Service OnPause");
} // end OnPause
protected override void OnShutdown()
{
log.Debug("Service OnShutdown");
} // end OnShutdown
} // end class
}_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list