|Line 189:||Line 189:|
Refer to [[How_to_debug_Systemd_problems]]
Refer to [[How_to_debug_Systemd_problems]]
= References =
= References =
Revision as of 08:12, 4 March 2011
systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux cgroups, supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for sysvinit. For more information, watch the video at http://linuxconfau.blip.tv/file/4696791/ or http://www.youtube.com/watch?v=TyMLi8QF6sw
systemd starts up and supervises the entire system and is based around the notion of units composed of a name and a type and matching a configuration file with the same name and type (e.g. a unit avahi.service has a configuration file with the same name and is a unit encapsulating the Avahi daemon). There are seven different types of units:
service: these are the most obvious kind of unit: daemons that can be started, stopped, restarted, reloaded.
socket: this unit encapsulates a socket in the file-system or on the Internet. systemd currently support AF_INET, AF_INET6, AF_UNIX sockets of the types stream, datagram, and sequential packet. It can also support classic FIFOs as transport. Each socket unit has a matching service unit, that is started if the first connection comes in on the socket or FIFO (e.g. nscd.socket starts nscd.service on an incoming connection).
device: this unit encapsulates a device in the Linux device tree. If a device is marked for this via udev rules, it will be exposed as a device unit in systemd. Properties set with udev can be used as configuration source to set dependencies for device units.
mount: this unit encapsulates a mount point in the file system hierarchy.
automount: this unit type encapsulates an automount point in the file system hierarchy. Each automount unit has a matching mount unit, which is started (i.e. mounted) as soon as the automount directory is accessed.
- target: this unit type is used for logical grouping of units: instead of actually doing anything by itself it simply references other units, which thereby can be controlled together. (e.g. multi-user.target, which is a target that basically plays the role of run-level 5 on classic SysV system; or bluetooth.target which is requested as soon as a bluetooth dongle becomes available and which simply pulls in bluetooth related services that otherwise would not need to be started: bluetoothd and obexd and suchlike).
snapshot: similar to target units snapshots do not actually do anything themselves and their only purpose is to reference other units.
systemd provides the following:
- aggressive parallelization capabilities using socket: To speed up the entire boot and start more processes in parallel, systemd creates the listening sockets before actually starting the daemon, and then just passes the socket to it. All sockets for all daemons are created in one step in the init system, and then in a second step run all daemons at once. If a service needs another, and it is not fully started up, what will happen is that the connection is queued in the providing service and the client will potentially block on that single request. But only that one client will block and only on that one request. Also, dependencies between services no longer have to be configured to allow proper parallelized start-up: starting all sockets at once and a service needing another, it surely can connect to its socket.
- D-Bus activation for starting services: Using bus activation, a service can be started the first time it is accessed. Bus activation also gives the minimal per-request synchronisation needed for starting up the providers and the consumers of D-Bus services at the same time: starting a service at the same time as another, if one is quicker, than via the bus activation logic the D-Bus queues the request until the other manages to establish its service name.
- offers on-demand starting of daemons
- keeps track of processes using Linux cgroups: Every executed process gets its own cgroup and it is very easy to configure systemd to place services in cgroups that have been configured externally, for example via the libcgroups utilities.
- supports snapshotting and restoring of the system state: Snapshots can be used to save/rollback the state of all services and units of the init system. Primarily it has two intended use cases: to allow the user to temporarily enter a specific state such as "Emergency Shell", terminating current services, and provide an easy way to return to the state before, pulling up all services again that got temporarily pulled down.
- maintains mount and automount points: Systemd monitors all mount points how they come and go, and can also be used to mount or unmount mount-points. /etc/fstab can be used here as an additional configuration source for these mount points. Using the
comment=fstab option you can even mark
/etc/fstabentries to become systemd controlled automount points..
- implements an elaborate transactional dependency-based service control logic: Systemd supports several kinds of dependencies between services (or units), using After/Before, Requires and Wants options in the unit configuration files to fix the ordering how units are activated. Requires and Wants, express a positive requirement dependency, either mandatory, or optional. There is Conflicts which expresses a negative requirement dependency, and others less used. As a transactional control, if a unit is requested to start up or shut down, systemd will add it and all its dependencies to a temporary transaction, verifing if the transaction is consistent (or the ordering via After/Before of all units is cycle-free). If it is not, systemd will try to fix it up, and removes non-essential jobs from the transaction that might remove the loop.
- For each process spawned, it controls: The environment, resource limits, working and root directory, umask, OOM killer adjustment, nice level, IO class and priority, CPU policy and priority, CPU affinity, timer slack, user id, group id, supplementary group ids, readable/writable/inaccessible directories, shared/private/slave mount flags, capabilities/bounding set, secure bits, CPU scheduler reset of fork, private /tmp name-space, cgroup control for various subsystems. Also, you can easily connect
stdin/stdout/stderrof services to
/dev/kmsg, arbitrary TTYs. If connected to a TTY for input systemd will make sure a process gets exclusive access, optionally waiting or enforcing it.
- The native configuration files use a syntax that closely follows the well-known
.desktopfiles: It is a simple syntax for which parsers exist already in many software frameworks. Also, this allows to rely on existing tools for i18n for service descriptions, and similar, without for admins the need to learn a new syntax.
(... and more advanced)
- Compatibility with SysV init scripts: It takes advantages of LSB and Red Hat chkconfig headers if they are available, if not, it uses otherwise available information, such as the start priorities in /etc/rc.d. These init scripts are simply considered a different source of configuration, easing the upgrade path to proper systemd services.
- /etc/fstab configuration file: it just another source of configuration. Using the comment= fstab option it is possible to mark /etc/fstab entries to become systemd controlled automount points.
- Support a simple templating/instance mechanism: For example, instead of having six configuration files for six gettys, it has only one getty@.service file which gets instantiated to firstname.lastname@example.org and suchlike. The interface part can even be inherited by dependency expressions, i.e. it is easy to encode that a service email@example.com pulls in firstname.lastname@example.org, while leaving the eth0 string wild-carded.
- Compatibility, to a certain extent, with
/dev/initctl. This compatibility is in fact implemented with a FIFO-activated service, which simply translates these legacy requests to D-Bus requests. Effectively this means the old shutdown, poweroff and similar commands from Upstart and sysvinit continue to work with systemd.
- Compatibility with
wtmp(To an extent that is far more than healthy, given how crufty
For all details view A short list of other features on the developer blog.
systemctl: used to introspect and control the state of the systemd system and service manager
systemd-cgls: recursively shows the contents of the selected Linux control group hierarchy in a tree
systemadm: a graphical frontend for the systemd system and service manager that allows introspection and control of systemd
View the man pages for more details.
Boot Kernel Command Line
On boot systemd activates (by default), the target unit default.target whose job is to activate services and other units by pulling them in via dependencies.
To override the unit to activate, systemd parses its own kernel command line arguments via the
systemd.unit= command line option. This may be used to temporarily boot into a different boot unit. The classical run-levels are replaced as following:
systemd.unit=rescue.target is a special target unit for setting up the base system and a rescue shell (similar to run level 1);
systemd.unit=emergency.target, is very similar to passing
init=/bin/sh but with the option to boot the full system from there;
systemd.unit=multi-user.target for setting up a non-graphical multi-user system;
systemd.unit=graphical.target for setting up a graphical login screen.
For details about these special systemd boot units, view the man
What is the status of systemd in Fedora?
Fedora 14 featured it is a technology preview. It is the default in Fedora 15 and has replaced Upstart.
Has all legacy System V init files been converted to systemd service files or equivalent?
Many of the core services have been converted but not all of them yet. The transition will happen over several releases. systemd is fully compatible with the legacy init scripts
What is the tool to manage services with systemd?
systemctl is the primary tool to use. It combines the functionality of both service and chkconfig into a single tool that you can use for instance to enable/disable services permanently or only for the current session.
systemctl - list all running services etc
systemctl disable foo.service - Disables a service to not start during bootup systemctl enable foo.serice - Enables a service to be started on bootup
systemctl start foo.service - Activates a service immediately systemctl stop foo.service - Deactivates a service immediately systemctl restart foo.service - Restarts a service systemctl status foo.service - Shows status of a service including whether it is running or not
Refer to man systemctl for more details. systemd-cgls lists the running process in a tree format. It can recursively show the content of any given control group. Refer to man systemd-cgls for more details.
How do I change the runlevel?
systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit.
Run level 3 is emulated by multi-user.target. Run level 5 is emulated by graphical.target. runlevel3.target is a symbolic link to multi-user.target and runlevel5.target is a symbolic link to graphical.target.
You can switch to 'runlevel 3' by running
systemctl isolate multi-user.target (or) systemctl isolate runlevel3.target
You can switch to 'runlevel 5' by running
systemctl isolate graphical.target (or) systemctl isolate runlevel5.target
How do I change the default runlevel?
systemd uses symlinks to point to the default runlevel. You have to delete the existing symlink first before creating a new one
Switch to runlevel 3 by default
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
Switch to runlevel 5 by default
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
systemd does not use /etc/inittab file.
How do I know the current run level?
runlevel command still works with systemd. You can continue using that however runlevels is a legacy concept in systemd and is emulated via 'targets' and multiple targets can be active at the same time. So the equivalent in systemd terms is
systemctl list-units --type=target
Does service command work with systemd?
Yes. It has been modified to call systemctl automatically when dealing with systemd service files. So either of the following commands does the same thing
service NetworkManager stop
systemctl stop NetworkManager.service
Does chkconfig command work with systemd?
Yes. Compatibility has been provided both ways. chkconfig has been modified to call systemctl when dealing with systemd service files. Also systemctl automatically calls chkconfig when dealing with a traditional sysv init file.
So either of the following commands does the same thing
chkconfig NetworkManager off
systemctl disable NetworkManager.service
Does system-config-services work with systemd?
system-config-services does not understand systemd service files yet. It needs to be updated or replaced
How do I change the number of gettys running by default?
To add another getty:
Simply place another symlink for instantiating another getty in the getty.target.wants/ directory:
ln -sf /lib/systemd/system/getty@.service /email@example.com systemctl daemon-reload systemctl start firstname.lastname@example.org
To remove a getty:
Simply remove the getty symlinks you want to get rid of in the getty.target.wants/ directory:
rm /email@example.com /firstname.lastname@example.org systemctl daemon-reload systemctl stop email@example.com firstname.lastname@example.org
systemd does not use /etc/inittab file.
How do I debug systemd issues?
Refer to How_to_debug_Systemd_problems