On Sat, 2008-10-25 at 12:35 -0400, Adam Tauno Williams wrote:
> 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

I have modified your test to log to a file (attached) and run it using
mono-service2. The output I see in the file is:
---------
Main
Service ctor
Service ctor complete
Starting 1 services....
Service OnStart
---------

So the problem must be something else.
// 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 System.IO;

namespace Whitemice.ZideNET
{
	static class log {
		public static void Debug (string str)
		{
			DebugFormat (str);
		}
		public static void DebugFormat (string str, params object [] args)
		{
			using (StreamWriter writer = File.AppendText ("/tmp/log.txt")) {
				writer.WriteLine (str, args);
			}
		}
		public static void Fatal (string str)
		{
			DebugFormat (str);
		}
	}

  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

Reply via email to