Nikolay Tsenkov
Nikolay Tsenkov

Reputation: 1128

Where to store services that shouldn't be moved (OSX app install)?

I am building a desktop app which creates a service (daemon) during install.

Before registering the service, though, I want to install the files of this service to a location, different than the app's Contents dir - the user might want to move the app from the Applications dir, and if the service changes location on the next start of the OS, it will not be located and my app will not be able to find it.

Where should I install the service at?

Thanks in advance.

Update:

Is "~/Library/Services" the right place?

Or, perhaps, "/Drivename/Library/Services" for multi-user use?

Upvotes: 0

Views: 113

Answers (1)

gaige
gaige

Reputation: 17471

There's a terminology ambiguity with this question and it might be causing you some difficulty with determining where to locate your files.

Under OSX, a Service can have two meanings, one of which is relating to code that executes in response to the Services menu item in applications, and that's what is stored in the various /Library/Services, /System/Library/Services, and ~/Library/Services directories, so you don't want to place them there.

Daemon Control file placement

Assuming about a daemon (which you mention specifically in the text of your message), then you are going to want to place it in one of the LaunchAgent or LaunchDaemon directories and use launchd to start the daemon for you. For launchd purposes, Agents are run per user and Daemons are run per system (difference is how many copies are run).

For daemons/services that are used by a single user and started when the user logs in, their configuration files may be stored in ~/Library/LaunchAgents, which will allow the system to kick them off whenever the user logs in to the system. If you need something that will be available at all times (i.e. starts when the system boots), you'll need to gain privileges and install in the /Library/LaunchDaemons location.

That's the tale of the configuration files for launchd, but it doesn't address directly your question of where to put the executables to prevent them from getting disconnected if the user relocates the Application outside of the /Applications folder.

Daemon executable placement

These days, fewer users are moving apps out of the /Applications folder unless they're intentionally uninstalling or deactivating them, so you may want to avoid trying to prevent this. Instead, when the application launches, you should verify that the daemon is running and if it isn't, install and activate the appropriate launchd configurations using your application's internal Library folder as the repository for the code which is referenced by the launchd configuration.

If you choose to store them separately, you should place them in either ~/Library/Application Support/(your app's id) or /Library/Application Support/(your app's id), depending on whether you are installing per-user or per-machine. Generally, the latter is preferred.

Upvotes: 1

Related Questions