:PROPERTIES: :ID: 80866258-4fd5-4ddc-b3e4-00fa3d3372d3 :END: #+title: Command line: systemctl #+date: 2021-07-27 13:47:34 +08:00 #+date_modified: 2022-12-06 18:25:19 +08:00 #+language: en #+property: header_args :eval no The go-to command to manage units in a systemd-ful system. For full details, you can view the =systemctl.1= manual page. * Synopsis #+begin_src shell systemctl [OPTIONS...] COMMAND [COMMAND_ARGS...] [COMMAND_OPTIONS...] #+end_src * Options - =--user= runs the binary in user mode with the user-specific options and load-path. See [[id:c7edff80-6dea-47fc-8ecd-e43b5ab8fb1e][systemd at user-level]] for more details. - =--help= is an obvious one. It prints a detailed help section of the command. - =--host= controls a remote system. Meaning, you can manage services and timers remotely. Will not work on certain subcommands such as =edit=. - =--container= is similar to =--host= but operates on a local container. - =--with-dependencies= will show the output of the unit specified along with its dependencies. This is only effective on certain subcommands such as =status=, =list-units=, =cat=, and =list-unit-files=. - =-p PROPERTIES= shows only the listed properties. Very useful for filtering the properties for =systemctl show= subcommand. Take note =PROPERTIES= can be a list of properties to show delimited with a comma. - =-P PROPERTIES= shows the value of the listed properies. Similar to =-p=, =PROPERTIES= can be a comma-delimited list of properties to be shown. * Subcommands - =show PATTERN= shows the properties of the matched units. It can also show with multiple units with a helpful label and proper formatting (which is very nice). This is the go-to subcommand for debugging a service. - =enable UNIT= and =disable UNIT= enables and disables units. It mainly adds the unit activation at startup. + =--now= starts/stops the unit. It is the equivalent of =systemctl {enable,disable} UNIT && systemctl {start,stop} UNIT=. Pretty handy if you intend to add the unit at startup and want to use it now. - =start UNIT= and =stop UNIT= starts and stops the unit, respectively. Though, this doesn't activate - =restart UNIT= restarts the given unit. This also reloads with the modified changes of the unit. - In some cases where restarting the unit isn't enough, =daemon-reload= will reload the daemon with the modified units. systemd does not have reload-at-change for its unit. That is, if a unit is modified, systemd will not run the modified version until reloaded. - =show-environment= shows the environment variables of the system. - =list-units [PATTERN...]= is self-explanatory ;p. - =is-active PATTERN...= prints the status of the matched unit and exits successfully if it's active. - =cat PATTERN...= shows contents of the given units in a neat formatted page.