17

after running

sudo pacman -Syyu

or

sudo pacman -S [something to install]

should I restart just to be safe?

10

If there are updates to the kernel, glibc or systemd, you may want to restart so the updated versions are in use. If you have, say, updates to your desktop environment, a simple logout/login is enough.

11

The best way is to find what programs/services use the old libraries and restart them. And you can achieve it by listing all used files using 'lsof' and find those that have 'DEL' type. DEL means filename was removed from the filesystem but it is still stuck in memory because someone uses it.

Here is the full command line:

 sudo lsof +c 0 | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u
  • 2
    After generating that list of services and libraries, it still is not clear which systemd services need to be restarted. Hence, even though I know which processes and libs need a restart, it is typically non-trivial to determine which services to restart based on that list. – bwv549 Jan 29 '15 at 20:36
6

The only mandatory reason to reboot is a new kernel (and you can soft-reboot using kexec). See https://wiki.archlinux.org/index.php/Kexec for details, in short:

  • load the new kernel, initramfs and specify the boot cmdline

    kexec -l /boot/new-kernel --initrd=/boot/new-initramfs --reuse-cmdline
    
  • invoke kexec (use systemctl for proper shutdown, kexec -e would execute directly)

    systemctl kexec
    
  • Note that if you create a kexec-load@.service as explained in the wiki, if you reboot, systemd will automatically soft-reboot using kexec instead of doing a bios reboot

Little bit improved version that gives systemd service names:

PIDS="(lsof +c0 -n 2> /dev/null | grep 'DEL.*lib' | awk '{print $2}' | sort -u)"
for PID in $PIDS; do
    systemctl status $i
done | grep '●' | awk '{print $2}' | sort -u

or one-line:

for i in $(lsof +c0 -n 2> /dev/null | grep 'DEL.*lib' | awk '{print $2}' | sort -u); do systemctl status $i; done | grep '●' | awk '{print $2}' | sort -u

Note that there are some issues:

  • systemctl daemon-reload should be executed prior to restarting anything else
  • if PID 1 (systemd itself) needs to be restarted, it can be done using systemctl daemon-reexec
  • systemctl restart dbus.service breaks some other services, they need to be restarted after dbus restart:
    • systemd itself: systemctl daemon-reexec
    • systemd-logind
    • systemd-machined
    • probably other systemd-*/other services that (heavily) use dbus
  • If you're connected via SSH and SSH needs to be restarted, but systemctl restart sshd won't restart it as long you are connected, I see 2 options:
    • schedule systemctl restart sshd using at/cron/systemd timers
    • restart SSH using another remote (secure) shell such as mosh
  • running screen/tmux may also block services like SSH from restarting, the easiest way is to close these sessions before restarting services
  • as told in a previous answer, logout/login may be needed, especially for graphical sessions
  • 1
    would you mind to improve the answer explaining how kexec is used? – Rui F Ribeiro Nov 16 '15 at 10:28
0

An easy way is to compare the version of the running kernel to the latest kernel on disk. I found a script that can do that easily.

As I have several kernels installed, I modified the script to check only the one corresponding to the running kernel. For example, I currently have versions 4.9.79 and 4.14.16 installed and thus need to check /boot/vmlinuz-4.14-x86_64. Unfortunately this won't work when I start using version 5.1, so an update will be needed (replace 4 by 3) or I need to find a more robust way.

Here is my script:

#!/bin/sh
NEXTLINE=0
FIND=""
CURRENT_KERNEL=`uname -r`
KERNEL_PATH="/boot/vmlinuz-${CURRENT_KERNEL:0:4}"
for I in `file $KERNEL_PATH*`; do
  if [ ${NEXTLINE} -eq 1 ]; then
    FIND="${I}"
    NEXTLINE=0
   else
    if [ "${I}" = "version" ]; then NEXTLINE=1; fi
  fi
done
    if [ ! "${FIND}" = "" ]; then
      if [ ! "${CURRENT_KERNEL}" = "${FIND}" ]; then
    echo "Boot required"
  else echo "No boot required"
  fi
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.