Should I restart after a pacman upgrade?

after running

sudo pacman -Syyu

or

sudo pacman -S [something to install]

should I restart just to be safe?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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 [email protected] 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

Method 3

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.

Method 4

https://github.com/tylerjl/overdue:

Overdue is a pacman post-transaction hook that looks for running daemons that reference deleted shared library file handles and notifies you about them. It’s a simple shell script that makes no changes to your system, and lists all relevant units for easy reference.

It uses lsof underneath, and it’s currently available in the AUR.

Method 5

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

Method 6

needrestart exists to answer that question, so install it with yay needrestart.

needrestart 3.6 - Restart daemons after library updates.

Authors:
  Thomas Liske <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98d919694988ab99f90988a9296d4978ed7979c8d">[email protected]</a>>

Copyright Holder:
  2013 - 2022 (C) Thomas Liske [http://fiasko-nw.net/~thomas/]

Upstream:
  https://github.com/liske/needrestart

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Usage:

  needrestart [-vn] [-c <cfg>] [-r <mode>] [-f <fe>] [-u <ui>] [-bkl]

    -v      be more verbose
    -q      be quiet
    -m <mode>   set detail level
    e   (e)asy mode
    a   (a)dvanced mode
    -n      set default answer to 'no'
    -c <cfg>    config filename
    -r <mode>   set restart mode
    l   (l)ist only
    i   (i)nteractive restart
    a   (a)utomatically restart
    -b      enable batch mode
    -p          enable nagios plugin mode
    -f <fe> override debconf frontend (DEBIAN_FRONTEND, debconf(7))
    -t <seconds> tolerate interpreter process start times within this value
    -u <ui>     use preferred UI package (-u ? shows available packages)

  By using the following options only the specified checks are performed:
    -k          check for obsolete kernel
    -l          check for obsolete libraries
    -w          check for obsolete CPU microcode

    --help      show this help
    --version   show version information


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x