python-trio / trio

Trio – a friendly Python library for async concurrency and I/O
https://trio.readthedocs.io
Other
6.07k stars 330 forks source link

Write a helper library for services/daemons #252

Open njsmith opened 7 years ago

njsmith commented 7 years ago

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:

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

Generic services:

njsmith commented 7 years ago

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 commented 6 years ago

See also this comment: https://github.com/python-trio/trio/issues/284#issuecomment-323510540 for some discussion of how service supervisors like to get service status notifications.