Standalone Topshelf service doesn't seem to be running

867 views
Skip to first unread message

ryexley

unread,
Oct 6, 2011, 9:04:29 AM10/6/11
to topshelf-discuss
I've created a standalone service using Topshelf, and am seeing some
weird behavior when I try to run the service after installing it. My
HostFactory's new service is setup to ConstructUsing my
FaxBatchProcessor class, like so:

public class Program
{
static void Main(string[] args)
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(".\
\FaxBatchService.logging.config"));
var host = HostFactory.New(x =>
{
x.AfterStoppingServices(n =>
Console.WriteLine("Services are being stopped"));
x.Service<FaxBatchProcessor>(s =>
{
s.SetServiceName("FaxBatchProcessor");
s.ConstructUsing(name => new
FaxBatchProcessor());
s.WhenStarted(fbp => fbp.Start());
s.WhenStopped(fbp => fbp.Stop());
});

x.RunAsLocalSystem();
x.SetDisplayName("FDC Fax Batch Processor");
x.SetDescription("FDC service for batch processing of
Agency DAFs");
x.SetServiceName("FaxBatchProcessor");
});

host.Run();
}
}

My FaxBatchProcessor class is pretty straight forward too, it's setup
like this:

public class FaxBatchProcessor
{
private readonly ILog _log;
private readonly Timer _timer;

public FaxBatchProcessor()
{
_log = LogManager.GetLogger(this.GetType());

_timer = new Timer(Service.ProcessingInterval) { AutoReset =
true };
_timer.Elapsed += (sender, eventArgs) =>
CheckForQueuedBatches();
}

public void Start()
{
_timer.Start();
_log.Info("FaxBatchProcessor started");

EnsureDocumentStorageRootExists();
}

public void Stop()
{
_timer.Stop();
_log.Info("FaxBatchProcessor stopped");
}

public void CheckForQueuedBatches()
{
...
}
}

I can install the service successfully by executing "MyExe.exe
install" from a command prompt, and the installation succeeds without
any issues, and I can even startup the service successfully. My
problem is that once the service is running...it doesn't actually *do*
anything...

When I start the service, I can tell that the Start() method is
getting run as expected, because the Directory that the
EnsureDocumentStorageRootExists() method creates gets created as
expected. The log file gets created when the service is installed, but
after that, it never gets updated. The Start method is supposed to log
"FaxBatchProcessor started" to the log file, but it never does...and
my logging configuration is set to log ALL messages. After installing
the service and starting it up...nothing ever happens.

I'm pretty lost as to why...anyone see anything I'm missing or doing
wrong? I really need to get this working. Any ideas would be greatly
appreciated.

Thanks.

Dru Sellers

unread,
Oct 6, 2011, 9:45:36 AM10/6/11
to topshelf...@googlegroups.com
man this looks pretty good to me. this is the second thing like this I have heard about.
can you try running it in console mode with a debugger and let me what's what?

-d

ryexley

unread,
Oct 6, 2011, 11:00:43 AM10/6/11
to topshelf-discuss
Yeah, it runs great as a console app, no errors or anything, and does
what I expect it to do.

Dru Sellers

unread,
Oct 6, 2011, 11:02:49 AM10/6/11
to topshelf...@googlegroups.com
hmmm.

ok. gonna have to get into this. I don't have anything for you right now. :(

-d

ryexley

unread,
Oct 6, 2011, 11:16:52 AM10/6/11
to topshelf-discuss
OK, well...let me know if there's anything I can do to help get this
figured out. I'd love to get this thing running as a service ASAP.

Thanks for taking a look at it.

On Oct 6, 11:02 am, Dru Sellers <d...@drusellers.com> wrote:
> hmmm.
>
> ok. gonna have to get into this. I don't have anything for you right now. :(
>
> -d
>
>
>
>
>
>
>
> On Thu, Oct 6, 2011 at 8:45 AM, Dru Sellers <d...@drusellers.com> wrote:
> > man this looks pretty good to me. this is the second thing like this I have
> > heard about.
> > can you try running it in console mode with a debugger and let me what's
> > what?
>
> > -d
>

Dru Sellers

unread,
Oct 6, 2011, 11:20:07 AM10/6/11
to topshelf...@googlegroups.com
at this exact moment I can only give you the very shitty. debug topshelf response. :(

that said, pull down TS from github and make sure the clock sample is working as a service.
then maybe debug through the winservice code. ?????

-d

John Simons

unread,
Oct 6, 2011, 4:09:15 PM10/6/11
to topshelf...@googlegroups.com
Wondering if there is any .Net exceptions being logged in the event viewer of the machine under Application?
Also what account are u using when running as a service vs console?

John


From: ryexley <rye...@gmail.com>
To: topshelf-discuss <topshelf...@googlegroups.com>
Sent: Friday, 7 October 2011 2:16 AM
Subject: [topshelf-discuss] Re: Standalone Topshelf service doesn't seem to be running

ryexley

unread,
Oct 6, 2011, 5:10:28 PM10/6/11
to topshelf-discuss
I've seen nothing at all in the Event Log on the machine. I've run the
service as Local System, Local Service, and my own user account as
well...same results with all accounts. When running via console, I've
ran the console with administrative privileges (hhmmm...don't think I
tried it without admin privs...will give that a shot), but my user
account is a member of the local Administrators group, so I would
think the results would be the same.

On Oct 6, 4:09 pm, John Simons <johnsimons...@yahoo.com.au> wrote:
> Wondering if there is any .Net exceptions being logged in the event viewer of the machine under Application?
> Also what account are u using when running as a service vs console?
>
> John
>
> ________________________________
> From: ryexley <ryex...@gmail.com>

ryexley

unread,
Oct 7, 2011, 9:21:45 AM10/7/11
to topshelf-discuss
Couple of follow-up items...

First, I tried running the app in console mode without admin privs,
and everything works as expected there, so it doesn't appear to be a
permissions issue from what I can tell at this point.

Second, I built the latest source from Github, and installed the clock
sample as a service...well, it *works*, but it only really works as
well as mine does as far as I can tell. It doesn't really *do*
anything when installed as a service. There's no console to write to,
and it's not writing anything to a log file when it runs, so...it's
kinda hard to tell if that really confirms or denies anything.

Have others used this for installing/running standalone services like
this successfully? Is it an OS issue maybe? I'm running this on 64bit
Win7 Ultimate. Haven't tried it on anything else. I haven't tried
actually debugging Topshelf or anything like that yet. That may end up
being my next step if I get the time, but I chose Topshelf in the
first place because I'm kinda under a time crunch and this looked like
I could get this up-and-running fast...It appears to be a great
framework, and I appreciate the work that's gone into it, but I've
tried it in both shelf and standalone mode now, and neither has worked
at all for me so far.

Chris Patterson

unread,
Oct 9, 2011, 11:08:39 AM10/9/11
to topshelf...@googlegroups.com
Which timer class are you using? I'm not sure if the Windows Forms timer class works in a service, but make sure you are using the Timer in the System.Threading namespace.

I've got dozens of services up and running with the latest NuGet of Topshelf, so there must be some other issue at play here.

ryexley

unread,
Oct 11, 2011, 8:47:00 AM10/11/11
to topshelf-discuss
I was using the same one used in the sample app: System.Timers.Timer.
For the sake of progress, I've removed Topshelf from the project and
started in another direction, but it would be simple enough to pull it
back in if any ideas toward a solution came up. Wish I hadn't had to
do that, but I need to get this thing up-and-running soon.

Jonas Gauffin

unread,
Oct 11, 2011, 8:49:04 AM10/11/11
to topshelf...@googlegroups.com
System.Timers.Timer works in a service too. The most notable difference is that System.Timers.Timer ignores all uncaught exceptions.

Dru Sellers

unread,
Oct 11, 2011, 2:31:08 PM10/11/11
to topshelf...@googlegroups.com
We can tweak the log4net config to write to a file (i thought I had that already).

I am running the sample shelf now. 

-d

Dru Sellers

unread,
Oct 11, 2011, 2:31:51 PM10/11/11
to topshelf...@googlegroups.com
the sample shelf is writing a log file. all looks good.

any updates?

-d

ryexley

unread,
Oct 11, 2011, 5:20:22 PM10/11/11
to topshelf-discuss
I don't have anything new to contribute. As I mentioned earlier today,
I removed Topshelf from the project for the sake of progress, so I
don't have any new information. I do know of a friend was recently ran
into what appeared to be at least a very similar issue using Topshelf,
so I'll contact him and see if he has anything additional to
contribute to the conversation. Sorry I'm not of more help, but I had
to move on to get something working for the time being.

On Oct 11, 2:31 pm, Dru Sellers <d...@drusellers.com> wrote:
> the sample shelf is writing a log file. all looks good.
>
> any updates?
>
> -d
>
>
>
>
>
>
>
> On Tue, Oct 11, 2011 at 1:31 PM, Dru Sellers <d...@drusellers.com> wrote:
> > We can tweak the log4net config to write to a file (i thought I had that
> > already).
>
> > I am running the sample shelf now.
>
> > -d
>

Dru Sellers

unread,
Oct 11, 2011, 5:26:37 PM10/11/11
to topshelf...@googlegroups.com
No problem.  I understand completely. :)
-d

