DeveloperWiki:Systemd

This page is for planning.

Packaging notes

Units

  • Use the upstream unit files whenever they exist
  • Try not to do anything Arch-specific. This will maximize chances of not having to change behavior in the future once the unit files are provided by upstream. In particular avoid EnvironmentFile=, especially if it points to the Arch-specific /etc/conf.d
  • Always separate initialization behavior from the actual daemon behavior. If necessary, use a separate unit for the initialization, blocked on a ConditionFoo from systemd.unit(5). An example of this is sshd.service and sshdgenkeys.service.

Not using an EnvironmentFile= is OK if:

  • Either the daemon has its own configuration file where the same settings can be specified
  • The default service file "just works" in the most common case. Users who want to change the behavior should then override the default service file. If it is not possible to provide a sane default service file, it should be discussed on a case-by-case basis

A few comments about service files, assuming current behavior should be roughly preserved, and fancy behavior avoided:

  • If your service requires the network to be configured before it starts, use After=network.target. Do not use Wants=network.target or Requires=network.target
  • Use Type=forking, unless you know it is not necessary
    • Many daemons use the exit of the first process to signal that they are ready, so to minimize problems, it is safest to use this mode
    • To make sure that systemd is able to figure out which process is the main process, tell the daemon to write a pidfile and point systemd to it using PIDFile=
    • If the daemon in question is dbus-activated, socket-activated, or specifically supports Type=notify, that is a different matter, but currently only the case for a minority of daemons
  • Arch's rc scripts do not support dependencies, but with systemd they should be added add where necessary
    • The most typical case is that requires the service to be running before is started. In that case add and to .
    • If the dependency is optional then add Wants=B and instead
    • Dependencies are typically placed on services and not on targets

If you want to get fancy, you should know what you are doing.

Example of a simple conversion

rc script
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting NIS Server"
    /usr/sbin/ypserv
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon ypserv
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping NIS Server"
    killall -q /usr/sbin/ypserv
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon ypserv
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start

tmpfiles.d

  • Instead of creating necessary runtime directories and files when a service is started (as some rc scripts do), ship a config file in .
  • A pacman hook included in systemd will run upon install to ensure the necessary runtime files are created right away, not just on the next boot

modules-load.d

  • Instead of loading necessary modules when a service is started (as some rc scripts do), ship a config file in .
  • Add lines to post_install (and post_upgrade if needed) to ensure the necessary modules are loaded on install, not just on the next boot

sysctl.d

  • IMO(dreisner): This should generally be avoided, as tying low level kernel behavior to a package might be considered evil.
gollark: Planck units don't imply quantized things.
gollark: What?
gollark: That's silly, QM only gives you a probability distribution IIRC.
gollark: This is only 16GB of memory, which you can get on a reasonable workstation now.
gollark: * 2^34, even better
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.