systemd-custom.xml 13 KB

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