Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Service does not start [modified]

Service does not start [modified]

Scheduled Pinned Locked Moved C#
sysadminlinuxdebuggingworkspace
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jordanwb
    wrote on last edited by
    #1

    This is my code:

    using System;
    using System.IO;
    using System.ServiceProcess;
    using System.ComponentModel;
    using System.Configuration;
    using System.Configuration.Install;

    namespace ServiceTest
    {
    public class MainClass : ServiceBase
    {
    public static void Main(string[] args)
    {
    ServiceBase.Run(new MainClass());
    }

        protected override void OnStart(string\[\] args)
        {
    		Console.WriteLine ("Started OK");
    		
    		base.OnStart (args);
    	}
    	
    	protected override void OnStop ()
    	{
    		Console.WriteLine ("Stoppeds OK");
    		
    		base.OnStop ();
    	}
    }
    
    \[RunInstaller(true)\]
    public class MainClassInstaller : Installer
    {
        public MainClassInstaller()
        {
            ServiceProcessInstaller process = new ServiceProcessInstaller();
    
            process.Account = ServiceAccount.LocalSystem;
    
            ServiceInstaller serviceAdmin = new ServiceInstaller();
    
            serviceAdmin.StartType = ServiceStartMode.Manual;
            serviceAdmin.ServiceName = "Service Test";
            serviceAdmin.DisplayName = "Service Test";
    
            Installers.Add(process);
            Installers.Add(serviceAdmin);
        }
    }
    

    }

    I'm writing a Server program in Monodevelop on Ubuntu 9.04, and I've got mono-service2 installed. When I try and run the exe via mono-service2 --debug ./ServiceTest.exe I don't get any output.

    modified on Monday, December 14, 2009 4:51 PM

    M J 2 Replies Last reply
    0
    • J Jordanwb

      This is my code:

      using System;
      using System.IO;
      using System.ServiceProcess;
      using System.ComponentModel;
      using System.Configuration;
      using System.Configuration.Install;

      namespace ServiceTest
      {
      public class MainClass : ServiceBase
      {
      public static void Main(string[] args)
      {
      ServiceBase.Run(new MainClass());
      }

          protected override void OnStart(string\[\] args)
          {
      		Console.WriteLine ("Started OK");
      		
      		base.OnStart (args);
      	}
      	
      	protected override void OnStop ()
      	{
      		Console.WriteLine ("Stoppeds OK");
      		
      		base.OnStop ();
      	}
      }
      
      \[RunInstaller(true)\]
      public class MainClassInstaller : Installer
      {
          public MainClassInstaller()
          {
              ServiceProcessInstaller process = new ServiceProcessInstaller();
      
              process.Account = ServiceAccount.LocalSystem;
      
              ServiceInstaller serviceAdmin = new ServiceInstaller();
      
              serviceAdmin.StartType = ServiceStartMode.Manual;
              serviceAdmin.ServiceName = "Service Test";
              serviceAdmin.DisplayName = "Service Test";
      
              Installers.Add(process);
              Installers.Add(serviceAdmin);
          }
      }
      

      }

      I'm writing a Server program in Monodevelop on Ubuntu 9.04, and I've got mono-service2 installed. When I try and run the exe via mono-service2 --debug ./ServiceTest.exe I don't get any output.

      modified on Monday, December 14, 2009 4:51 PM

      M Offline
      M Offline
      Migounette
      wrote on last edited by
      #2

      Try to use: Console.Out or Console.Err

      J 1 Reply Last reply
      0
      • M Migounette

        Try to use: Console.Out or Console.Err

        J Offline
        J Offline
        Jordanwb
        wrote on last edited by
        #3

        Still no output.

        M 1 Reply Last reply
        0
        • J Jordanwb

          Still no output.

          M Offline
          M Offline
          Migounette
          wrote on last edited by
          #4

          I replied too quickly.... In fact stdin and stdout may be rerouted under linux --> /var/log/messages --> you can try to use strace to see where the logs goes otherwise use: --no-daemon in order to see the output going to the console I hope it's the good answer :)

          1 Reply Last reply
          0
          • J Jordanwb

            This is my code:

            using System;
            using System.IO;
            using System.ServiceProcess;
            using System.ComponentModel;
            using System.Configuration;
            using System.Configuration.Install;

            namespace ServiceTest
            {
            public class MainClass : ServiceBase
            {
            public static void Main(string[] args)
            {
            ServiceBase.Run(new MainClass());
            }

                protected override void OnStart(string\[\] args)
                {
            		Console.WriteLine ("Started OK");
            		
            		base.OnStart (args);
            	}
            	
            	protected override void OnStop ()
            	{
            		Console.WriteLine ("Stoppeds OK");
            		
            		base.OnStop ();
            	}
            }
            
            \[RunInstaller(true)\]
            public class MainClassInstaller : Installer
            {
                public MainClassInstaller()
                {
                    ServiceProcessInstaller process = new ServiceProcessInstaller();
            
                    process.Account = ServiceAccount.LocalSystem;
            
                    ServiceInstaller serviceAdmin = new ServiceInstaller();
            
                    serviceAdmin.StartType = ServiceStartMode.Manual;
                    serviceAdmin.ServiceName = "Service Test";
                    serviceAdmin.DisplayName = "Service Test";
            
                    Installers.Add(process);
                    Installers.Add(serviceAdmin);
                }
            }
            

            }

            I'm writing a Server program in Monodevelop on Ubuntu 9.04, and I've got mono-service2 installed. When I try and run the exe via mono-service2 --debug ./ServiceTest.exe I don't get any output.

            modified on Monday, December 14, 2009 4:51 PM

            J Offline
            J Offline
            Jimmanuel
            wrote on last edited by
            #5

            I've tested your code on my 9.10 installation and it works fine, but I was able to reproduce your problem. Whether or not it's the same problem I can't tell, but here's how I figured out what it was: In addition to writing to the Console, your programs output is sent to the user.log file, you can view it by going to [System -> Administration -> Log File Viewer]. In the list on the left hand side you should be able to find user.log, select it and scroll to the bottom of the log file on the right to see the output from your program. What I did to screw things up was run mono-service2, then open the System Monitor and kill the mono process. When I tried to run mono-service2 again it put an error message in the user.log file that helped me fix the problem, in my case it had created a lock file that wasn't properly disposed of. All I had to do was delete the lock file and all was back to normal. Try checking your log file for any errors that might indicate what's wrong.

            :badger:

            J 1 Reply Last reply
            0
            • J Jimmanuel

              I've tested your code on my 9.10 installation and it works fine, but I was able to reproduce your problem. Whether or not it's the same problem I can't tell, but here's how I figured out what it was: In addition to writing to the Console, your programs output is sent to the user.log file, you can view it by going to [System -> Administration -> Log File Viewer]. In the list on the left hand side you should be able to find user.log, select it and scroll to the bottom of the log file on the right to see the output from your program. What I did to screw things up was run mono-service2, then open the System Monitor and kill the mono process. When I tried to run mono-service2 again it put an error message in the user.log file that helped me fix the problem, in my case it had created a lock file that wasn't properly disposed of. All I had to do was delete the lock file and all was back to normal. Try checking your log file for any errors that might indicate what's wrong.

              :badger:

              J Offline
              J Offline
              Jordanwb
              wrote on last edited by
              #6

              I changed it to Console.Error.Writeline and I was able to see "Started Ok" and "Stopped Ok". I ran mono-service2 with the --no-daemon arg. I'll try it without. *Edit* I started it without the --no-daemon argument, there is no output, but mono does show up in the list of running processes. *Edit #2* There is no output in the user.log file coming from my "service". *Edit #3* Changing it from Console.Error to Console.Out made no change.

              modified on Monday, December 14, 2009 11:22 PM

              J 1 Reply Last reply
              0
              • J Jordanwb

                I changed it to Console.Error.Writeline and I was able to see "Started Ok" and "Stopped Ok". I ran mono-service2 with the --no-daemon arg. I'll try it without. *Edit* I started it without the --no-daemon argument, there is no output, but mono does show up in the list of running processes. *Edit #2* There is no output in the user.log file coming from my "service". *Edit #3* Changing it from Console.Error to Console.Out made no change.

                modified on Monday, December 14, 2009 11:22 PM

                J Offline
                J Offline
                Jimmanuel
                wrote on last edited by
                #7

                I'm surprised that it outputted at all; Windows Services don't have visible consoles attached, running without the --debug flag seems to do that. What if you try writing to a file instead?

                :badger:

                J 1 Reply Last reply
                0
                • J Jimmanuel

                  I'm surprised that it outputted at all; Windows Services don't have visible consoles attached, running without the --debug flag seems to do that. What if you try writing to a file instead?

                  :badger:

                  J Offline
                  J Offline
                  Jordanwb
                  wrote on last edited by
                  #8

                  In my opening post I stated I was running Ubuntu 9.04

                  J 1 Reply Last reply
                  0
                  • J Jordanwb

                    In my opening post I stated I was running Ubuntu 9.04

                    J Offline
                    J Offline
                    Jimmanuel
                    wrote on last edited by
                    #9

                    Yes, but a service is a service. I would expect mono to mimic the behavior of services on their native platform, which is what running without the --debug flag seems to do. Natively they have no console or UI so if you want output, the easiest way is to write it to a file. Like I said, though, your code works on my 9.10 installation with the --debug flag. :badger:

                    J 1 Reply Last reply
                    0
                    • J Jimmanuel

                      Yes, but a service is a service. I would expect mono to mimic the behavior of services on their native platform, which is what running without the --debug flag seems to do. Natively they have no console or UI so if you want output, the easiest way is to write it to a file. Like I said, though, your code works on my 9.10 installation with the --debug flag. :badger:

                      J Offline
                      J Offline
                      Jordanwb
                      wrote on last edited by
                      #10

                      I'll try writing to a file. *Edit* On Ubuntu 9.10 the output of Console.WriteLine, Console.Out.WriteLine and Console.Error.WriteLine goes to the user log. Why do I have to killall mono in order to stop the service? Why can't I just call mono-service2 ServiceTest.exe to stop it?

                      modified on Tuesday, December 15, 2009 12:02 PM

                      J 1 Reply Last reply
                      0
                      • J Jordanwb

                        I'll try writing to a file. *Edit* On Ubuntu 9.10 the output of Console.WriteLine, Console.Out.WriteLine and Console.Error.WriteLine goes to the user log. Why do I have to killall mono in order to stop the service? Why can't I just call mono-service2 ServiceTest.exe to stop it?

                        modified on Tuesday, December 15, 2009 12:02 PM

                        J Offline
                        J Offline
                        Jimmanuel
                        wrote on last edited by
                        #11

                        From what it looked like when I tried it killing the mono process didn't give it a chance to cleanup the lock file that it created for the service that it was running. Any further attempts to run the service would fail because it would see the dead lock file and think it was still running. The docs for mono-service[^] tell you how to start a service where you know where the lock file is and then use that to stop the service. :badger:

                        J 1 Reply Last reply
                        0
                        • J Jimmanuel

                          From what it looked like when I tried it killing the mono process didn't give it a chance to cleanup the lock file that it created for the service that it was running. Any further attempts to run the service would fail because it would see the dead lock file and think it was still running. The docs for mono-service[^] tell you how to start a service where you know where the lock file is and then use that to stop the service. :badger:

                          J Offline
                          J Offline
                          Jordanwb
                          wrote on last edited by
                          #12

                          Okay Thanks.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups