Systemd: Difference between revisions

From Bitpost wiki
No edit summary
Line 5: Line 5:
You should probably turn off systemd-resolved and manually configure /etc/resolv.conf, since systemd sucks the chrome off a donkey's ballbearings.
You should probably turn off systemd-resolved and manually configure /etc/resolv.conf, since systemd sucks the chrome off a donkey's ballbearings.


  sudo systemctl disable systemd-resolved
  sudo systemctl disable systemd-resolved.service && sudo service systemd-resolved stop
  sudo systemctl stop systemd-resolved
  # older: sudo systemctl disable systemd-resolved && sudo systemctl stop systemd-resolved
# IMPORTANT as it is a symlink to a systemd file that is out of our control:
sudo rm /etc/resolv.conf
  sudo emacs -nw /etc/resolv.conf # use [nameserver 8.8.8.8] if you don't have anything better
  sudo emacs -nw /etc/resolv.conf # use [nameserver 8.8.8.8] if you don't have anything better
# or typically it is already available:
sudo cp ~m/resolv.conf.goog /etc/resolv.conf


=== NTP ===
=== NTP ===

Revision as of 23:13, 7 October 2018

Systemd has done serious damage to networkmanager dns cron ntp... We have to adapt to it, here we go.

DNS

You should probably turn off systemd-resolved and manually configure /etc/resolv.conf, since systemd sucks the chrome off a donkey's ballbearings.

sudo systemctl disable systemd-resolved.service && sudo service systemd-resolved stop
# older: sudo systemctl disable systemd-resolved && sudo systemctl stop systemd-resolved

# IMPORTANT as it is a symlink to a systemd file that is out of our control:
sudo rm /etc/resolv.conf 

sudo emacs -nw /etc/resolv.conf # use [nameserver 8.8.8.8] if you don't have anything better
# or typically it is already available:
sudo cp ~m/resolv.conf.goog /etc/resolv.conf

NTP

DO NOT INSTALL ntp daemon any more, instead we now have systemd-timesyncd. That relies on systemd-networkd. Here's what I did on gold (which needed a specific ntp server)...

sudo apt remove ntp
emacs /etc/systemd/timesyncd.conf # if you need to hit a non-standard ntp server
systemctl status systemd-networkd systemd-timedated systemd-timesyncd
sudo timedatectl set-ntp on
sudo systemctl start systemd-networkd systemd-timedated systemd-timesyncd


Timers

Use these in place of cron. Each one typically does one task.

   systemd timer services
   ----------------------
   https://www.certdepot.net/rhel7-use-systemd-timers/

   create a script to do the work:
     echo "/usr/sbin/logrotate /etc/logrotate.conf" >/usr/local/sbin/logrotate.sh

   create a service file:
     nano /usr/lib/systemd/system/logrotate.service
       [Unit]
       Description=Rotate logs

       [Service]
       Type=simple
       ExecStart=/usr/local/sbin/logrotate.sh
       User=root

       [Install]
       WantedBy=multi-user.target

   create a timer file:
     nano /usr/lib/systemd/system/logrotate.timer
       [Unit]
       Description=Rotate logs as needed every night at 2am

       [Timer]
       OnCalendar=*-*-* 02:00:00
       Unit=logrotate.service

       [Install]
       WantedBy=multi-user.target

   activate on boot:
     # NOTE you must enable the service (even though not run directly), plus the timer
     # then start the timer
     systemctl enable logrotate       
     systemctl enable logrotate.timer
     systemctl start logrotate.timer

   utils:
     systemctl is-enabled ####.timer
     systemctl is-active ####.timer   # to see if timer is active and enabled
     systemctl start ####      # to run service immediately
     systemctl status ####     # nice status output
     systemctl daemon-reload   # to restart services after config changes
     systemctl list-timers [####*]  # to list timers that start with #####