Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X daemon using Objective-C - launchd

I'm new in Mac OS X world but I have skills on Windows dev.

I need to develop a daemon (on Windows will be Windows Service) that uploads/downloads files from a Web Service.

My question is: is it possible to create an app written in Objective-C that will be the daemon (to upload/download) and to launch it when the OS starts using launchd? Or there's another way to create a daemon?

Thank you

like image 642
avmauricio Avatar asked May 08 '12 22:05

avmauricio


1 Answers

On OS X these services are called LaunchDaemon (system-wide) and LaunchAgent (user-specific). You create a configuration which tells the system when to start, which executable to run, what to do with stdin, stdout, and stderr, which arguments to pass, and so on. Have a look at these man pages:

launchd(8)       # the service controlling other services
launchctl(1)     # the command to control services
launchd.plist(5) # the configuration format for services

The daemon can be written in any language that runs on OS X. So Objective-C is a typical choice for the Mac platform, but anything else from Ruby, Python, and Perl over AppleScript to plain C or C++ would do.

And no, there is no other (recommended) way to do this on the Mac. init.d-style scripts don't work on the Mac [or on Darwin, it's UNIX layer]. Or, more precisely, there is not the infrastructure that runs them.

For more info see the Daemons and Services Programming Guide.

like image 67
febeling Avatar answered Oct 20 '22 20:10

febeling