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.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="runlevel" conditional='HAVE_SYSV_COMPAT'
7 xmlns:xi="http://www.w3.org/2001/XInclude">
10 <title>runlevel</title>
11 <productname>systemd</productname>
15 <refentrytitle>runlevel</refentrytitle>
16 <manvolnum>8</manvolnum>
20 <refname>runlevel</refname>
21 <refpurpose>Print previous and current SysV runlevel</refpurpose>
26 <command>runlevel</command>
27 <arg choice="opt" rep="repeat">options</arg>
32 <title>Overview</title>
34 <para>"Runlevels" are an obsolete way to start and stop groups of
35 services used in SysV init. systemd provides a compatibility layer
36 that maps runlevels to targets, and associated binaries like
37 <command>runlevel</command>. Nevertheless, only one runlevel can
38 be "active" at a given time, while systemd can activate multiple
39 targets concurrently, so the mapping to runlevels is confusing
40 and only approximate. Runlevels should not be used in new code,
41 and are mostly useful as a shorthand way to refer the matching
42 systemd targets in kernel boot parameters.</para>
45 <title>Mapping between runlevels and systemd targets</title>
46 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
47 <colspec colname="runlevel" />
48 <colspec colname="target" />
51 <entry>Runlevel</entry>
58 <entry><filename>poweroff.target</filename></entry>
62 <entry><filename>rescue.target</filename></entry>
65 <entry>2, 3, 4</entry>
66 <entry><filename>multi-user.target</filename></entry>
70 <entry><filename>graphical.target</filename></entry>
74 <entry><filename>reboot.target</filename></entry>
82 <title>Description</title>
84 <para><command>runlevel</command> prints the previous and current
85 SysV runlevel if they are known.</para>
87 <para>The two runlevel characters are separated by a single space
88 character. If a runlevel cannot be determined, N is printed
89 instead. If neither can be determined, the word "unknown" is
92 <para>Unless overridden in the environment, this will check the
93 utmp database for recent runlevel changes.</para>
97 <title>Options</title>
99 <para>The following option is understood:</para>
103 <term><option>--help</option></term>
105 <xi:include href="standard-options.xml" xpointer="help-text" />
112 <title>Exit status</title>
114 <para>If one or both runlevels could be determined, 0 is returned,
115 a non-zero failure code otherwise.</para>
120 <title>Environment</title>
122 <variablelist class='environment-variables'>
124 <term><varname>$RUNLEVEL</varname></term>
126 <listitem><para>If <varname>$RUNLEVEL</varname> is set,
127 <command>runlevel</command> will print this value as current
128 runlevel and ignore utmp.</para></listitem>
132 <term><varname>$PREVLEVEL</varname></term>
134 <listitem><para>If <varname>$PREVLEVEL</varname> is set,
135 <command>runlevel</command> will print this value as previous
136 runlevel and ignore utmp.</para></listitem>
146 <term><filename>/run/utmp</filename></term>
148 <listitem><para>The utmp database <command>runlevel</command> reads the previous and current runlevel
151 <xi:include href="version-info.xml" xpointer="v237"/></listitem>
157 <title>See Also</title>
158 <para><simplelist type="inline">
159 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
160 <member><citerefentry><refentrytitle>systemd.target</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
161 <member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>