systemd

From Gentoo Linux Wiki
Jump to: navigation, search
spacer
Gentoo has an official article on:
Systemd


From systemd's website:

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.

Contents

  • 1 Installation
    • 1.1 Kernel
    • 1.2 Userland
    • 1.3 Finalizing w/ grub
    • 1.4 Finalizing w/ grub 2
  • 2 Services
    • 2.1 Hardware related
      • 2.1.1 LVM
      • 2.1.2 microcode_ctl
      • 2.1.3 radeon-power_profile
      • 2.1.4 ALSA
    • 2.2 Network
      • 2.2.1 Static network
      • 2.2.2 DHCPCD
      • 2.2.3 wpa_supplicant
      • 2.2.4 network manager
      • 2.2.5 wicd
      • 2.2.6 dnsmasq
      • 2.2.7 munge
    • 2.3 Core services
      • 2.3.1 dcron
      • 2.3.2 fcron
      • 2.3.3 hwclock
      • 2.3.4 loadkeys
      • 2.3.5 metalog
      • 2.3.6 ntp-client
    • 2.4 Display managers
      • 2.4.1 KDM
      • 2.4.2 XDM/GDM
      • 2.4.3 startx
    • 2.5 Daemons and servers
      • 2.5.1 Samba
      • 2.5.2 NMBD
      • 2.5.3 CUPS
      • 2.5.4 distccd
      • 2.5.5 lighttpd
      • 2.5.6 MySQL
      • 2.5.7 PostgreSQL
      • 2.5.8 NFS
      • 2.5.9 ntpd
      • 2.5.10 Postfix
      • 2.5.11 sshd
      • 2.5.12 sshd.socket (socket-activated sshd)
      • 2.5.13 Verynice
      • 2.5.14 Openvpn
      • 2.5.15 nginx
      • 2.5.16 php-fpm
      • 2.5.17 renderd
    • 2.6 Misc
      • 2.6.1 iptables
      • 2.6.2 kexec_load
      • 2.6.3 rtorrent (in screen)
      • 2.6.4 Mediatomb
      • 2.6.5 gpm
  • 3 Troubleshooting
    • 3.1 OpenRC Compatibility
    • 3.2 Removing OpenRC
    • 3.3 PAM support: su, sudo, screen...
  • 4 See also

[edit] Installation

[edit] Kernel

The Gentoo ebuild for systemd requires at least 2.6.38 kernel. Although it is higher than what upstream requires, we already had trouble running systemd on 2.6.37.

systemd requires some non-standard kernel options to be enabled:

Linux Kernel Configuration: systemd options
General setup  --->
     [*] Control Group support
Device Drivers --->/
     Generic Driver Options  --->
          [*] Maintain a devtmpfs filesystem to mount at /dev
File systems --->
     [*] Filesystem wide access notification
     < > Kernel automounter support
     <*> Kernel automounter version 4 support (also supports v3)

(Re)build and (Re)install.

[edit] Userland

Many packages support systemd by default and are already available in the official portage tree but are (obviously) not stable yet.

Keyword required for installing systemd:

File: /etc/portage/package.keywords
sys-apps/systemd
sys-apps/dbus
sys-fs/udev
sys-kernel/linux-headers
>=sys-apps/kmod-5

Optional: if you want GTK support, then add these packages too:

File: /etc/portage/package.keywords
dev-libs/atk
dev-libs/glib
dev-lang/vala
x11-libs/gtk+:2

For desktops you can also add the following few systemd-ready packages:

File: /etc/portage/package.keywords
net-dns/avahi
net-misc/networkmanager
net-wireless/bluez
net-wireless/wpa_supplicant
sys-auth/consolekit

Install systemd and related packages:

emerge --ask --verbose systemd

[edit] Finalizing w/ grub

By default systemd will start your system to allow you to login in on a tty. This means no display manager gets started, no network is set up, etc. Make sure to enable the necessary services before you reboot.

Finally you will need to tell your kernel to run the init provided by systemd. If you have a kernel built by genkernel, change the real_init kernel parameter to point to /usr/bin/systemd:

File: /boot/grub/grub.conf
...
title=My Gentoo Linux
root (hd0,0)
kernel /my-genkernel... root=/dev/hda3 real_init=/usr/bin/systemd
initrd /initramfs-genkernel-x86-2.6.32-gentoo-r7

If you have built your kernel yourself, change the init kernel parameter to point to /usr/bin/systemd:

File: /boot/grub/grub.conf
title=My Gentoo Linux
root (hd0,0)
kernel /vmlinuz.bin root=/dev/hda3 init=/usr/bin/systemd
...
Note: If you're using Initramfs the systemd start is set inside of initramfs file, not in grub/lilo config

[edit] Finalizing w/ grub 2

/etc/default/grub file gedited to have this line look like this....

GRUB_CMDLINE_LINUX_DEFAULT="init=/usr/bin/systemd quiet"

[edit] Services

To list available services, run:

systemctl

To enable services (similar to what rc-update -a does):

systemctl enable foobar.service

A further list of unit files is available from git.overlays.gentoo.org/gitweb/?p=user/systemd.git;a=tree;f=sys-apps/systemd-units/files or from cgit.freedesktop.org/systemd/systemd/tree/units

You can find a list of some packages and their openrc and systemd services in the Gentoo Wiki

[edit] Hardware related

[edit] LVM

File: /etc/systemd/system/lvm.service
[Unit]
Description=Linux Volume Manager
DefaultDependencies=no
Requires=udev-settle.service
After=udev-settle.service
Before=shutdown.target local-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/pvscan --ignorelockingfailure
ExecStart=/sbin/vgscan --mknodes --ignorelockingfailure
ExecStart=/sbin/vgchange --sysinit -a ly
ExecStop=/sbin/lvchange --sysinit -a ln $(/sbin/vgs -o vg_name --noheadings --nosuffix 2> /dev/null)
ExecStop=/sbin/lvchange --sysinit -a ln
ExecStop=/sbin/vgchange --sysinit -a ln

[Install]
WantedBy=sysinit.target
systemctl enable lvm.service

[edit] microcode_ctl

File: /etc/systemd/system/microcode_ctl.service
[Unit]
Description=CPU microcode updater

[Service]
Type=oneshot
ExecStart=/usr/sbin/microcode_ctl -qu -f /lib/firmware/microcode.dat

[Install]
WantedBy=multi-user.target
systemctl enable microcode_ctl.service

[edit] radeon-power_profile

File: /etc/systemd/system/radeon-power_profile.service
[Unit]
Description=Radeon Power Profile

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/radeon-power_profile low

[Install]
WantedBy=multi-user.target
File: /usr/local/sbin/radeon-power_profile
#!/bin/sh

EXEC_NAME=`basename $0`;

TARGET="/sys/class/drm/card0/device/power_profile"
CURRENT_PROFILE=`cat ${TARGET}`

append_profile() {
        local PROFILE=$1
        echo -n "  ${PROFILE}"
        if [ "x${CURRENT_PROFILE}x" == "x${PROFILE}x" ]; then
                echo -n " (current)"
        fi
        echo
}

