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

Write a helper library for services/daemons #252

Open
njsmith opened this issue Jul 27, 2017 · 2 comments
Open

Write a helper library for services/daemons #252

njsmith opened this issue Jul 27, 2017 · 2 comments

Comments

@njsmith
Copy link
Member

njsmith commented Jul 27, 2017

A very common use case for a library like trio is writing long-running server processes. We should make it easy to get this right. This should probably be as a new package on top of trio. Some brainstorming:

Integrating with platform-specific service management systems:

  • Windows services

  • Launchd integration, in particular socket activation. This is done by calling launch_activate_socket("lookup-key", ...), which returns an array of fds. (Could be multiple e.g. one for IPv4 and one for IPv6).

  • Systemd integration: socket activation (depends on On Linux, set up socket object correctly when creating from an fd #251), watchdog support, sd_notify, maybe sd_pid_notify_with_fds, ... (see sd-daemon.h). These can be done via a binding to libsystemd or through our own implementation (they're all pretty trivially defined in terms of environment variable manipulation etc.), and either way there's a choice whether to write our own or use an existing one.

It might also make sense to support classic double-fork daemonization, though that's fallen out of popularity these days.

Generic services:

  • abstracting away the differences between different socket activation styles (a bit tricky, since launchd always uses names but we can't really introspect the returned sockets – again see On Linux, set up socket object correctly when creating from an fd #251 – while systemd prefers to use introspection and only supports names as a fallback.)

  • graceful shutdown -- SIGTERM, however windows services do it

@njsmith
Copy link
Member Author

njsmith commented Aug 1, 2017

Systemd check-list for well-behaved Linux daemons: https://www.freedesktop.org/software/systemd/man/daemon.html#New-Style%20Daemons
(scroll-up for a checklist for old-style daemons)

(See also: suggestions for writing daemons that accept sockets from systemd or fall back to creating their own)

MacOS documentation for well-behaved MacOS daemons: https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

That MacOS docs page says that daemons should "check in" (which according to the sample code uses launch_msg) and get the "launch dictionary", but I guess actually this is deprecated?

@njsmith
Copy link
Member Author

njsmith commented Sep 3, 2018

See also this comment: #284 (comment) for some discussion of how service supervisors like to get service status notifications.

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

No branches or pull requests

1 participant