Henrik Feldt

unread,
Jan 19, 2012, 10:30:23 AM1/19/12
to topshelf...@googlegroups.com
A while ago I did a spike on quartz and topshelf:
https://github.com/haf/QuartzTopshelfSample

Perhaps for someone finding this thread in the future, this could be a good way to move forward, rather than having the raw Timer.

Cheers,

Travis Smith

unread,
Jan 19, 2012, 4:10:15 PM1/19/12
to topshelf...@googlegroups.com
Thanks, that's brilliant. If you feel like writing up the examples
into the Docs or something, I'm sure we'd be happy to include those as
well.

-Travis

Henrik Feldt

unread,
Jan 31, 2012, 1:06:10 PM1/31/12
to topshelf...@googlegroups.com
Cool, yeah, I could write them up in the docs. I have a bit of doc currently outstanding as pull requests that might be interesting to pull in for you.

jason

unread,
Feb 14, 2012, 4:58:02 PM2/14/12
to topshelf-discuss
Did this problem ever get resolved? I'm having the exact same issue

jt

On Jan 31, 1:06 pm, Henrik Feldt <logi...@gmail.com> wrote:
> Cool, yeah, I could write them up in the docs. I have a bit of doc
> currently outstanding as pull requests that might be interesting to pull in
> for you.
>
> On Thu, Jan 19, 2012 at 10:10 PM, Travis Smith <tra...@legomaster.net>wrote:
>
>
>
>
>
>
>
> > Thanks, that's brilliant. If you feel like writing up the examples
> > into the Docs or something, I'm sure we'd be happy to include those as
> > well.
>
> > -Travis
>
> > On Thu, Jan 19, 2012 at 10:30 AM, Henrik Feldt <logi...@gmail.com> wrote:
> > > A while ago I did a spike on quartz and topshelf:
> > >https://github.com/haf/QuartzTopshelfSample
>
> > > Perhaps for someone finding this thread in the future, this could be a
> > good
> > > way to move forward, rather than having the raw Timer.
>
> > > Cheers,
>
> > > On Tue, Oct 11, 2011 at 11:26 PM, Dru Sellers <d...@drusellers.com>
> > wrote:
>
> > >> No problem.  I understand completely. :)
> > >> -d
>
> ...
>
> read more »

Travis Smith

unread,
Feb 14, 2012, 4:59:37 PM2/14/12
to topshelf...@googlegroups.com
Generate some logs, try to also write to logs from your service, then
we can maybe see what's going on. Also indicating what version of
Topshelf you're using is helpful.

-Travis

jason turim

unread,
Feb 14, 2012, 5:03:32 PM2/14/12
to topshelf...@googlegroups.com
Here's the start up code, this is using TopShelf 2.2.2.0
https://gist.github.com/1830880 

my logs show the following
... HostFactory is running
... HostConfigurator is running

and then nothing, so it looks like none of the Before*, After* or When* callbacks are firing

jason turim

unread,
Feb 14, 2012, 6:12:21 PM2/14/12
to topshelf...@googlegroups.com
Folks,

This turned out to be operator error - I need to reconfigure log4net inside each of the When* lambda expressions.  Once I did that, my log lit up as I expected it to.

jt
Reply all
Reply to author
Forward
0 new messages