Systemd: Difference between revisions

From Edgar BV Wiki
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 11: Line 11:


     systemctl enable|disable service
     systemctl enable|disable service
To get a script to start as a service
  vi /usr/lib/systemd/system/SCRIPTNMAME.service
<pre>
[Unit]
Description=Evologger instance
Documentation=https://wiki.edgarbv.com/index.php?title=My_guide_to_grafana_/_influxdb
Wants=network-online.target
After=network-online.target
After=grafana.service grafana-server.service  mariadb.service mysql.service
[Service]
User=evologger
Group=evologger
Restart=on-failure
ExecStart=/opt/evologger/evologger.sh &>>/var/log/evologger
[Install]
WantedBy=default.target
</pre>
After editing these scripts always do
  systemctl daemon-reload
To show all services, do the following. Add | grep enabled to see which are enabled.
  systemctl list-unit-files


= logs =
= logs =
Line 30: Line 57:


     journalctl -f
     journalctl -f
= networking =
==setting up interfaces==
https://www.freedesktop.org/software/systemd/man/systemd.network.html
he main network file must have the extension .network; other extensions are ignored. Networks are applied to links whenever the links appear.
The .network files are read from the files located in the system network directories /usr/lib/systemd/network and /usr/local/lib/systemd/network, the volatile runtime network directory /run/systemd/network and the local administration network directory /etc/systemd/network.
he main network file must have the extension .network; other extensions are ignored. Networks are applied to links whenever the links appear.
The .network files are read from the files located in the system network directories /usr/lib/systemd/network and /usr/local/lib/systemd/network, the volatile runtime network directory /run/systemd/network and the local administration network directory /etc/systemd/network.
==resolving==
https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html#
Systemd builds a stub / cache on 127.0.0.53, which you can see in /etc/resolv.conf (which links to /run/systemd/stub-resolv.conf). 3rd party programmes will sometimes edit /run/systemd/resolve/resolv.conf where you can see what else is resolving.
You also specify DNS in the Networks section
eg
<pre>
[Match]
Name=wlo1 # the device name here
[Network] # add multiple DNS
DNS=8.8.8.8
DNS=208.67.222.22
</pre>
Then restart:
  sudo service systemd-networkd restart
Also look into:
    netplan apply
Then check:
    systemd-resolve --status wlo1
    In addition to /etc/systemd/network, drop-in ".d" directories can be placed in /lib/systemd/network or /run/systemd/network directories. Drop-in files in /etc take precedence over those in /run which in turn take precedence over those in /lib. Drop-in files under any of these directories take precedence over the main netdev file wherever located. (Of course, since /run is temporary and /usr/lib is for vendors, it is unlikely drop-ins should be used in either of those places.)
Another approach disable the DNSStubListener for usage with dnsmasq:
  sudo nano /etc/systemd/resolved.conf:
  DNSStubListener=false

Latest revision as of 08:34, 14 January 2020

services

You can use the service or systemctl commands to work with these. Apparently systemctl is more direct and service is a wrapper script.

   systemctl start|stop|restart|status service

To find out if a service is enabled / will start up at boot

   systemctl is-enabled service

To enable|disable it at boot

   systemctl enable|disable service

To get a script to start as a service

  vi /usr/lib/systemd/system/SCRIPTNMAME.service
[Unit]
Description=Evologger instance
Documentation=https://wiki.edgarbv.com/index.php?title=My_guide_to_grafana_/_influxdb
Wants=network-online.target
After=network-online.target
After=grafana.service grafana-server.service  mariadb.service mysql.service

[Service]
User=evologger
Group=evologger
Restart=on-failure
ExecStart=/opt/evologger/evologger.sh &>>/var/log/evologger

[Install]
WantedBy=default.target

After editing these scripts always do

  systemctl daemon-reload

To show all services, do the following. Add | grep enabled to see which are enabled.

  systemctl list-unit-files

logs

How To Use Journalctl to View and Manipulate Systemd Logs

To filter by unit (a unit can be all kinds of stuff)

   journalctl -u service|username|groupname

show all information (instead of truncated)

   journalctl -a

to throw the output to stdout instead of the less pager

   journalctl --no-pager

to follow output live

   journalctl -f

networking

setting up interfaces

https://www.freedesktop.org/software/systemd/man/systemd.network.html

he main network file must have the extension .network; other extensions are ignored. Networks are applied to links whenever the links appear.

The .network files are read from the files located in the system network directories /usr/lib/systemd/network and /usr/local/lib/systemd/network, the volatile runtime network directory /run/systemd/network and the local administration network directory /etc/systemd/network.

he main network file must have the extension .network; other extensions are ignored. Networks are applied to links whenever the links appear.

The .network files are read from the files located in the system network directories /usr/lib/systemd/network and /usr/local/lib/systemd/network, the volatile runtime network directory /run/systemd/network and the local administration network directory /etc/systemd/network.

resolving

https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html# Systemd builds a stub / cache on 127.0.0.53, which you can see in /etc/resolv.conf (which links to /run/systemd/stub-resolv.conf). 3rd party programmes will sometimes edit /run/systemd/resolve/resolv.conf where you can see what else is resolving.

You also specify DNS in the Networks section eg

[Match]
Name=wlo1 # the device name here

[Network] # add multiple DNS 
DNS=8.8.8.8
DNS=208.67.222.22

Then restart:

  sudo service systemd-networkd restart

Also look into:

   netplan apply

Then check:

   systemd-resolve --status wlo1


   In addition to /etc/systemd/network, drop-in ".d" directories can be placed in /lib/systemd/network or /run/systemd/network directories. Drop-in files in /etc take precedence over those in /run which in turn take precedence over those in /lib. Drop-in files under any of these directories take precedence over the main netdev file wherever located. (Of course, since /run is temporary and /usr/lib is for vendors, it is unlikely drop-ins should be used in either of those places.)

Another approach disable the DNSStubListener for usage with dnsmasq:

  sudo nano /etc/systemd/resolved.conf:
  DNSStubListener=false