Bug 323226 (MONO80538) - Program not working using mono-service (working well using mono)
Summary: Program not working using mono-service (working well using mono)
Status: RESOLVED INVALID
Alias: MONO80538
Product: Mono: Runtime
Classification: Mono
Component: generics (show other bugs)
Version: 1.2
Hardware: Other Other
: P3 - Medium : Blocker
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Martin Baulig
URL:
Whiteboard:
Keywords: blocking
Depends on:
Blocks:
 
Reported: 2007-01-17 14:06 UTC by rouzaire
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:23:14 UTC


---- Reported by rouzaire@matiasat.com 2007-01-17 07:06:31 MST ----

Description of Problem:

I have a program that works perfectly under mono as a console, but not 
using mono-service. It seems like mono-service is not compiled with all 
librairies...

I compile with VCS2005.Net, and run it on Linux Fedora Core 6, using Mono 
1.2.2

Steps to reproduce the problem:

1. As i run the program (code below) using a console : "mono 
TestService.exe -runconsole". Everything works fine.

2. As i run it using a daemon script (script 
below) : "/var/init.d/TestService start", the program doesn't work. The 
classes StringSplitOptions, and the methods Array.Resize and Array.Copy 
seem to be blocking

Additional Information:

// ---------------------
// One file program code
// ---------------------
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.ServiceProcess;
using System.Threading;
using System.IO;
using System.Net.Sockets;
using System.Net;

namespace TestService
{

    // **************************
    // Program Class
    // **************************

    static class Program
    {

        [STAThread]
        static void Main(string[] args)
        {

            Trace.Listeners.Add(new TextWriterTraceListener
(Application.ExecutablePath + ".log", "log"));
            Trace.AutoFlush = true;

            string runMode = "-runservice";
            if (args.Length > 0 && args[0] != null && args[0].Equals("-
runconsole")) runMode = "-runconsole";

            // *************************************
            // Running as a service
            if (runMode.Equals("-runservice"))
            {
                Trace.WriteLine("TestService:: Service starting");
                ServiceBase[] servicesToRun = new ServiceBase[] { new 
ServiceRunner() };
                ServiceBase.Run(servicesToRun);
            }
            // *************************************
            // Running as a console
            else if (runMode.Equals("-runconsole"))
            {
                Trace.WriteLine("TestService:: Console starting");
                ActionClass action = new ActionClass();
                action.Start();
                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
                action.Stop();
                Console.WriteLine("TestService:: Console stopped");
            }
            else 
            {
                Console.WriteLine("---------------------------------------
------------------------");
                Console.WriteLine("Usage : TestService.exe [-runservice 
(default)] [-runconsole] ");
                Console.WriteLine("---------------------------------------
------------------------");
                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
            }

        }

    }

    // **************************
    // Service Class
    // **************************

    class ServiceRunner : ServiceBase
    {

        ActionClass action = null;

        public ServiceRunner()
        {
        
            try
            {
                Trace.WriteLine("TestService:: Initializing ServiceImpl");
                this.ServiceName = "TestService";
            }
            catch (Exception ex) {
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                Console.WriteLine("TestService:: Starting ServiceImpl");
                action = new ActionClass();
                action.Start();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }

        protected override void OnStop()
        {
            try
            {
                Trace.WriteLine("TestService:: Stopping ServiceImpl");
                action.Stop();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }

    }

    // **************************
    // Action Class
    // **************************

    class ActionClass
    {

        private Thread thread = null;

        public ActionClass() {
            Trace.WriteLine("TestService:: Initializing ActionClass");
            thread = new Thread(new ThreadStart(this.DoThreadStart));
            thread.IsBackground = false;
        }

        public void Start()
        {
            Trace.WriteLine("TestService:: Starting ActionClass");
            thread.Start();
        }

        public void Stop()
        {
            try
            {
                Trace.WriteLine("TestService:: Stopping ActionClass");
                thread.Abort();
                thread = null;
            }
            catch (Exception ex) {
                Trace.WriteLine(ex.Message);
                Trace.WriteLine(ex.StackTrace);
            }
        }

        private void DoThreadStart() {
            byte[] bytes = { 1, 2, 3, 4 };
            byte[] bytesAdd = { 5, 6, 7, 8 };
            
            while (true) 
            {
                try {
                    Trace.WriteLine("TestService:: Processing thread 
action");

                    /*
                    // Test for StringSplitOptions
                    string[] sep = { ";" };
                    string[] s = ("xxx;yyy;;zzz").Split(sep, 
StringSplitOptions.RemoveEmptyEntries);
                    Trace.WriteLine("Split result : " + s.Length);
                    */

                    /*
                    // Test for Array functions
                    int lastLength = bytes.Length;
                    Array.Resize(ref bytes, bytes.Length + 
bytesAdd.Length);
                    Array.Copy(bytesAdd, 0, bytes, lastLength, 
bytesAdd.Length);
                    Trace.WriteLine("Resize result : " + bytes.Length);
                    */

                    Thread.Sleep(1000);
                } catch (Exception ex) {
                    Trace.WriteLine(ex.Message);
                    Trace.WriteLine(ex.StackTrace);
                }
            }
        }
    }


}

// ------------------------------------------
// Daemon script (/etc/init.d/TestService)
// ------------------------------------------


#!/bin/sh
# chkconfig: 1356 85 15 
# description:TestService Mono - Linux

# processname: TestService

# Source function library.
. /etc/rc.d/init.d/functions


#Variables
PIDFILE=$"/var/TestService/TestService.pid"
PROCESS=$"TestService"
MONOPATH=$"/usr/bin/mono-service"
EXEPATH=$"/var/TestService/TestService.exe"
OPTIONS=$"-l:$PIDFILE -m:TestService"

start() {
rm -f ${PIDFILE}
daemon $MONOPATH $OPTIONS $EXEPATH
RETVAL=$?
echo 
return $RETVAL
}

stop()
{
kill `cat ${PIDFILE}`
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${PIDFILE}
}

case "$1" in
 start)
    echo -n $"Starting $PROCESS: "
start
;;
 stop)
    echo -n $"Stopping $PROCESS: "
stop
;;
 restart)
    echo -n $"Reloading $PROCESS: "
stop
sleep 10
start
;;
 status)
status -p ${PIDFILE}
;;
 *)
     echo -n "Usage: $PROCESS start| stop|restart|status"
     exit 1
esac



---- Additional Comments From miguel@ximian.com 2007-01-17 09:28:26 MST ----

You must use mono-service2 if your application is compiled against the
2.0 API.



---- Additional Comments From rouzaire@matiasat.com 2007-01-17 11:39:01 MST ----

Oups...
It did'nt work first, but i modified the mono-service2.sh 
Thanks a lot
Rouz


Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>Linux Fedora Core 6</cf_op_sys_details>
Unknown operating system other. Setting to default OS "Other".