Systemd usage: Difference between revisions

From wikinotes
No edit summary
 
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
<source lang="bash">
Instructions on viewing, configuring, monitoring your system's services/timers/targets.
systemctl enable  myservice
systemctl start  myservice
systemctl stop    myservice
systemctl restart myservice


systemctl is-active  myservice
= Documentation =
systemctl is-enabled  myservice
<blockquote>
{| class="wikitable"
|-
| <code>man systemctl</code> || https://man.archlinux.org/man/core/systemd/systemctl.1.en
|-
|}
</blockquote><!-- Documentation -->


systemctl  list-units                    # list all enabled services
= Service Management =
systemctl -t service -a                  # list all services
<blockquote>
sudo journalctl -f -u myservice.service  # tail unitfile's log
Manage Service
sudo systemctl --system daemon-reload    # reload unitfiles
<syntaxhighlight lang="bash">
ps xawf -eo pid,user,cgroup,args        # display startup tree
systemctl {enable,start,stop,restart} myservice
</syntaxhighlight>


journalctl -b                            # All boot messages
Override Service Options
journalctl /usr/bin/program              # All logs associated with a particular program
<syntaxhighlight lang="bash">
journalctl -u <servicename>.service     # All logs associated with a particular service
# creates /etc/systemd/system/myservice.service.d/override.conf
</source>
# where you can override service settings
systemctl edit myservice.service
</syntaxhighlight>
 
Info about services/status
<syntaxhighlight lang="bash">
systemctl {is-active,is-enabled} myservice
 
systemctl show \
  [-p property,...] `# list specific properties` \
  [foo.service]      `# filter to unitfile` \
</syntaxhighlight>
</blockquote><!-- Service Management -->
 
= System Management =
<blockquote>
<syntaxhighlight lang="bash">
systemctl --system daemon-reload          # reload unitfiles
systemctl [--user] list-units -t target  # list all targets
 
# list filepaths for each service
for service in $(systemctl list-units -t service,timer | head -n -6 | sed -n '2,$p'  | sed -E 's/^[^a-zA-Z0-9]+//' | awk -F' ' '{ print $1 }'); do
  systemctl show -P Id,FragmentPath "$service" | sed 'N;s/\n/ /'
done | column -t
</syntaxhighlight>
systemctl {list-units,list-timers,list-sockets}
</blockquote><!-- Management -->
 
= Logs =
<blockquote>
See [[systemd journald]]
</blockquote><!-- Logs -->

Latest revision as of 17:36, 11 December 2022

Instructions on viewing, configuring, monitoring your system's services/timers/targets.

Documentation

man systemctl https://man.archlinux.org/man/core/systemd/systemctl.1.en

Service Management

Manage Service

systemctl {enable,start,stop,restart} myservice

Override Service Options

# creates /etc/systemd/system/myservice.service.d/override.conf
# where you can override service settings
systemctl edit myservice.service

Info about services/status

systemctl {is-active,is-enabled} myservice

systemctl show \
  [-p property,...]  `# list specific properties` \
  [foo.service]      `# filter to unitfile` \

System Management

systemctl --system daemon-reload          # reload unitfiles
systemctl [--user] list-units -t target   # list all targets

# list filepaths for each service
for service in $(systemctl list-units -t service,timer | head -n -6 | sed -n '2,$p'  | sed -E 's/^[^a-zA-Z0-9]+//' | awk -F' ' '{ print $1 }'); do
  systemctl show -P Id,FragmentPath "$service" | sed 'N;s/\n/ /'
done | column -t

systemctl {list-units,list-timers,list-sockets}

Logs

See systemd journald