Mac and Window services

I have an app which I want to run as a service on windows and mac, however I have this problem.

if I make the app a serviceappcation it works fine as a service under windows but as a service on a mac it just runs loads of times even using a mutex
if I make the app a console app, it works fine on a mac, but then under windows i have no ability to stop and start the service

Is there a way in compile directives that I can automate what the app will be, either service or console? taking into account if I change the type to console from service I have to keep removing the stop method of app.

I’m curious. In the other thread, you mentioned that the app was crashing on startup. Is that still happening?

You might also want to check and see if the app is actually creating the mutex file. I suspect it’s not and that would explain why you’re getting multiple instances.

Also, where are you putting the daemon plist file? And can you show what the plist looks like?

Also, if you’ll be doing a lot of daemon work, I suggest using LaunchControl. It’s well worth the $10 and makes setting up, experimenting with and maintaining Agents and Daemons a breeze on macOS.

Ok, so first, I suggest adding a ThrottleInterval key just to limit how quickly your app relaunches:

<key>ThrottleInterval</key> <integer>60</integer>

Also, what’s the user and group on your plist?

you should be able to run it in demo mode for a few days

ok, so I’ve got a simple serviceapplication running here on my mac. There were two things I had to do…

First, you should return True in the DontDaemonize event. The OS is doing that for you.

Second, make sure you have a run loop in the Run event like this:

While True App.DoEvents(10) Wend

In LaunchControl, check out the StandardOutput key. That’ll allow you to send the results of Print and StdOut to a specific file for debugging instead of having to weed through the system logs.