1 / 15

Service invocation

Service invocation. Evan Miller eam@yahoo-inc.com. 10.20.11. Agenda. Unix process management, how and why we daemonize Patterns for invoking and shutting down services. Process process process Overview of Daemontools and Runit Q&A. Typical daemonization.

edie
Download Presentation

Service invocation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Service invocation Evan Miller eam@yahoo-inc.com 10.20.11

  2. Agenda • Unix process management, how and why we daemonize • Patterns for invoking and shutting down services. Process process process • Overview of Daemontools and Runit • Q&A

  3. Typical daemonization • Attempt to separate process from calling context • Setsid, process group, process session, disassociate controlling tty • Double fork • Reopen stdin, stdout, stderr to /dev/null • Chdir / • All because process fork from user shell • Attempt to create known starting state • Avoid holding resources • Sshd ever hang after starting a service?

  4. Many things left for granted • Environment vars • Nice, ionice • Other filehandles • Services stop runing – now what? • Story: Admin logs in to restart a service, TZ and LANG • Impossible to enumerate all process attributes!

  5. Two ways your process starts

  6. A better way? • Runit / daemontools • License • Minor command differences • Services start from init • No user shell • Each process gets a supervisor • Each process gets a logger • Init is always running, therefore our stuff is always running • Suite of useful helper tools • Suite of helper tools • How do you drop privileges from the commandline? Sudo/su are terrible

  7. Daemontools process tree

  8. Daemontools architecture

  9. Daemontoolsfilesystem layout • /service/$APP/run • /service/$APP/supervise/{control,lock,ok,status} • Sockets for communication • /service/$APP/log

  10. Daemontools helper commands • Setuidgid • Softlimit • Pgrphack • fghack • Envdir • Key is pluggable, modular commands. Unix philosophy.

  11. Control via messaging • Svc / sv • Send signals via supervise • Svc –t /service/sshd • Svstat / sv status • Read status of running process • No parent/child relationship between invoking user’s process, and app

  12. Requirements for the service • Must foreground • Can log via stdout for simple cases • Should clean up temporary resources before starting • Can it break? Assume it’s broken • Should kill competing services before starting • Sleep between failures to handle restart churn • Should exit gracefully on TERM • Should have documented requirements for cleanup

  13. Recipes and patterns

  14. Startup / shutdown philosophy • Create any runtime state which is known in advance • mkdir /var/log/foo • Resource in use? aggressively reclaim. • Fuser –k –ntcp 80 • Nuke transient runtime data on startup, restore to known good state • Check_dbmy.db || rm –fmy.db • No ordering of services • Poll for resource instead

  15. Questions?

More Related