systemd-custom.xml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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-scripts-systemd-custom" revision="systemd">
  8. <?dbhtml filename="systemd-custom.html"?>
  9. <title>Systemd Usage and Configuration</title>
  10. <indexterm zone="ch-scripts-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 <filename>systemd-system.conf(5)</filename> manual page for details on
  20. 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>This is not necessary if there is a separate partition for
  41. <filename class="directory">/tmp</filename> specified in
  42. <filename>/etc/fstab</filename>.</para>
  43. </sect2>
  44. <sect2>
  45. <title>Configuring Automatic File Creation and Deletion</title>
  46. <para>There are several services that create or delete files or
  47. directories:</para>
  48. <itemizedlist>
  49. <listitem><para>systemd-tmpfiles-clean.service</para></listitem>
  50. <listitem><para>systemd-tmpfiles-setup-dev.service</para></listitem>
  51. <listitem><para>systemd-tmpfiles-setup.service</para></listitem>
  52. </itemizedlist>
  53. <para>The system location for the configuration files is
  54. <filename>/usr/lib/tmpfiles.d/*.conf</filename>. The local
  55. configuration files are in
  56. <filename class="directory">/etc/tmpfiles.d</filename>. Files in
  57. <filename class="directory">/etc/tmpfiles.d</filename> override
  58. files with the same name in
  59. <filename class="directory">/usr/lib/tmpfiles.d</filename>. See
  60. <filename>tmpfiles.d(5)</filename> manual page for file format
  61. details.</para>
  62. </sect2>
  63. <sect2>
  64. <title>Overriding Default Services Behavior</title>
  65. <para>The parameter of a unit can be overriden by creating a directory
  66. and a configuration file in <filename
  67. class="directory">/etc/systemd/system</filename>. For example:</para>
  68. <screen role="nodump"><userinput>mkdir -pv /etc/systemd/system/foobar.service.d
  69. cat > /etc/systemd/system/foobar.service.d/foobar.conf &lt;&lt; EOF
  70. <literal>[Service]
  71. Restart=always
  72. RestartSec=30</literal>
  73. EOF</userinput></screen>
  74. <para>See <filename>systemd.unit(5)</filename> manual page for more
  75. information. After creating the configuration file, run
  76. <userinput>systemctl daemon-reload</userinput> and <userinput>systemctl
  77. restart foobar</userinput> to activate the changes to a service.</para>
  78. </sect2>
  79. <sect2>
  80. <title>Debugging the Boot Sequence</title>
  81. <para>Rather than plain shell scripts used in SysVinit or BSD style init
  82. systems, systemd uses a unified format for different types of startup
  83. files (or units). The command <command>systemctl</command> is used to
  84. enable, disable, controll state, and obtain status of unit files. Here
  85. are some examples of frequently used commands:</para>
  86. <itemizedlist>
  87. <listitem>
  88. <para><command>systemctl list-units -t <replaceable>&lt;service&gt;</replaceable> [--all]</command>:
  89. lists loaded unit files of type service.</para>
  90. </listitem>
  91. <listitem>
  92. <para><command>systemctl list-units -t <replaceable>&lt;target&gt;</replaceable> [--all]</command>:
  93. lists loaded unit files of type target.</para>
  94. </listitem>
  95. <listitem>
  96. <para><command>systemctl show -p Wants <replaceable>&lt;multi-user.target&gt;</replaceable></command>:
  97. shows all units that depend on the multi-user target. Targets are
  98. special unit files that are anogalous to runlevels under
  99. SysVinit.</para>
  100. </listitem>
  101. <listitem>
  102. <para><command>systemctl status <replaceable>&lt;servicename.service&gt;</replaceable></command>:
  103. shows the status of the servicename service. The .service extension
  104. can be omitted if there are no other unit files with the same name,
  105. such as .socket files (which create a listening socket that provides
  106. similar functionality to inetd/xinetd).</para>
  107. </listitem>
  108. </itemizedlist>
  109. </sect2>
  110. <sect2>
  111. <title>Working with the Systemd Journal</title>
  112. <para>Logging on a system booted with systemd is handled with
  113. systemd-journald (by default), rather than a typical unix syslog daemon.
  114. You can also add a normal syslog daemon and have both work side by
  115. side if desired. The systemd-journald program stores journal entries in a
  116. binary format rather than a plain text log file. To assist with
  117. parsing the file, the command <command>journalctl</command> is provided.
  118. Here are some examples of frequently used commands:</para>
  119. <itemizedlist>
  120. <listitem>
  121. <para><command>journalctl -r</command>: shows all contents of the
  122. journal in reverse chronological order.</para>
  123. </listitem>
  124. <listitem>
  125. <para><command>journalctl -u <replaceable>UNIT</replaceable></command>:
  126. shows the journal entries associated with the specified UNIT
  127. file.</para>
  128. </listitem>
  129. <listitem>
  130. <para><command>journalctl -b[=ID] -r</command>: shows the journal
  131. entries since last successfull boot (or for boot ID) in reverse
  132. chronological order.</para>
  133. </listitem>
  134. <listitem>
  135. <para><command>journalctl -f</command>: povides functionality similar
  136. to tail -f (follow).</para>
  137. </listitem>
  138. </itemizedlist>
  139. </sect2>
  140. <sect2>
  141. <title>Long Running Processes</title>
  142. <para>Beginning with systemd-230, all user processes are killed when a
  143. user session is ended, even if nohup is used, or the process uses
  144. <function>daemon()</function> or <function>setsid()</function>. This is a
  145. deliberate change from a historically permissive environment to a more
  146. restrictive one. The new behavior may cause issues if you depend on long
  147. running programs (e.g., <command>screen</command> or
  148. <command>tmux</command>) to remain active after ending your user
  149. session. There are three ways to enable lingering processes to remain after
  150. a user session is ended.</para>
  151. <itemizedlist>
  152. <listitem>
  153. <para>
  154. <emphasis>Enable process lingering for only needed users</emphasis>:
  155. normal users have permission to enable process lingering
  156. with the command <command>loginctl enable-linger</command> for their
  157. own user. System administrators can use the same command with a
  158. <parameter>user</parameter> argument to enable for a user. That user
  159. can then use the <command>systemd-run</command> command to start
  160. long running processes. For example: <command>systemd-run --scope
  161. --user /usr/bin/screen</command>. If you enable lingering for your
  162. user, the user@.service will remain even after all login sessions are
  163. closed, and will automatically start at system boot. This has the
  164. advantage of explicitly allowing and disallowing processes to run
  165. after the user session has ended, but breaks backwards compatibility
  166. with tools like <command>nohup</command> and utilities that use
  167. <function>deamon()</function>.
  168. </para>
  169. </listitem>
  170. <listitem>
  171. <para>
  172. <emphasis>Enable system-wide process lingering</emphasis>:
  173. you can set <parameter>KillUserProcesses=no</parameter> in
  174. <filename>/etc/logind.conf</filename> to enable process lingering
  175. globally for all users. This has the benefit of leaving the old
  176. method available to all users at the expense of explicit control.
  177. </para>
  178. </listitem>
  179. <listitem>
  180. <para>
  181. <emphasis>Disable at build-time</emphasis>: You can enable
  182. lingering by default while building systemd by adding the switch
  183. <parameter>--without-kill-user-processes</parameter> to the
  184. <command>configure</command> command for systemd. This completely
  185. disables the ability of systemd to kill user processes at session
  186. end.
  187. </para>
  188. </listitem>
  189. </itemizedlist>
  190. </sect2>
  191. </sect1>