if [ $# != 1 ]; then
        echo "usage: ${EXEC_NAME} <profile>"
        echo
        echo "Valid profiles:"
        for AVAILABLE_PROFILE in low high default auto; do
                append_profile ${AVAILABLE_PROFILE}
        done
        exit 0
fi

PROFILE="$1"

if [ "x${PROFILE}x" == "xlowx" ] || [ "x${PROFILE}x" == "xhighx" ] || [ "x${PROFILE}x" == "xautox" ] || [ "x${PROFILE}x" == "xdefaultx" ]; then
        echo "${PROFILE}" > ${TARGET}
else
        logger "[${EXEC_NAME}] WARN: Invalid power_profile '${PROFILE}'"
        exit 1
fi

exit 0
systemctl enable radeon-power_profile.service

[edit] ALSA

alsa-utils already provides systemd service files. They are enabled automatically when installed.

[edit] Network

[edit] Static network

File: /etc/systemd/system/network.service
[Unit]
Description=Network Connectivity

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/ifconfig eth0 192.168.1.2 mtu 1496
ExecStart=/sbin/route add default gw 192.168.1.1
ExecStop=/sbin/ifconfig eth0 down

[Install]
WantedBy=network.target
systemctl enable network.service
Note: As a comfortable alternative you can alternatively use dhcpcd to assign static configurations:
File: /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
systemctl enable dhcpcd.service

[edit] DHCPCD

As of 5.2.12-r1, dhcpcd ebuild installs dhcpcd.service unit file.

[edit] wpa_supplicant

As of 0.7.3-r3, wpa_supplicant ebuild provides two systemd units:

  • wpa_supplicant.service for NetworkManager users (using D-Bus),
  • wpa_supplicant@.service for plain wpa_supplicant users.

The latter one should be enabled as wpa_supplicant@wlan0.service, where wlan0 shall be replaced by your wireless interface.


[edit] network manager

fix me please =(

[edit] wicd

File: /etc/systemd/system/wicd.service
[Unit]
Description=Wicd Network Manager

[Service]
Type=dbus
BusName=org.wicd.daemon
ExecStart=/usr/sbin/wicd -f

[Install]
WantedBy=network.target
systemctl enable wicd.service

[edit] dnsmasq

File: /etc/systemd/system/dnsmasq.service
[Unit]
Description=dnsmasq service
After=network.target

[Service]
ExecStartPre=/usr/sbin/dnsmasq --test
ExecStart=/usr/sbin/dnsmasq -d -u dnsmasq -g dnsmasq
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[edit] munge

See code.google.com/p/munge/issues/detail?id=11

File: /etc/systemd/system/munged.service
[Unit]
Description=Start/Stop the MUNGE authentication service.
After=syslog.target auditd.service 

[Service]
Type=forking
User=munge
# Start up will fail if /etc/munge/munge.key does not exist
# A fresh key can be generated with /usr/sbin/create-munge-key
ExecStartPre=/usr/bin/test -r /etc/munge/munge.key
ExecStart=/usr/sbin/munged 
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/var/run/munge/munged.pid

[Install]
WantedBy=multi-user.target

[edit] Core services

[edit] dcron

File: /etc/systemd/system/dcron.service
[Unit]
Description=dcron

[Service]
ExecStart=/usr/sbin/crond
Type=forking

[Install]
WantedBy=multi-user.target

[edit] fcron

File: /etc/systemd/system/fcron.service
[Unit]
Description=fcron service

[Service]
ExecStart=/usr/sbin/fcron -f -y

[Install]
WantedBy=multi-user.target

[edit] hwclock

File: /etc/systemd/system/hwclock.service
[Unit]
Description=hwclock

[Service]
Type=oneshot
ExecStart=/sbin/hwclock --hctosys --localtime
ExecStop=/sbin/hwclock --systohc --localtime

[Install]
WantedBy=multi-user.target
systemctl enable hwclock.service

[edit] loadkeys

File: /etc/systemd/system/loadkeys.service
[Unit]
Description=Loads keymap in console (dvorak in example)
DefaultDependencies=no
Before=sysinit.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/loadkeys -q /usr/share/keymaps/i386/dvorak/dvorak.map.gz

[Install]
WantedBy=multi-user.target
systemctl enable loadkeys.service


[edit] metalog

File: /etc/systemd/system/metalog.service
[Unit]
Description=System Logger Daemon

[Service]
ExecStart=/usr/sbin/metalog
File: /etc/systemd/system/metalog.socket
[Unit]
Description=Syslog Socket

[Socket]
ListenDatagram=/dev/log

[Install]
WantedBy=sockets.target
systemctl enable metalog.socket

[edit] ntp-client

File: /etc/systemd/system/ntp-client.service
[Unit]
Description=NTP client
After=hwclock.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/ntpdate -s -b -u 0.gentoo.pool.ntp.org 1.gentoo.pool.ntp.org 2.gentoo.pool.ntp.org 3.gentoo.pool.ntp.org

[Install]
WantedBy=multi-user.target
systemctl enable ntp-client.service

[edit] Display managers

[edit] KDM

File: /etc/systemd/system/kdm@.service
[Unit]
Description=K Display Manager on %I
Requires=dev-%i.device
After=dev-%i.device

[Service]
ExecStart=/usr/bin/kdm -nodaemon %I
StandardOutput=syslog

[Install]
Alias=graphical.target.wants/kdm@tty7.service
systemctl enable kdm@tty7.service

Starting with systemd-187, the file contents have changed.

File: /etc/systemd/system/kdm.service
[Unit]
Description=KDM Display Manager
Conflicts=getty@tty1.service
After=systemd-user-sessions.service getty@tty1.service plymouth-quit.service

[Service]
ExecStart=/usr/bin/kdm -nodaemon
Restart=always
IgnoreSIGPIPE=no

[Install]
Alias=display-manager.service
systemctl enable kdm.service

[edit] XDM/GDM

File: /etc/systemd/system/xdm.service
[Unit]
Description=X-Window Display Manager
After=systemd-user-sessions.service

[Service]
ExecStart=/usr/bin/xdm -nodaemon

[Install]
Alias=display-manager.service
systemctl enable xdm.service

(or quite possibly just 'systemctl enable xdm.service' as there is already a xdm.service file located @ /usr/lib64/systemd/system/xdm.service)

[edit] startx

File: /etc/systemd/system/startx.service
[Unit]
Description=Startx

[Service]
#User=bob #uncomment this to run startx as desired user (in example bob), otherwise it will run startx as root
ExecStart=/usr/bin/startx

[Install]
WantedBy=graphical.target

[edit] Daemons and servers

[edit] Samba

File: /etc/systemd/system/samba.service
[Unit]
Description=Samba server
After=syslog.target
After=network.target

[Service]
Group=samba

ExecStart=/usr/sbin/smbd --pid-file=/var/run/samba/smbd.pid
ExecStop=/bin/kill -15 $MAINPID
PIDFile=/var/run/samba/smbd.pid

Restart=always

[Install]
WantedBy=multi-user.target

[edit] NMBD

File: /etc/systemd/system/nmbd.service
[Unit]
Description=NMBD server
After=syslog.target
After=network.target

[Service]
Group=samba

ExecStart=/usr/sbin/smbd --pid-file=/var/run/samba/nmbd.pid
ExecStop=/bin/kill -15 $MAINPID
PIDFile=/var/run/samba/nmbd.pid

Restart=always

[Install]
WantedBy=multi-user.target

[edit] CUPS

Starting with cups 1.5.2-r20 the necessary socket, path and service files are provided by the ebuild.

[edit] distccd

File: /etc/systemd/system/distccd.service
[Unit]
Description=distcc

[Service]
ExecStart=/usr/bin/distccd --user distcc --daemon --no-detach --port 3632 --log-level info --allow 192.168.1.0/24 --listen 192.168.1.111 -N 15 

[Install]
WantedBy=multi-user.target

[edit] lighttpd

File: /etc/systemd/system/lighttpd.service
[Unit]
Description=Lighttpd Daemon
After=network.target

[Service]
ExecStartPre=/usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf
ExecStart=/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
File: /etc/tmpfiles.d/lighttpd.conf
d /var/run/lighttpd 0750 lighttpd lighttpd -
systemctl enable lighttpd.service

[edit] MySQL

File: /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL database server
After=syslog.target
After=network.target

[Service]
User=mysql
Group=mysql

ExecStart=/usr/sbin/mysqld --pid-file=/var/run/mysqld/mysqld.pid
ExecStop=/bin/kill -15 $MAINPID
PIDFile=/var/run/mysqld/mysqld.pid

# We rely on systemd, not mysqld_safe, to restart mysqld if it dies
Restart=always

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target
File: /etc/tmpfiles.d/mysqld.conf
# systemd tmpfile settings for mysql
# See tmpfiles.d(5) for details

d /var/run/mysqld 0755 mysql mysql -
systemctl enable mysqld.service

[edit] PostgreSQL

This starts PostgreSQL.

File: /etc/tmpfiles.d/postgresql.conf
d /run/postgres 0700 postgres postgres -
File: /etc/systemd/system/postgresql@.service
[Unit]
Description=Initializing Postgresql %i Database

[Service]
User=postgres
Group=postgres

EnvironmentFile=/etc/conf.d/postgresql-%I

PermissionsStartOnly=true

ExecStartPre=/bin/mkdir /run/postgresql -p
ExecStartPre=/bin/chown postgres:postgres /run/postgresql
ExecStart=-/bin/sh -c "/usr/lib/postgresql-%I/bin/postgres -D /etc/postgresql-%I --data-directory=/var/lib/postgresql/%I/data"

[Install]
WantedBy=multi-user.target

[edit] NFS

Implements the functions of /etc/init.d/nfs, /etc/init.d/nfsmount and helper services.

File: /etc/modules-load.d/nfs.conf
sunrpc
nfs

The following is only necessary if you are running a NFS server.

File: /etc/modules-load.d/nfs-server.conf
nfsd

The following files are necessary for all versions of NFS:

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.