service application troubles

I have service application that I created using the empty service template.

I’m currently running on mac.

It uses a timer currently set to 10 seconds (will be 60 seconds after I get it all set up) When the timer fires, it logs on to a server, downloads some information and processes it then sends the information to a serial device.

I have a plist setup to handle launching at startup and hopefully keeping running in background: /Library/LaunchDaemons/myapp/com.myapp.plist

I have two problems:

  1. I can’t seem to get the app to load automatically on startup. But I can get it to launch from terminal using: “launchctl load -w /Library/LaunchDaemons/com.myapp.plist”

  2. Once I use launchctl to load the plist, the service does launch but then it duplicates itself (as I observe in the Activity Monitor app). As you may guess the service duplicates itself eveytime the timer fires, in this case every 10 seconds.

Does anyone have suggestions as to how to deal with these two problems?

Below is the text from the plist file

[code]<?xml version="1.0" encoding="UTF-8"?>

Label com.myapp OnDemand ProgramArguments /Library/Application Support/myapp/myapp start RunAtLoad UserName root [/code]

I’m bumping this one hoping some fresh eyes can have a look. . I’ve gotten everything up and running on windows (I got to say, it’s a first for me to have a windows project ready before the Mac one.) For whatever reason on this one, The Mac side is a real head scratcher for me.

If anyone has gotten a service app to load and stay loaded on a Mac, I hope to hear from you as to how you set it up.

Thanks in advance!
Joseph

A service application calls daemon by default, which launchd doesn’t like. If you return True from the DontDaemonize event, it should work.

Thanks for your reply Joe… That helped a lot! I return true and now it only launches once now. I can still only load using launchctl though.

I believe it’s not loading on start up or login because I’m having some sort of permissions and ownership problem with the plist file. Messing around with permissions got me to where I can load on startup But only while logged in as root.

sudo chown root changed ownership
sudo chmod 644 changed permissions

Not sure what permissions should be set to when I’m not logged in as root…

Thanks again!