Service does not start [modified]
-
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
-
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
Try to use: Console.Out or Console.Err
-
Try to use: Console.Out or Console.Err
-
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 :)
-
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
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:
-
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:
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
-
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
-
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:
-
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:
-
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:
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 callmono-service2 ServiceTest.exe
to stop it?modified on Tuesday, December 15, 2009 12:02 PM
-
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 callmono-service2 ServiceTest.exe
to stop it?modified on Tuesday, December 15, 2009 12:02 PM
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:
-
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: