I am at the point where I need to make an existing desktop application a service and enable this application to run at computer startup without the need of a user to log in and run it. This service has the need to always be running in the back ground performing various network/db checks and responses.
At this point I have successfully removed all GUI aspects and have an event driven console app that works. Now onto the next step making a service app that will run on MAC OSX Server 10.7.5 and daemonize so it runs at startup
I have used the service app template to start with but am looking for more info about what I should pay attention to from a Xojo perspective as I work to complete this service.
Beyond the bigger picture I am looking to find out simple things like:
How do you get this to run code in the debugger? I have code in the run statement but when I select run in the IDE the code never gets to the first break point
Can you do this remotely?
How can arguments be passed at startup
How can you have another program check for existence of this service and then start the service in case it is not running?
I have looked through the help archives, language learning and RBLibrary seeking help docs on how to accomplish this and came up fairly empty. I have checked the supplied examples. I could have missed it but I did not find such information there either.
Any suggestions and/or documentation recommendations on how to create Xojo service apps on MAC as well as daemon steps would be appreciated
[quote=50225:@Carl Fitzsimmons]I have used launched on both Console and Event Driven Console apps and the response is '‘launched: This program is not meant to be run directly.’
Both the Console and Event Driven Console apps were created using the Xojo Templates
Both apps start when double clicked and open in Terminal[/quote]
Right
For launchd you write a little script that tells the OS how & when to start your app (at boot etc) and the OS will take care of doing whatever it is you asked launchd to do
You don’t run launched directly
Interesting. I downloaded Lingon. Setting up a Daemon or Agent seems straight forward
So I placed the entire folder that was output from Xojo build process of the Event Driven Console App into Applications folder
Set permissions to root xrw as well as owner, group, everyone else
Created a User Daemon for this Event Driven Console App
Rebooted the machine
The Event Driven Console app fails to start
I rebooted several times and then looked at the System Diagnostic Reports. The failure is at the same place which is a location in the app that writes to system log.
When I double click on the Event Driven Console App after I have logged in the app works fine
The specific sub in my app is writing to the error log. This app needs to go out on the network and perform a bunch of reads/writes to/from a db as well as other networked devices on startup. So it seems that this app is starting up at the wrong time of the boot up sequence of the machine
If that seems reasonable how do I delay the start until a certain time later or monitor an environment value such as something that would indicate the machine is up and ready to go?
Send_message checks directories for existence, creates new directories if needed, then checks for log file, creates if needed then writes to the log file, then leaves to calling sub
The file on startup will be new. The app has permissions to write set to root.
So I am not sure what to look for and since this fails on startup there is no way to debug which is why I am writing to sys log. Most importantly this is the error print routine that is called meaning the network request to the DB has failed.
The app works once the machine is running from the same location the plist file is pointed to
Yes. Rather interesting. I had implemented a Exception err handler for various exceptions at the end of the routine. So when it failed it called itself.
Now to find out why it failed. The only thing this performs is checking directories, creates a directory when it does not exist, checks for a log file and creates one if it does not exist then go back to the calling sub
The big question is that this works fine when the machine is up and running. Make she think of network/File IO stuff
I’d do two things to your write_Log_Error() method
make sure it is bulletproof - it should trap all reasonable exceptions and have graceful failure modes
log messages liberally using System.DebugLog() - I would also add a “verbose” debugging mode to your app such as this:
#if VerboseDebug
system.DebugLog("just entered method")
#endif
...
#if VerboseDebug
system.DebugLog("about to try to make the folder")
#endif
...
#if VerboseDebug
system.DebugLog("reached the end of the method, about to exit")
#endif
Just a note: Perhaps it would be better to use a variable which can be changed at runtime to get better logging. Then you may set a specific environment variable (or command ling argument like “-v”, “-vv”) to trigger the output.
if verboseLevel=1 then
system.DebugLog("just entered method")
end
if verboseLevel=2 then
system.DebugLog("just wrote the first log ;-)")
end
The benefit of this is that you may able to tell your customer how to enable logging on his machine where something does not work.