COMPARISON 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. Comparison of Dinit with other supervision / init systems
  2. =========================================================
  3. This is intended to be an objective description of the differences between Dinit and several
  4. other similar software packages. Due to a myriad of details, it is difficult to provide a very
  5. meaningful comparison without going into great detail (which this document does not). It does,
  6. however, serve as a short survey of service supervision and init systems, and provides a starting
  7. point for understanding the unique features of, and ideas embodied in, the Dinit system.
  8. Tenets of Dinit's design
  9. =-=-=-=-=-=-=-=-=-=-=-=-
  10. Before comparing with other systems, it's important to understand that Dinit is designed with
  11. certain basic principles in mind:
  12. 1. Robustness (including allocation robustness)
  13. Dinit is intended to be able to be used as an "init" process, the special process that runs with
  14. PID 1 and is the first user-space process launched by the kernel (details may vary according to
  15. operating system). An important attribute of an init is that it is robust - that is, it doesn't
  16. crash or otherwise terminate, even in situations where many other programs might. The reason for
  17. this is that a terminating init process may cause the kernel to panic, and crash the whole system.
  18. One situation that Dinit must be able to handle robustly is memory allocation failure, i.e.
  19. running out of memory. Many programs do not handle this gracefully, assuming that allocation will
  20. always succeed, or that immediate termination is a reasonable outcome in the event of allocation
  21. failure. Dinit instead may fail a particular operation, but should never terminate due to
  22. allocation failure.
  23. Exhaustion of resources other than memory (such as file descriptors) needs to be handled
  24. similarly. Various Dinit operations try to pre-allocate resources, where possible, to avoid
  25. getting stuck in a situation where an important operation is only partially completed (for
  26. example: once Dinit starts a service process, it is *always* able to monitor that process). Dinit
  27. maintains a log buffer to avoid losing log messages when the logging daemon is overloaded or not
  28. yet started, but gracefully handles the buffer becoming full, making sure to output a message
  29. indicating that log messages may have been lost, and not outputting partial log lines.
  30. 2. Service Dependencies as the Basis of System Management
  31. Dinit has a straight-forward dependency resolution model: services can depend on other
  32. services, and a service cannot run (or continue running) if its dependencies are not met.
  33. Managing services is the primary business of Dinit, and since everything Dinit does externally
  34. is via a service, dependencies are how system management tasks are configured. Booting, for
  35. example, is configured by having a single "boot" service depend on the various other services that
  36. should be started at boot time. Various early-boot tasks such as checking and mounting the main
  37. filesystem hierarchy can be configured as services, which other "long-lived" services depend on.
  38. There are also soft dependencies ("waits-for" and "depends-ms" in Dinit configuration language)
  39. which do not impose such requirements, but which are useful for for system management ("start XYZ
  40. on boot, but do not fail to boot if XYZ cannot be started").
  41. Dependencies are, with only minor exceptions, the only relationship between services. Services
  42. cannot be configured to conflict with each other, for example; that kind of functionality would
  43. need to be managed externally (if needed at all).
  44. 3. Limited Feature Scope
  45. Dinit aims to provide a basic framework for the most fundamental system management: booting,
  46. starting and stopping services, and shutting down. Everything else, then, is delegated to the
  47. services; other aspects of system management should be handled by external (or at least
  48. separable) packages.
  49. While there should be leeway to add features to Dinit at a later point, the guiding principle is
  50. that it should always be possible to build and run Dinit as a standalone service manager which
  51. includes functionality only for the management of services and for simple system tasks
  52. revolving mainly around service management (basically: boot and shutdown).
  53. Having considered those guiding principles, we'll now take a look at some other service managers,
  54. starting with those that do not perform dependency management.
  55. Systems without dependency management
  56. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  57. A variety of init/supervision packages do not perform proper dependency management
  58. of supervisions. By this I mean that, broadly speaking:
  59. - starting a service should automatically start any services that the former
  60. requires (and wait, if appropriate, until they have started)
  61. - likewise, stopping a service should automatically stop any dependent services.
  62. Dinit (and various other packages) perform dependency management. The following
  63. packages do not:
  64. * Daemontools (http://cr.yp.to/daemontools.html)
  65. * Epoch (http://universe2.us/epoch.html)
  66. * Finit (http://github.com/troglobit/finit)
  67. * Minit (http://www.fefe.de/minit)
  68. * Perp (http://b0llix.net/perp/)
  69. * Runit (http://smarden.org/runit/)
  70. I've read arguments that suggest dependency management isn't really needed: when a service
  71. requires another, the command to start the dependency can be included in the dependent's
  72. startup script; if the dependency goes down, the dependent should presumably fail in some
  73. way and go down itself. Supervision of the service may try to restart it, but should use an
  74. increasing delay to avoid continuously bouncing the service up and down. In my opinion this could
  75. create unnecessary load, unnecessary delay, and noise in logs that might make it more difficult to
  76. pinpoint the cause of problems, though I'll acknowledge that in simpler setups these are unlikely
  77. to be real problems. It may also make it much more difficult to see what will else will start
  78. when some particular service is started (or what will stop when a service is stopped).
  79. Not all services will necessarily behave as is required for this type of service management to
  80. work properly. An argument could be made that this is a fault of the particular service / daemon,
  81. but practical considerations may be in play.
  82. The basic problem of starting login sessions only after system initialisation has (at least
  83. partially) completed is naturally solved with a dependency-managing solution; you can have the tty
  84. sessions (getty) depend on some other service unit which, in turn, depends on the basic system
  85. initialisation services. In non-dependency-handling managers this must usually be special-cased
  86. (eg an "inittab" which is processed once all services have started).
  87. With all the above in mind, I feel that dependency management allows generally greater flexibility
  88. and control in how services are managed. While this might not always be useful, and comes at a
  89. certain cost of complexity, I argue that it is at least sometimes useful, and that the cost is not
  90. so high. However, to be fair, many systems have successfully taken the simpler approach.
  91. Now, we'll look at some systems which *do* have dependency management: Nosh, OpenRC, S6-RC,
  92. Systemd, and some others.
  93. Nosh suite (http://homepage.ntlworld.com/jonathan.deboynepollard/Softwares/nosh.html)
  94. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  95. Another seemingly modular init system offering dependency management and socket activation, with
  96. BSD licensing. Service configuration is expressed through directory structure (symbolic links
  97. represent service dependencies, etc; "start", "stop" and "run" commands are individual scripts
  98. within a service directory bundle). It provides a simple shell-like scripting language which can
  99. be used (via the "nosh" interpreter) to implement service commands without requiring the user of a
  100. full shell. Several "chain loading" utilities are provided to allow running processes in a
  101. different directory, with a different user id, with resource limits, etc.
  102. It was originally designed for BSD systems but works on Linux too (i.e. is portable). It does not
  103. provide a D-Bus interface.
  104. Compared to Dinit, the two most significant differences appear to be use of a directory structure
  105. for service configuration (Dinit uses a combination of directory structure and ini-style
  106. configuration file), and use of small chain loading utilities to implement service parameters
  107. (Dinit has a wider range of direct configuration options via the service description file).
  108. Nosh seems to be a quite mature system with a range of features that makes it
  109. appear competitive, feature-wise, in terms of system/service management, with
  110. Systemd - though without a lot of the feature-creep extras that can easily be
  111. implemented separately.
  112. It is not clear to me whether Nosh is robust to allocation failure.
  113. OpenRC (Gentoo)
  114. -=-=-=-=-=-=-=-
  115. The OpenRC system used in Gentoo Linux is a dependency-managing service supervision
  116. system with functionality that may similar in some respects to Dinit. According to
  117. Wikipedia, it provides parallel startup of services (like Dinit), though this is
  118. disabled by default. It is designed to be used in conjunction with a primary init
  119. which handles system management and which defers to openrc at boot or shutdown to
  120. bring services up or down.
  121. Unusually, OpenRC does not run as a daemon itself; it terminates once it has
  122. established service states. It has some support for integration with service
  123. supervisors such as S6.
  124. Service configuration is specified via a shell script, with the 'openrc-run'
  125. interpreter (which makes certain special shell functions available, and interprets
  126. shell variables once the service script completes. For performance reasons
  127. metatdata extracted from the service scripts is cached in an alternative format.
  128. Although the build system seems to have some support for BSD OSes, it did not
  129. build successfully on OpenBSD when tested (revision 33d3f33).
  130. S6-RC (http://skarnet.org/software/s6-rc/s6-rc.html)
  131. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  132. S6-RC provides a dependency-management system over the top of the S6 supervision
  133. system. S6-RC requires compiling the complete set of service descriptions into a
  134. database. Services are are configured via a directory structure, with a
  135. one-parameter-per-file style, rather than a single service description file.
  136. As well as services, S6-RC has the concept of service "bundles", named groups
  137. of services that can be started/stopped as a group (Dinit also supports this via
  138. "internal" services, which can group other services via dependencies, though with
  139. slight functional differences as a result).
  140. New services cannot be added once the system is in operation, and service
  141. definitions cannot be changed in general, except by re-compiling the database;
  142. S6-RC will then start any new services as required (and stop any processes no longer
  143. considered part of an active service).
  144. S6-RC in general seems to follow the philosophy of breaking up functionality into smaller
  145. parts and implementing these smaller parts as separate programs, wherever
  146. practical. Thus, process supervision, log file management, and service management
  147. are all separate programs.
  148. In contrast to S6-RC, Dinit does not requires compiling service definitions, instead
  149. loading and parsing them on-the-fly. Also, Dinit incorporates service
  150. supervision and management into a single process (and does not require one
  151. supervisory process per service). On the other hand, the Dinit process is
  152. somewhat more complex than any of the individual S6-RC components.
  153. S6-RC nicely manages chaining of service standard input/output, facilitating
  154. setting up a logging chain where a logging process consumes the output of a
  155. service, and either can be restarted while losing only minimal (if any)
  156. output from the logs.
  157. It appears that S6-RC supports only hard dependencies: that is if, a service depends
  158. on another then that service must start, and stay running. Dinit supports a number
  159. of dependency types including "soft" dependencies which allow the dependency to
  160. stop or fail without necessarily stopping the dependent.
  161. It seems likely that S6-RC is resilient to allocation failure.
  162. Systemd
  163. -=-=-=-
  164. Systemd is probably the most widely used init system on Linux as in recent years.
  165. Compared to Dinit, Systemd provides a range of functionality such as:
  166. - setting priority and various other attributes of the service process that
  167. Dinit does not support [yet].
  168. - seat/session management
  169. - syslogd replacement (or at least, partial replacement)
  170. - ability to run tasks at certain times
  171. - inetd replacement (lazily launch services to handle connection to IP ports)
  172. - asynchronous filesystem check/mount
  173. - control group (cgroup) / container management
  174. - private tmp directories for services / login sessions
  175. - system time management
  176. Some of this functionality can be found in other daemons/packages which can be be used
  177. to supplement the functionality of Dinit or another service manager, and even in the
  178. case of Systemd, some of the functionality is not part of the core process (the
  179. actual systemd binary).
  180. In Systemd terminology, it manages "units" of which services are one type. In practice
  181. this is an issue only of nomenclature; Dinit "services" and Systemd "units" are, I think,
  182. essentially the same thing.
  183. Systemd running in "system" mode does not properly support running with a PID other than
  184. one [1]. That is, it must replace /sbin/init. Systemd can however be run in "user" mode
  185. where it (most likely) provides roughly the same level of functionality as Dinit, though
  186. in a more complex package.
  187. The Systemd interdependence graph is more complex than for Dinit and most other
  188. dependency-handling service managers: a service can conflict with another service, meaning
  189. that starting one causes the other to stop and vice versa. Systemd implements shutdown
  190. via a special "shutdown" unit which conflicts with other services so that they stop
  191. when the shutdown is "started". Other service managers typically do not implement shutdown
  192. as a service but as a special action; they then don't need to support conflicting
  193. services.
  194. The "shutdown" unit is just one example of a "special" service. Systemd has several such
  195. services, for various purposes, including for tight integration with D-Bus (Systemd
  196. exposes a D-Bus API, and contains its own implementation of the D-Bus protocol).
  197. Systemd makes no attempt to be portable to operating system kernels other than Linux.
  198. The maintainers have stated that they consider it infeasible to port to non-Linux-based
  199. OSes and will refuse patches designed to do so [2]. Dinit, by comparison, strives to be
  200. portable.
  201. [1] http://freedesktop.org/software/systemd/man/systemd.html as at 18/11/2015
  202. [2] http://freedesktop.org/wiki/Software/systemd/InterfacePortabilityAndStabilityChart/
  203. as at 18/11/2015
  204. Cinit (http://www.nico.schottelius.org/software/cinit; defunct)
  205. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  206. An obscure init system which apparently offers portability and dependency
  207. management, just as Dinit does. Development appears to have ceased some
  208. time ago, unfortunately.
  209. InitNG (http://initng.org/trac; defunct)
  210. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  211. A highly modular init system which apparently offers dependency management
  212. (as Dinit does). Portability status is unclear; may be Linux-only (Dinit
  213. strives for portability). Development may have ceased (website is now showing
  214. Japanese text which I am unable to read) although there are what looks like
  215. maintenance commits from 2017 in the Github repository at
  216. https://github.com/initng/initng.
  217. Upstart (Ubuntu; http://upstart.ubuntu.com)
  218. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  219. Upstart does not provide real dependency management; instead "events" (including services
  220. starting or stopping) can be specified to trigger start/stop of other services. That is,
  221. if service A depends on service B, Upstart is configured so as to start A whenever B starts
  222. (and it's not possible, or at least not trival, to start B without also starting A).
  223. This is backwards from the Dinit approach (and that taken by most dependency-managing supervision
  224. systems) which allow the dependencies of a service to be specified declaratively.
  225. Upstart apparently offers a D-Bus interface. Dinit eschews D-Bus in favour of a simple
  226. custom control protocol.
  227. GNU Shepherd (https://www.gnu.org/software/shepherd/)
  228. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  229. This is the init system / service manager used in Guix. It is written in Guile, an interpreted
  230. language which is most likely not robust to allocation failure.
  231. The service descriptions are also written in Guile, though the API is designed to make it easy
  232. to define services without any programming knowledge.
  233. The documentation for GNU Shepherd is currently somewhat incomplete. It appears to offer full
  234. dependency management however.