Upgrade to Pro — share decks privately, control downloads, hide ads and more …

systemd: The Good Parts

systemd: The Good Parts

Even though there is some dissatisfaction with systemd in the sysadmin community, James Nugent, an engineer at Samsung Research, shows why it largely fulfills its primary purposes.

In this talk he takes a tour of the great, and sometimes unappreciated or lesser-known features of systemd. He also explains how it can be paired with Packer and Terraform as a component of self-healing systems, and how it can also be used in a production-grade Consul cluster.

James Nugent

July 11, 2018
Tweet

More Decks by James Nugent

Other Decks in Technology

Transcript

  1. systemd: The Good Parts
    James Nugent
    Samsung Electronics
    @jen20

    View full-size slide

  2. Fedora 15 May 2011
    openSUSE 12.2 September 2012
    CentOS 7.14.04 April 2014
    Red Hat Enterprise Linux 7.0 June 2014
    SUSE Linux Enterprise Server 12 October 2014
    Debian 8 April 2015
    Ubuntu 15.04 April 2015
    systemd Adop+on

    View full-size slide

  3. Fedora 15 May 2011
    openSUSE 12.2 September 2012
    CentOS 7.14.04 April 2014
    Red Hat Enterprise Linux 7.0 June 2014
    SUSE Linux Enterprise Server 12 October 2014
    Debian 8 April 2015
    Ubuntu 15.04 April 2015
    systemd Adop+on

    View full-size slide

  4. Aspects of systemd
    • System and service manager
    • This is what we’ll focus on today
    • So2ware pla6orm for developing other applica9ons
    • We’ll touch on this too
    • “Glue” between the kernel and user applica9ons
    • Some references at the end

    View full-size slide

  5. Unit File Paths
    • /lib/systemd/system
    • For package-installed units
    • /etc/systemd/system
    • For Administrator-configured units
    • /run/systemd/system
    • For non-persistent run9me modifica9ons

    View full-size slide

  6. name.type
    consul.service

    View full-size slide

  7. name.type
    ssh.socket

    View full-size slide

  8. Service Units

    View full-size slide

  9. Service Unit Types
    • Simple (default) - for executables which run without
    daemonising - like Consul.
    • Forking - for executables which daemonise themselves
    • Oneshot - usually short-lived programs which run to comple9on
    and terminate
    • No+fy - for executables which will no9fy systemd when they
    are started and available for work.
    • Consul now supports this - more later!

    View full-size slide

  10. Unit Commands
    • systemctl enable consul.service
    • systemctl start consul.service
    • systemctl stop consul.service
    • systemctl restart consul.service
    • systemctl status consul.service

    View full-size slide

  11. systemctl status consul.service

    View full-size slide

  12. systemctl status consul.service
    Unit Name & Descrip9on

    View full-size slide

  13. systemctl status consul.service
    Unit Name & Descrip9on Enabled Status

    View full-size slide

  14. systemctl status consul.service
    Unit Name & Descrip9on Enabled Status
    Up9me

    View full-size slide

  15. systemctl status consul.service
    Unit Name & Descrip9on Enabled Status
    Up9me
    All processes

    View full-size slide

  16. systemctl status consul.service
    Unit Name & Descrip9on Enabled Status
    Up9me
    All processes
    Last 10 log lines

    View full-size slide

  17. “Drop-in” ConfiguraGon

    View full-size slide

  18. “Drop-in” Configura+on

    View full-size slide

  19. “Drop-in” Configura+on
    Per-Service Drop-In
    Configura9on Directory

    View full-size slide

  20. “Drop-in” Configura+on
    Loaded Drop-in
    Configura9on Files

    View full-size slide

  21. systemd-delta

    View full-size slide

  22. Common Bootstrapping PaGern
    • Install so2ware from a generic package
    • apt-get install consul
    • Install bootstrapping script and drop-in configura9on from an
    environment-specific package
    • apt-get install consul-bootstrap-aws
    • apt-get install consul-bootstrap-azure

    View full-size slide

  23. Working Example

    View full-size slide

  24. Target Units

    View full-size slide

  25. consul-online.target
    network-online.target
    consul.service
    multi-user.target
    consul-online.service
    service-that-depends-on-consul.service

    View full-size slide

  26. Socket Units

    View full-size slide

  27. If a service dies, its listening socket stays
    around, not losing a single message. After
    a restart of the crashed service it can
    continue right where it left off. If a service
    is upgraded we can restart the service
    while keeping around its sockets, thus
    ensuring the service is continously
    responsive. Not a single connection is lost
    during the upgrade.
    —Lennart Poettering

    View full-size slide

  28. If a service dies, its listening socket stays
    around, not losing a single message. After
    a restart of the crashed service it can
    continue right where it left off. If a service
    is upgraded we can restart the service
    while keeping around its sockets, thus
    ensuring the service is continously
    responsive. Not a single connection is lost
    during the upgrade.

    View full-size slide

  29. If a service dies, its listening socket stays
    around, not losing a single message. After
    a restart of the crashed service it can
    continue right where it left off. If a service
    is upgraded we can restart the service
    while keeping around its sockets, thus
    ensuring the service is continously
    responsive. Not a single connection is lost
    during the upgrade.

    View full-size slide

  30. Socket Ac+va+on in Go
    Credit: Vincent Bernat - “IntegraBon of a Go Service with systemd” - 2018

    View full-size slide

  31. Socket Ac+va+on in Go
    Credit: Vincent Bernat - “IntegraBon of a Go Service with systemd” - 2018

    View full-size slide

  32. $ go build 404.go
    $ systemd-socket-activate -l 8000 ./404
    Listening on [::]:8000 as 3
    $ curl '[::1]':8000
    404 page not found
    $ curl '[::1]':8000
    404 page not found

    View full-size slide

  33. Service Unit

    View full-size slide

  34. Graceful Shutdown

    View full-size slide

  35. This talk only scratches the
    surface of the capabiliGes of
    systemd

    View full-size slide

  36. References
    • https://freedesktop.org/wiki/Software/systemd/
    • https://github.com/jen20/hashidays-nyc
    • https://github.com/hashicorp/consul/pull/3164
    • https://vincent.bernat.im/en/blog/2018-
    systemd-golang-socket-activation

    View full-size slide