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

Init: then and now

Init: then and now

A story of starting systems up

Pierre-Yves Ritschard

November 07, 2017
Tweet

More Decks by Pierre-Yves Ritschard

Other Decks in Programming

Transcript

  1. Grüß Gott Pierre-Yves Ritschard CTO & Co-founder at Unix since

    96 Open-Source developer at OpenBSD, Riemann, Collectd, and more @pyr Exoscale 2 . 1
  2. Exoscale Infrastructure as a service Part of A1 Digital Zones

    in Frankfurt, Vienna, Zürich, Geneva 3 . 1
  3. The rmware Exposes BUS access Rudimentary way to communicate list

    devices Looks for a bootloader in on devices Usually very basic environment (sometimes 16- bit) 7 . 1
  4. The kernel Discovers devices on Buses Prepares environment to run

    process(es) using a common format Exposes standard facilities for programs: Abstracted I/O: open(2) Memory management: mmap(2), malloc(3) Process handling: fork(2), signal(2) Network abstractions: socket(2), bind(2), connect(2) 13 . 1
  5. Init First process started by the kernel Runs boot sequence

    Mounts lesystems Starts the network Starts essential subsystems: syslog, ntpd, cron Starts background daemons: ssh, smtpd Root of process tree 15 . 1
  6. A small detour: the process tree There is a process

    hierarchy in Unix The kernel runs only one user process 20 . 1
  7. Init simpli ed How would you? Mount lesystems Start the

    network Start essential subsystems: syslog, ntpd, cron Start background daemons: ssh, smtpd 26 . 1
  8. Standard Init swapon -a umount -a >/dev/null 2>&1 mount -a

    -t nonfs . /etc/rc.conf sh /etc/netstart if [ X${rwhod} = X"YES" ]; then echo -n ' rwhod'; rwhod fi if [ X${lpd} = X"YES" ]; then echo -n ' printer'; lpd fi . /etc/rc.local 27 . 1
  9. Are we there? How does the system stop? How do

    I restart or stop services? 30 . 1
  10. This isn't ideal It's hard to keep track of startup

    order Plenty of services didn't react well to standard signals No way to easily gather service status No way to ensure a critical service stays up This puts a lot on application packagers Especially on non-standardized systems Hello ! 33 . 1
  11. Case in point: daemons int daemon(void) { switch (fork()) {

    case -1: return (-1); case 0: break; default: _exit(0); } if (setsid() == -1) return (-1); (void)chdir("/"); (void)close(STDIN_FILENO); (void)close(STDOUT_FILENO); (void)close(STDERR_FILENO); return (0); } 34 . 1
  12. Case in point: daemons How do I know the child's

    PID? How do I keep track of service availability 35 . 1
  13. System V You all know it /etc/init.d/rc5.d/S99blargh Introduces runlevels Enforces

    the concept of service startup, status, and shutdown. inittab(5) to de ne runlevels as state transitions Still leaves much to be desired 40 . 1
  14. Ubuntu Upstart Simple DSL Event based start on (net-device-up and

    local- filesystems) Support for environment, logging, and PID tracking 41 . 1
  15. Ubuntu Upstart description "Warp agent" start on runlevel [2345] stop

    on runlevel [!2345] respawn respawn limit 5 60 limit nofile 8192 8192 pre-start script [ -x "/usr/sbin/warp-agent" ] || exit 0 [ -r "/etc/warp/agent.json" ] || exit 0 end script exec /usr/sbin/warp-agent /etc/warp/agent.json 42 . 1
  16. Ubuntu Upstart Drawbacks Very brittle job supervision Left the process

    in un xable states on a regular basis 44 . 1
  17. SystemD DSL based Builds a dependency graph Support for environment,

    logging, PID tracking Opt-in support for resource constraints, rewalling 45 . 1
  18. SystemD drawbacks Hard to avoid heated discussions Wide scope means

    more room for error Mixed focus on desktop & servers can be off-puting for admins Heavily coupled to DBUS That giant, little-known attack vector on your system 48 . 1
  19. Shepperd (define nginx (make <service> #:provides '(nginx web-server) #:start (make-forkexec-constructor

    (list "nginx")) #:stop (make-kill-destructor))) (register-services nginx) 49 . 1