Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

launchd item: Start netatalk in non-forking mode #1859

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

EricFromCanada
Copy link
Contributor

An issue with the current implementation of the launchd item is that unloading or stopping the it (e.g by running sudo brew services stop netatalk) doesn't actually stop the netatalk process. This is because the launchd is running the equivalent of sudo netatalkd start (which starts netatalk (which itself starts afpd and cnid_metad)) and immediately exits.

Since Apple's docs for processes managed by launchd specify that they be non-forking, a workaround is to invoke the netatalk process directly with its -d flag. When the launchd item is stopped, netatalk is ended along with afpd and cnid_metad.

Copy link
Member

@rdmark rdmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@rdmark rdmark merged commit 206fb77 into Netatalk:main Jan 8, 2025
28 checks passed
@NJRoadfan
Copy link
Contributor

I am a bit confused by this change. Shouldn't Netatalk be started and stopped with:

sudo launchctl start io.netatalk.daemon
sudo launchctl stop io.netatalk.daemon

As opposed to sudo netatalkd stop and sudo netatalkd start?

Right now it looks like launchd is now just starting the netatalk daemon and not doing any lock file housekeeping that the netatalkd script does.

@EricFromCanada
Copy link
Contributor Author

EricFromCanada commented Jan 9, 2025

This came up during the development of the netatalk Homebrew formula. Essentially, formulae can define services that can be started and stopped with the brew services command, which behind the scenes is just (on macOS) running launchctl commands like the ones above.

This change adjusts how the io.netatalk.daemon launchd item starts netatalk by ensuring it's done without forking, so that when the launchd item is stopped, then the netatalk process and its subprocess stop as well; this wasn't happening originally.

The netatalkd script still serves as a handy way to start and stop netatalk on-demand in the shell, but it's actually written to be a StartupItem, which is how user-level background processes were managed in early versions of OS X until being replaced by launchd in 10.4 Tiger and eventually phased out.

[admin's note: edited to fix URL]

@rdmark
Copy link
Member

rdmark commented Jan 9, 2025

As an historical view: The original purpose of the netatalkd script was to activate the OBJC_DISABLE_INITIALIZE_FORK_SAFETY flag and stop macOS frameworks from instantly killing netatalk upon launch. We figured out recently how to avoid linking with Objective-C libraries, so this workaround is no longer needed.

I agree that losing lockfile housekeeping is a drawback. In systemd, if you point to the lockfile with the PIDFile= option, systemd does the housekeeping for you. I wonder if launchd has a similar facility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants