systemd-custom.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-config-systemd-custom" revision="systemd">
  8. <?dbhtml filename="systemd-custom.html"?>
  9. <title>Systemd Usage and Configuration</title>
  10. <indexterm zone="ch-config-systemd-custom">
  11. <primary sortas="e-Systemd">Systemd Customization</primary>
  12. </indexterm>
  13. <sect2>
  14. <title>Basic Configuration</title>
  15. <para>The <filename>/etc/systemd/system.conf</filename> file contains a set
  16. of options to control basic systemd operations. The default file has all
  17. entries commented out with the default settings indicated. This file is
  18. where the log level may be changed as well as some basic logging settings.
  19. See the <filename>systemd-system.conf(5)</filename> manual page for details
  20. on each configuration option.</para>
  21. </sect2>
  22. <sect2>
  23. <title>Disabling Screen Clearing at Boot Time</title>
  24. <para>The normal behavior for systemd is to clear the screen at
  25. the end of the boot sequence. If desired, this behavior may be
  26. changed by running the following command:</para>
  27. <screen role="nodump"><userinput>mkdir -pv /etc/systemd/system/getty@tty1.service.d
  28. cat &gt; /etc/systemd/system/getty@tty1.service.d/noclear.conf &lt;&lt; EOF
  29. <literal>[Service]
  30. TTYVTDisallocate=no</literal>
  31. EOF</userinput></screen>
  32. <para>The boot messages can always be reviewed by using the
  33. <userinput>journalctl -b</userinput> command as the
  34. <systemitem class="username">root</systemitem> user.</para>
  35. </sect2>
  36. <sect2>
  37. <title>Disabling tmpfs for /tmp</title>
  38. <para>By default, <filename class="directory">/tmp</filename> is created as
  39. a tmpfs. If this is not desired, it can be overridden by executing the
  40. following command:</para>
  41. <screen role="nodump"><userinput>ln -sfv /dev/null /etc/systemd/system/tmp.mount</userinput></screen>
  42. <para>Alternatively, if a separate partition for
  43. <filename class="directory">/tmp</filename> is desired, specify that
  44. partition in a <filename>/etc/fstab</filename> entry.</para>
  45. <warning>
  46. <para>
  47. Do not create the symbolic link above if a separate partition is used
  48. for <filename class="directory">/tmp</filename>. This will prevent the
  49. root file system (/) from being remounted r/w and make the system
  50. unusable when booted.
  51. </para>
  52. </warning>
  53. </sect2>
  54. <sect2>
  55. <title>Configuring Automatic File Creation and Deletion</title>
  56. <para>There are several services that create or delete files or
  57. directories:</para>
  58. <itemizedlist>
  59. <listitem><para>systemd-tmpfiles-clean.service</para></listitem>
  60. <listitem><para>systemd-tmpfiles-setup-dev.service</para></listitem>
  61. <listitem><para>systemd-tmpfiles-setup.service</para></listitem>
  62. </itemizedlist>
  63. <para>The system location for the configuration files is
  64. <filename>/usr/lib/tmpfiles.d/*.conf</filename>. The local
  65. configuration files are in
  66. <filename class="directory">/etc/tmpfiles.d</filename>. Files in
  67. <filename class="directory">/etc/tmpfiles.d</filename> override
  68. files with the same name in
  69. <filename class="directory">/usr/lib/tmpfiles.d</filename>. See
  70. <filename>tmpfiles.d(5)</filename> manual page for file format
  71. details.</para>
  72. <para>
  73. Note that the syntax for the
  74. <filename>/usr/lib/tmpfiles.d/*.conf</filename> files can be
  75. confusing. For example, the default deletion of files in the /tmp directory
  76. is located in <filename>/usr/lib/tmpfiles.d/tmp.conf</filename> with
  77. the line:
  78. <screen role="nodump">q /tmp 1777 root root 10d</screen>
  79. The type field, q, discusses creating a subvolume with quotas which
  80. is really only applicable to btrfs filesystems. It references type v
  81. which in turn references type d (directory). This then creates the
  82. specified directory if it is not present and adjusts the permissions
  83. and ownership as specified. Contents of the directory will be
  84. subject to time based cleanup if the age argument is specified.
  85. </para>
  86. <para>
  87. If the default parameters are not desired, then the file should
  88. be copied to <filename class="directory">/etc/tmpfiles.d</filename>
  89. and edited as desired. For example:
  90. <screen role="nodump"><userinput>mkdir -p /etc/tmpfiles.d
  91. cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d</userinput></screen>
  92. </para>
  93. </sect2>
  94. <sect2>
  95. <title>Overriding Default Services Behavior</title>
  96. <para>The parameters of a unit can be overriden by creating a directory
  97. and a configuration file in <filename
  98. class="directory">/etc/systemd/system</filename>. For example:</para>
  99. <screen role="nodump"><userinput>mkdir -pv /etc/systemd/system/foobar.service.d
  100. cat > /etc/systemd/system/foobar.service.d/foobar.conf &lt;&lt; EOF
  101. <literal>[Service]
  102. Restart=always
  103. RestartSec=30</literal>
  104. EOF</userinput></screen>
  105. <para>See <filename>systemd.unit(5)</filename> manual page for more
  106. information. After creating the configuration file, run
  107. <userinput>systemctl daemon-reload</userinput> and <userinput>systemctl
  108. restart foobar</userinput> to activate the changes to a service.</para>
  109. </sect2>
  110. <sect2>
  111. <title>Debugging the Boot Sequence</title>
  112. <para>Rather than plain shell scripts used in SysVinit or BSD style init
  113. systems, systemd uses a unified format for different types of startup
  114. files (or units). The command <command>systemctl</command> is used to
  115. enable, disable, control state, and obtain status of unit files. Here
  116. are some examples of frequently used commands:</para>
  117. <itemizedlist>
  118. <listitem>
  119. <para><command>systemctl list-units -t <replaceable>&lt;service&gt;</replaceable> [--all]</command>:
  120. lists loaded unit files of type service.</para>
  121. </listitem>
  122. <listitem>
  123. <para><command>systemctl list-units -t <replaceable>&lt;target&gt;</replaceable> [--all]</command>:
  124. lists loaded unit files of type target.</para>
  125. </listitem>
  126. <listitem>
  127. <para><command>systemctl show -p Wants <replaceable>&lt;multi-user.target&gt;</replaceable></command>:
  128. shows all units that depend on the multi-user target. Targets are
  129. special unit files that are anogalous to runlevels under
  130. SysVinit.</para>
  131. </listitem>
  132. <listitem>
  133. <para><command>systemctl status <replaceable>&lt;servicename.service&gt;</replaceable></command>:
  134. shows the status of the servicename service. The .service extension
  135. can be omitted if there are no other unit files with the same name,
  136. such as .socket files (which create a listening socket that provides
  137. similar functionality to inetd/xinetd).</para>
  138. </listitem>
  139. </itemizedlist>
  140. </sect2>
  141. <sect2>
  142. <title>Working with the Systemd Journal</title>
  143. <para>Logging on a system booted with systemd is handled with
  144. systemd-journald (by default), rather than a typical unix syslog daemon.
  145. You can also add a normal syslog daemon and have both operate side by
  146. side if desired. The systemd-journald program stores journal entries in a
  147. binary format rather than a plain text log file. To assist with
  148. parsing the file, the command <command>journalctl</command> is provided.
  149. Here are some examples of frequently used commands:</para>
  150. <itemizedlist>
  151. <listitem>
  152. <para><command>journalctl -r</command>: shows all contents of the
  153. journal in reverse chronological order.</para>
  154. </listitem>
  155. <listitem>
  156. <para><command>journalctl -u <replaceable>UNIT</replaceable></command>:
  157. shows the journal entries associated with the specified UNIT
  158. file.</para>
  159. </listitem>
  160. <listitem>
  161. <para><command>journalctl -b[=ID] -r</command>: shows the journal
  162. entries since last successful boot (or for boot ID) in reverse
  163. chronological order.</para>
  164. </listitem>
  165. <listitem>
  166. <para><command>journalctl -f</command>: provides functionality similar
  167. to tail -f (follow).</para>
  168. </listitem>
  169. </itemizedlist>
  170. </sect2>
  171. <sect2>
  172. <title>Working with Core Dumps</title>
  173. <para>Core dumps are useful to debug crashed programs, especially
  174. when a daemon process crashes. On systemd booted systems the core
  175. dumping is handled by <command>systemd-coredump</command>. It will
  176. log the core dump in the journal and store the core dump itself in
  177. <filename class="directory">/var/lib/systemd/coredump</filename>.
  178. To retrieve and process core dumps, the <command>coredumpctl</command>
  179. tool is provided. Here are some examples of frequently used commands:
  180. </para>
  181. <itemizedlist>
  182. <listitem>
  183. <para><command>coredumpctl -r</command>: lists all core dumps in
  184. reverse chronological order.</para>
  185. </listitem>
  186. <listitem>
  187. <para><command>coredumpctl -1 info</command>: shows the information
  188. from the last core dump.</para>
  189. </listitem>
  190. <listitem>
  191. <para><command>coredumpctl -1 debug</command>: loads the last core
  192. dump into <ulink url="&blfs-book;general/gdb.html">GDB</ulink>.
  193. </para>
  194. </listitem>
  195. </itemizedlist>
  196. <para>Core dumps may use a lot of disk space. The maximum disk space
  197. used by core dumps can be limited by creating a configuration file in
  198. <filename class="directory">/etc/systemd/coredump.conf.d</filename>.
  199. For example:</para>
  200. <screen role="nodump"><userinput>mkdir -pv /etc/systemd/coredump.conf.d
  201. cat &gt; /etc/systemd/coredump.conf.d/maxuse.conf &lt;&lt; EOF
  202. <literal>[Coredump]
  203. MaxUse=5G</literal>
  204. EOF</userinput></screen>
  205. <para>See the <filename>systemd-coredump(8)</filename>,
  206. <filename>coredumpctl(1)</filename>, and
  207. <filename>coredump.conf.d(5)</filename> manual pages for more
  208. information.</para>
  209. </sect2>
  210. <sect2>
  211. <title>Long Running Processes</title>
  212. <para>Beginning with systemd-230, all user processes are killed when a user
  213. session is ended, even if nohup is used, or the process uses the
  214. <function>daemon()</function> or <function>setsid()</function> functions.
  215. This is a deliberate change from a historically permissive environment to a
  216. more restrictive one. The new behavior may cause issues if you depend on
  217. long running programs (e.g., <command>screen</command> or
  218. <command>tmux</command>) to remain active after ending your user session.
  219. There are three ways to enable lingering processes to remain after a user
  220. session is ended.</para>
  221. <itemizedlist>
  222. <listitem>
  223. <para>
  224. <emphasis>Enable process lingering for only selected users</emphasis>:
  225. Normal users have permission to enable process lingering
  226. with the command <command>loginctl enable-linger</command> for their
  227. own user. System administrators can use the same command with a
  228. <parameter>user</parameter> argument to enable for a user. That user
  229. can then use the <command>systemd-run</command> command to start
  230. long running processes. For example: <command>systemd-run --scope
  231. --user /usr/bin/screen</command>. If you enable lingering for your
  232. user, the user@.service will remain even after all login sessions are
  233. closed, and will automatically start at system boot. This has the
  234. advantage of explicitly allowing and disallowing processes to run
  235. after the user session has ended, but breaks backwards compatibility
  236. with tools like <command>nohup</command> and utilities that use
  237. <function>daemon()</function>.
  238. </para>
  239. </listitem>
  240. <listitem>
  241. <para>
  242. <emphasis>Enable system-wide process lingering</emphasis>:
  243. You can set <parameter>KillUserProcesses=no</parameter> in
  244. <filename>/etc/systemd/logind.conf</filename> to enable process lingering
  245. globally for all users. This has the benefit of leaving the old
  246. method available to all users at the expense of explicit control.
  247. </para>
  248. </listitem>
  249. <listitem>
  250. <para>
  251. <emphasis>Disable at build-time</emphasis>: You can disable
  252. lingering by default while building systemd by adding the switch
  253. <parameter>-Ddefault-kill-user-processes=false</parameter> to the
  254. <command>meson</command> command for systemd. This completely
  255. disables the ability of systemd to kill user processes at session
  256. end.
  257. </para>
  258. </listitem>
  259. </itemizedlist>
  260. </sect2>
  261. </sect1>