1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
6 <refentry id=
"runlevel"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude"
8 conditional=
"ENABLE_UTMP">
11 <title>runlevel
</title>
12 <productname>systemd
</productname>
16 <refentrytitle>runlevel
</refentrytitle>
17 <manvolnum>8</manvolnum>
21 <refname>runlevel
</refname>
22 <refpurpose>Print previous and current SysV runlevel
</refpurpose>
27 <command>runlevel
</command>
28 <arg choice=
"opt" rep=
"repeat">options
</arg>
33 <title>Overview
</title>
35 <para>"Runlevels" are an obsolete way to start and stop groups of
36 services used in SysV init. systemd provides a compatibility layer
37 that maps runlevels to targets, and associated binaries like
38 <command>runlevel
</command>. Nevertheless, only one runlevel can
39 be
"active" at a given time, while systemd can activate multiple
40 targets concurrently, so the mapping to runlevels is confusing
41 and only approximate. Runlevels should not be used in new code,
42 and are mostly useful as a shorthand way to refer the matching
43 systemd targets in kernel boot parameters.
</para>
46 <title>Mapping between runlevels and systemd targets
</title>
47 <tgroup cols='
2' align='left' colsep='
1' rowsep='
1'
>
48 <colspec colname=
"runlevel" />
49 <colspec colname=
"target" />
52 <entry>Runlevel
</entry>
59 <entry><filename>poweroff.target
</filename></entry>
63 <entry><filename>rescue.target
</filename></entry>
66 <entry>2,
3,
4</entry>
67 <entry><filename>multi-user.target
</filename></entry>
71 <entry><filename>graphical.target
</filename></entry>
75 <entry><filename>reboot.target
</filename></entry>
83 <title>Description
</title>
85 <para><command>runlevel
</command> prints the previous and current
86 SysV runlevel if they are known.
</para>
88 <para>The two runlevel characters are separated by a single space
89 character. If a runlevel cannot be determined, N is printed
90 instead. If neither can be determined, the word
"unknown" is
93 <para>Unless overridden in the environment, this will check the
94 utmp database for recent runlevel changes.
</para>
98 <title>Options
</title>
100 <para>The following option is understood:
</para>
104 <term><option>--help
</option></term>
106 <xi:include href=
"standard-options.xml" xpointer=
"help-text" />
113 <title>Exit status
</title>
115 <para>If one or both runlevels could be determined,
0 is returned,
116 a non-zero failure code otherwise.
</para>
121 <title>Environment
</title>
123 <variablelist class='environment-variables'
>
125 <term><varname>$RUNLEVEL
</varname></term>
127 <listitem><para>If
<varname>$RUNLEVEL
</varname> is set,
128 <command>runlevel
</command> will print this value as current
129 runlevel and ignore utmp.
</para></listitem>
133 <term><varname>$PREVLEVEL
</varname></term>
135 <listitem><para>If
<varname>$PREVLEVEL
</varname> is set,
136 <command>runlevel
</command> will print this value as previous
137 runlevel and ignore utmp.
</para></listitem>
147 <term><filename>/run/utmp
</filename></term>
149 <listitem><para>The utmp database
<command>runlevel
</command> reads the previous and current runlevel
150 from.
</para></listitem>
156 <title>See Also
</title>
158 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>