(Clean up intro. Recommend .conf method to override unit file. Add tip on using systemd-delta) |
(clean up commands to modern systemctl equivalents) |
||
Line 49: | Line 49: | ||
Activates a service immediately: | Activates a service immediately: | ||
<pre> systemctl start foo | <pre> systemctl start foo </pre> | ||
Deactivates a service immediately: | Deactivates a service immediately: | ||
<pre> systemctl stop foo | <pre> systemctl stop foo </pre> | ||
Restarts a service: | Restarts a service: | ||
<pre> systemctl restart foo | <pre> systemctl restart foo </pre> | ||
Shows status of a service including whether it is running or not: | Shows status of a service including whether it is running or not: | ||
<pre> systemctl status foo | <pre> systemctl status foo </pre> | ||
Enables a service to be started on bootup: | Enables a service to be started on bootup: | ||
<pre> systemctl enable foo | <pre> systemctl enable foo </pre> | ||
Disables a service to not start during bootup: | Disables a service to not start during bootup: | ||
<pre> systemctl disable foo | <pre> systemctl disable foo </pre> | ||
Check whether a service is already enabled or not: | Check whether a service is already enabled or not: | ||
<pre> systemctl is-enabled foo | <pre> systemctl is-enabled foo; echo $? </pre> | ||
0 indicates that it is enabled, and 1 indicates that it is disabled. In Fedora 17, in addition to the return code, "enabled" or "disabled" will be printed to stdout. | 0 indicates that it is enabled, and 1 indicates that it is disabled. In Fedora 17, in addition to the return code, "enabled" or "disabled" will be printed to stdout. | ||
Line 79: | Line 79: | ||
Refer to man systemctl for more details. | Refer to man systemctl for more details. | ||
== How do I change the runlevel? == | == How do I change the target (runlevel) ? == | ||
systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit. | systemd has the concept of targets which is a more flexible replacement for runlevels in sysvinit. | ||
Line 87: | Line 87: | ||
You can switch to 'runlevel 3' by running | You can switch to 'runlevel 3' by running | ||
<pre> systemctl isolate multi-user | <pre> systemctl isolate multi-user.target </pre> | ||
You can switch to 'runlevel 5' by running | You can switch to 'runlevel 5' by running | ||
<pre> systemctl isolate graphical.target | <pre> systemctl isolate graphical.target | ||
== How do I change the default | == How do I change the default target? == | ||
<pre> systemctl | <pre> systemctl set-default <name of target>.target </pre> | ||
graphical.target is the default. You might want multi-user.target for the equivalent of non graphical (runlevel 3) from sysv init. The full list of targets can be accessed via systemctl list-units --type=target | |||
systemd does not use /etc/inittab file. | systemd does not use /etc/inittab file. | ||
== How do I know the current | == How do I know the current target? == | ||
<pre> systemctl get-default </pre> | |||
== How to power off the machine ? == | |||
You can use | You can use | ||
<pre> | |||
poweroff | <pre> poweroff </pre> | ||
</pre> | |||
Some more possibilities are: <code>halt -p</code>, <code>init 0</code>, <code>shutdown -P now</code> | Some more possibilities are: <code>halt -p</code>, <code>init 0</code>, <code>shutdown -P now</code> | ||
Line 138: | Line 123: | ||
(or) | (or) | ||
<pre> systemctl stop NetworkManager | <pre> systemctl stop NetworkManager </pre> | ||
== Does chkconfig command work with systemd? == | == Does chkconfig command work with systemd? == | ||
Line 150: | Line 135: | ||
(or) | (or) | ||
<pre> systemctl disable NetworkManager | <pre> systemctl disable NetworkManager </pre> | ||
chkconfig --list doesn't list systemd services, only Sys V services. The output of chkconfig takes note of this, along with supplying additional information. | chkconfig --list doesn't list systemd services, only Sys V services. The output of chkconfig takes note of this, along with supplying additional information. | ||
Line 237: | Line 222: | ||
{{admon/tip| Don't forget to reload systemd daemon using <code>systemctl daemon-reload</code> and <code> systemctl restart foobar</code> after editing a unit file where foobar is the name of the unit. Also note that you can <code> systemd-delta </code> to list the unit files which have been customized and also the precise differences }} | {{admon/tip| Don't forget to reload systemd daemon using <code>systemctl daemon-reload</code> and <code> systemctl restart foobar</code> after editing a unit file where foobar is the name of the unit. Also note that you can <code> systemd-delta </code> to list the unit files which have been customized and also the precise differences }} | ||
{{admon/note|When modifying an unit that has an symlink pointing to that unit for example like the display-manager.service -> prefdm.service does, the symlink should be copied instead of the actual unit | {{admon/note|When modifying an unit that has an symlink pointing to that unit for example like the display-manager.service -> prefdm.service does, the symlink should be copied instead of the actual unit (ie) display-manager.service should be copied to the /etc/systemd/system directory or a new unit created with .includes that bears that name .}} | ||
== How do I debug systemd issues? == | == How do I debug systemd issues? == |
Revision as of 06:35, 20 January 2014
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
Why systemd?
http://0pointer.de/blog/projects/why.html
systemd documentation
systemd has very comprehensive documentation. Refer to
http://0pointer.de/blog/projects/systemd-docs.html
Tools
systemctl
: used to introspect and control the state of the systemd system and service managersystemd-cgls
: recursively shows the contents of the selected Linux control group hierarchy in a treesystemadm
: a graphical frontend for the systemd system and service manager that allows introspection and control of systemd. Part of the systemd-gtk page. This is a early version and needs more work. Do not use it for now unless you are a developer.
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 systemd.special
page.
it 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.
list all running services etc:
systemctl
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 start/stop or enable/disable services?
Activates a service immediately:
systemctl start foo
Deactivates a service immediately:
systemctl stop foo
Restarts a service:
systemctl restart foo
Shows status of a service including whether it is running or not:
systemctl status foo
Enables a service to be started on bootup:
systemctl enable foo
Disables a service to not start during bootup:
systemctl disable foo
Check whether a service is already enabled or not:
systemctl is-enabled foo; echo $?
0 indicates that it is enabled, and 1 indicates that it is disabled. In Fedora 17, in addition to the return code, "enabled" or "disabled" will be printed to stdout.
Refer to man systemctl for more details.
How do I change the target (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
You can switch to 'runlevel 5' by running
systemctl isolate graphical.target == How do I change the default target? == <pre> systemctl set-default <name of target>.target
graphical.target is the default. You might want multi-user.target for the equivalent of non graphical (runlevel 3) from sysv init. The full list of targets can be accessed via systemctl list-units --type=target
systemd does not use /etc/inittab file.
How do I know the current target?
systemctl get-default
How to power off the machine ?
You can use
poweroff
Some more possibilities are: halt -p
, init 0
, shutdown -P now
Note that halt
used to work the same as poweroff
in previous Fedora releases, but systemd distinguishes between the two, so halt
without parameters now does exactly what it says - it merely stops the system without turning it off.
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
(or)
systemctl stop NetworkManager
Does chkconfig command work with systemd?
Yes, for turning on/off services, 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
(or)
systemctl disable NetworkManager
chkconfig --list doesn't list systemd services, only Sys V services. The output of chkconfig takes note of this, along with supplying additional information.
Does system-config-services work with systemd?
Yes. It does.
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 /etc/systemd/system/getty.target.wants/getty@tty9.service systemctl daemon-reload systemctl start getty@tty9.service
To remove a getty:
Simply remove the getty symlinks you want to get rid of in the getty.target.wants/ directory:
rm /etc/systemd/system/getty.target.wants/getty@tty5.service /etc/systemd/system/getty.target.wants/getty@tty6.service systemctl daemon-reload systemctl stop getty@tty5.service getty@tty6.service
systemd does not use /etc/inittab file.
How do I set automatic login on a virtual console terminal?
First create a new service similar to getty@.service:
# cp /lib/systemd/system/getty@.service \ /etc/systemd/system/autologin@.service # ln -s /etc/systemd/system/autologin@.service \ /etc/systemd/system/getty.target.wants/getty@tty8.service
then edit ExecStart, Restart and Alias values, like this:
... ExecStart=-/sbin/mingetty --autologin USERNAME %I Restart=no ... Alias=getty.target.wants/getty@tty8.service
and finally reload daemon and start the service:
systemctl daemon-reload systemctl start getty@tty8.service
Note that if you exit tty8 session, you wont be able to use it until next reboot or manual start by systemctl, except if you leave Restart as ‘always’, but I highly recommend to avoid this according to security reasons.
How do I customize a unit file/ add a custom unit file?
The best way to customize unit files is to add /etc/systemd/system/foobar.service.d/*.conf where foobar.service is the name of the service you want to customize. If a directory doesn't already exist, create one and drop a conf file with the settings you want to override. For example,
/etc/systemd/system/httpd.service/restart.conf
[Service] Restart=always RestartSec=30
Refer to man systemd.unit page for more details.
Alternatively, you can copy the distribution provided unit file from /lib/systemd/system to /etc/systemd/system since the latter has higher precedence. If a line starts with .include
followed by a file name, the specified file will be parsed at this point. Make sure that the file that is included has the appropiate section headers before any directives.You should use .include
statement instead of copying the whole unit file from /lib/systemd/system to /etc/systemd/system if possible. This will enable to update the unchanged directives correctly during future package updates.
Be careful when using .include
together with directives that can be defined multiple times (like EnvironmentFile=
), since we can only add new directives, but we can't remove already defined ones. We have to copy the whole file from /lib/systemd/system to /etc/systemd/system in this case.
Let's say we use a lighttpd server and we want to lower its niceness value. All we need to do is to add Nice=-5
to the lighttpd.service file. We can do this by either copying the whole file from /lib/systemd/system/lighttpd.service to /etc/systemd/system/lighttpd.service or creating the following file in /etc/systemd/system/lighttpd.service:
.include /lib/systemd/system/lighttpd.service [Service] Nice=-5
How do I debug systemd issues?
Refer to How_to_debug_Systemd_problems
Readahead
systemd has a built-in readahead implementation which is not enabled on upgrades. It should improve bootup speed but your mileage may vary depending on your hardware. To enable it:
systemctl enable systemd-readahead-collect.service systemctl enable systemd-readahead-replay.service
Warnings on separate /usr partition
Refer to http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken and http://cgit.freedesktop.org/systemd/tree/README for details.
Man pages
systemd comes with extensive documentation including several man pages. The web version is at
http://www.freedesktop.org/software/systemd/man/
References
- http://0pointer.de/blog/projects/ - Lennart's blog has lots of information about systemd. Lennart is the primary systemd developer
- http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions
- http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks
- Features Fedora 15:systemd
- Project homepage
- Interview with the developer
- cgroups