Service Management API: SMAppService agent/daemon registered by root?

Looking at the sample project in: https://developer.apple.com/documentation/servicemanagement/updating_your_app_package_installer_to_use_the_new_service_management_api

It appears that the SMAppServiceSampleCode command line tool must be executed in a user context to successfully register the agent.

Consequently, the pkg that is created in the sample project would not register the agent if it is installed as root (or when installed from an MDM).

This could be worked out by using launchctl asuser to run the command line tool as the logged-in user user in the postinstall, but if nobody is logged in the pkg installation would actually fail.

If the command line tool is meant to be transparent to the user and not necessarily used by the user, are there any workarounds for this or something that I am missing?

Answered by DTS Engineer in 752848022

I was under the impression that this might go away at some point

While I can’t predict The Future™, I can say that:

  • We’ve made no official statements that support your theory.

  • A lot of folks — both developers shipping products and advanced end users — rely on launchd property lists, so taking them away would be a serious compatibility challenge.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I’d like to clarify your goal here. SMAppService is targeted at apps that want to self install. Using it from an installer package seems weird. Why do that when you could simply have the installer lay down a launchd property list file in /Library/Launch{Daemons,Agents}?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I assume moving forward (macOS 13 and beyond) it will still be perfectly acceptable to continue to use "legacy" launchd items for scenarios where packages installed as root can lay the daemon/agent plists in /Library/Launch* and bootstrap them?

I was under the impression that this might go away at some point, perhaps I was wrong about that.

Accepted Answer

I was under the impression that this might go away at some point

While I can’t predict The Future™, I can say that:

  • We’ve made no official statements that support your theory.

  • A lot of folks — both developers shipping products and advanced end users — rely on launchd property lists, so taking them away would be a serious compatibility challenge.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

This is helpful @eskimo, thanks!

Service Management API: SMAppService agent/daemon registered by root?
 
 
Q