sections in this module City College of San Francisco - CS260A
Linux System Administration

Module: StartupShutdown III
module list

systemctl

systemctl is used to inspect and control the systemd (init(1)) system. We will cover a subset of its syntax. For a complete list, see the man page

systemctl [ options ] command [ name ]

name is one or more unit files, separated by space. If name does not have an extension, .service is assumed.

we will only cover one option, since it is useful to limit output in the default case:

--type=xyz
xyz is a comma-separated list of unit types. when listing units, output is limited to these types (this option limits the output for the commands list-units, list-unit-files and status

commands:

command
meaning
list-units
this is the default command. It lists all loaded active units. Add the --all option to see inactive units.
list-unit-files
List all unit files and indicate whether they are enabled, disabled or static (which means there is nothing to enable - this is used for such things as path or slice units)
start
stop
reload
restart
these are similar to the upstart commands, or to service commands (with name and command reversed). name is one or more unit names.
reload here means reload the unit-specific configuration, not systemd's configuration of the unit. (i.e., sshd reloads sshd_config)
daemon-reload
reload systemd's configuration. this reads all the units and recreates the dependency tree. It does not start or stop any units, but any changes in dependencies configured before the daemon-reload will now be effective when a transition occurs.
status
give status of all units (default) or of the name unit(s). Note: sometimes systemctl will truncate the output of status adding ellipses to the end of the line. To get complete information you will need to add the -l option (lower-case L).
show
give machine-readable status of systemd itself (no name(s) given) or the units named
enable
disable
enable or disable the named unit(s). This is used to configure a new unit - this will reload systemd's configuration similar to daemon-reload afterwards. Note that, similar to the difference between chkconfig and service on earlier systems, this configures the unit to start but does not start it. To start it requires a following start command.
isolate
start the listed units and stop all others. This only has effect if the unit has a special option that allows it to be isolated and it is set to true. (AllowIsolate=yes
isolate is used to change the overall system state, just like a system5 change in runlevel would do (see the halt, reboot, rescue, poweroff, emergency commands)
For example, when running in graphical mode, systemctl isolate multi-user.target would take the system to text mode, equivalent to init 3 or initctl stop prefdm on 6.5
default
rescue
emergency
halt
poweroff
reboot
take the system to the indicated state. poweroff = halt + power off; rescue is single-user mode, while emergency is similar to booting to a root shell (with no filesystems mounted rw) Note: on VMs you should use poweroff rather than halt.
default is actually not a target; it is symlinked to a different target - whatever the default state is (multi-user or graphical, probably)
these are effectively isolate commands
set-default
set the default target. Should be one of rescue.target, emergency.target, multi-user.target or graphical.target. reboot.target is probably not a good choice.

Examples:

systemctl restart sshd

restart sshd.service

systemctl start xyz  or   systemctl stop xyz

start xyz.service (or shut it down)

systemctl enable sshd  or  systemctl disable sshd

configure sshd to start automatically (or not). You can check whether a unit is enabled or disabled and whether it is running or not by using the systemctl status x  command where x is the unit name:

# systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: active (running) since Fri 2014-07-18 11:52:53 PDT; 2h 24min ago
 Main PID: 1347 (sshd)

In this output you can see if sshd is active (if systemd thinks it has been started correctly and either has processes running or has finished its work), running, and whether it is enabled (equivalent to being installed under chkconfig, like chkconfig --add or chkconfig on) or disabled (like chkconfig --del or chkconfig off)

systemctl isolate halt.target  or   systemctl halt (or just halt)

halt the system

systemctl isolate reboot.target or systemctl reboot (or just reboot)

duh

systemctl isolate multi-user.target

go to text mode (out of graphical mode)

systemctl restart display-manager

restart the window manager. (This would be systemctl restart graphical.target, but targets cannot be restarted, only services.)

systemctl --type=service

list all service units (the default command is list-units, but without --type it will list all types)

In the example below, we show all the active targets. This gives you a good idea of what is configured to be running on your system:

# systemctl --type target list-units
UNIT                LOAD   ACTIVE SUB    DESCRIPTION
basic.target        loaded active active Basic System
cryptsetup.target   loaded active active Encrypted Volumes
getty.target        loaded active active Login Prompts
graphical.target    loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target     loaded active active Local File Systems
multi-user.target   loaded active active Multi-User System
network.target      loaded active active Network
nfs.target          loaded active active Network File System Server
paths.target        loaded active active Paths
remote-fs.target    loaded active active Remote File Systems
slices.target       loaded active active Slices
sockets.target      loaded active active Sockets
swap.target         loaded active active Swap
sysinit.target      loaded active active System Initialization
time-sync.target    loaded active active System Time Synchronized
timers.target       loaded active active Timers

Having said all this, there are a bunch of mysteries. As an example. if you look at the swap.target, I dont have any idea what this has to do with having a swap device. It still looks like the swap device is activated by reading the fstab. If the swap device is removed from the fstab, systemctl still says swap is loaded and active, but there are no swap devices. Contrarily, if you disable the swap target, and reboot (with the swap device still in the fstab) the system still has a swap device when it reboots and it re-enables the swap target. Even more interesting, stopping swap.target has no effect.

I believe the answer is that systemd can be used to activate the swap device but it is not. Instead, systemd reads the fstab and activates filesystems from there, at least in the default configuration.

Prev This page was made entirely with free software on linux:  
Kompozer, the Mozilla Project
and Openoffice.org      
Next

Copyright 2014 Greg Boyd - All Rights Reserved.