1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"runlevel"
10 xmlns:
xi=
"http://www.w3.org/2001/XInclude"
11 conditional=
"ENABLE_UTMP">
14 <title>runlevel
</title>
15 <productname>systemd
</productname>
19 <contrib>Developer
</contrib>
20 <firstname>Lennart
</firstname>
21 <surname>Poettering
</surname>
22 <email>lennart@poettering.net
</email>
28 <refentrytitle>runlevel
</refentrytitle>
29 <manvolnum>8</manvolnum>
33 <refname>runlevel
</refname>
34 <refpurpose>Print previous and current SysV runlevel
</refpurpose>
39 <command>runlevel
</command>
40 <arg choice=
"opt" rep=
"repeat">options
</arg>
45 <title>Overview
</title>
47 <para>"Runlevels" are an obsolete way to start and stop groups of
48 services used in SysV init. systemd provides a compatibility layer
49 that maps runlevels to targets, and associated binaries like
50 <command>runlevel
</command>. Nevertheless, only one runlevel can
51 be
"active" at a given time, while systemd can activate multiple
52 targets concurrently, so the mapping to runlevels is confusing
53 and only approximate. Runlevels should not be used in new code,
54 and are mostly useful as a shorthand way to refer the matching
55 systemd targets in kernel boot parameters.
</para>
58 <title>Mapping between runlevels and systemd targets
</title>
59 <tgroup cols='
2' align='left' colsep='
1' rowsep='
1'
>
60 <colspec colname=
"runlevel" />
61 <colspec colname=
"target" />
64 <entry>Runlevel
</entry>
71 <entry><filename>poweroff.target
</filename></entry>
75 <entry><filename>rescue.target
</filename></entry>
78 <entry>2,
3,
4</entry>
79 <entry><filename>multi-user.target
</filename></entry>
83 <entry><filename>graphical.target
</filename></entry>
87 <entry><filename>reboot.target
</filename></entry>
95 <title>Description
</title>
97 <para><command>runlevel
</command> prints the previous and current
98 SysV runlevel if they are known.
</para>
100 <para>The two runlevel characters are separated by a single space
101 character. If a runlevel cannot be determined, N is printed
102 instead. If neither can be determined, the word
"unknown" is
105 <para>Unless overridden in the environment, this will check the
106 utmp database for recent runlevel changes.
</para>
110 <title>Options
</title>
112 <para>The following option is understood:
</para>
116 <term><option>--help
</option></term>
118 <xi:include href=
"standard-options.xml" xpointer=
"help-text" />
125 <title>Exit status
</title>
127 <para>If one or both runlevels could be determined,
0 is returned,
128 a non-zero failure code otherwise.
</para>
133 <title>Environment
</title>
135 <variablelist class='environment-variables'
>
137 <term><varname>$RUNLEVEL
</varname></term>
139 <listitem><para>If
<varname>$RUNLEVEL
</varname> is set,
140 <command>runlevel
</command> will print this value as current
141 runlevel and ignore utmp.
</para></listitem>
145 <term><varname>$PREVLEVEL
</varname></term>
147 <listitem><para>If
<varname>$PREVLEVEL
</varname> is set,
148 <command>runlevel
</command> will print this value as previous
149 runlevel and ignore utmp.
</para></listitem>
159 <term><filename>/run/utmp
</filename></term>
161 <listitem><para>The utmp database
<command>runlevel
</command> reads the previous and current runlevel
162 from.
</para></listitem>
168 <title>See Also
</title>
170 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>systemd.target
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>systemctl
</refentrytitle><manvolnum>1</manvolnum></citerefentry>