Skip to content

Commit

Permalink
feat: Check for services that require a post upgrade restart
Browse files Browse the repository at this point in the history
Check if any services need to be restarted after updating and offers to do so (if there are).
The listing of the services is done via `checkservices` from [archlinux/contrib](https://github.com/archlinux/contrib) (available in the [extra] [archlinux-contrib](https://archlinux.org/packages/extra/any/archlinux-contrib/) package).
The `dbus-broker.service` and `systemd-logind.service` services are purposely excluded from the listing as they are known for creating issues on restart (see bus1/dbus-broker#93 & https://askubuntu.com/questions/1057028/ubuntu-18-04-freezes-when-running-systemctl-restart-systemd-logind-service)

Close #181
  • Loading branch information
Antiz96 committed Jul 6, 2024
1 parent 8cb822a commit 4355ab1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Fonctionnalités :
- Vérification et listing automatiques des paquets orphelins et propose de les supprimer.
- Vérification automatique de la présence d'anciens paquets et/ou paquets désinstallés dans le cache et propose de les supprimer.
- Listing et aide au traitement des fichiers pacnew/pacsave.
- Vérification automatique des services nécessitant un redémarrage d'après mise à jour et propose de les redémarrer s'il y en a.
- Vérification automatique des mises à jour du noyau en attente nécessitant un redémarrage et propose de redémarrer s'il y en a une.
- Support de `sudo`, `doas` et `run0`.
- Prise en charge optionnelle des paquets AUR (via `yay` ou `paru`).
Expand All @@ -40,14 +41,14 @@ Fonctionnalités :
### AUR

Installez le paquet AUR [arch-update](https://aur.archlinux.org/packages/arch-update "arch-update AUR package").
Consultez également [la liste des dépendances optionnelles](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=arch-update#n11) dont vous pourriez avoir besoin.
Consultez également la liste des dépendances optionnelles (disponible dans la section ["depuis la source"](#depuis-la-source) ci-dessous) dont vous pourriez avoir besoin.

### Depuis la source

Installez les dépendances requises :

```bash
sudo pacman -S --needed pacman-contrib curl htmlq diffutils hicolor-icon-theme python python-pyqt6 qt6-svg glib2
sudo pacman -S --needed pacman-contrib archlinux-contrib curl htmlq diffutils hicolor-icon-theme python python-pyqt6 qt6-svg glib2
```

Dépendances optionnelles supplémentaires dont vous pourriez avoir besoin ou que vous pourriez souhaiter :
Expand Down Expand Up @@ -179,7 +180,8 @@ Codes de sortie :
7 Aucune mise à jour en attente durant l'utilisation de l'option `-l/--list`
8 Erreur lors de la génération d'un fichier de configuration avec l'option `--gen-config`
9 Erreur lors de la lecture du fichier de configuration avec l'option `--show-config`
10 Erreur lors de la creation du fichier desktop autostart pour l'applet systray avec l'option `--tray --enable`
10 Erreur lors de la creation du fichier desktop autostart pour l'applet systray avec l'option `--tray --enable`
11 Erreur lors du redémarrage des services nécessitant un redémarrage après mise à jour
```

Pour plus d'informations, consultez la page de manuel arch-update(1).
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Features:
- Automatic check and listing of orphan packages and offers to remove them.
- Automatic check for old and/or uninstalled cached packages and offers to remove them.
- Lists and helps you processing pacnew/pacsave files.
- Automatic check for services requiring a post update restart and offers to do so if there are.
- Automatic check for pending kernel updates requiring a reboot to be applied and offers to do so if there's one.
- Support for `sudo`, `doas` & `run0`.
- Optional support for AUR packages (through `yay` or `paru`).
Expand All @@ -40,14 +41,14 @@ Features:
### AUR

Install the [arch-update](https://aur.archlinux.org/packages/arch-update "arch-update AUR package") AUR package.
Also check [the list of optional dependencies](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=arch-update#n11) you might need or want.
See also the list of optional dependencies (available in the ["from source"](#from-source) section below) you may need.

### From Source

Install required dependencies:

```bash
sudo pacman -S --needed pacman-contrib curl htmlq diffutils hicolor-icon-theme python python-pyqt6 qt6-svg glib2
sudo pacman -S --needed pacman-contrib archlinux-contrib curl htmlq diffutils hicolor-icon-theme python python-pyqt6 qt6-svg glib2
```

Additional optional dependencies you might need or want:
Expand Down Expand Up @@ -180,6 +181,7 @@ Exit Codes:
8 Error when generating a configuration file with the `--gen-config` option
9 Error when reading the configuration file with the `--show-config` option
10 Error when creating the autostart desktop file for the systray applet with the `--tray --enable` option
11 Error when restarting services that require a post upgrade restart
```

For more information, see the arch-update(1) man page.
Expand Down
6 changes: 5 additions & 1 deletion doc/man/arch-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If no option is passed, launch the relevant series of functions to perform a com
.br
Before performing the update, it offers to display the latest Arch Linux news to the user. By default, Arch news are only displayed if at least a new one has been published since the last run. Arch news published since the last run or at the same date are tagged as '[NEW]'.
.br
Arch-Update also checks for orphan packages, unused Flatpak packages, old and/or uninstalled cached packages in pacman's cache, pacnew/pacsave files and pending kernel update requiring a reboot to be applied and, if there are, offers to process them.
Arch-Update also checks for orphan packages, unused Flatpak packages, old and/or uninstalled cached packages in pacman's cache, pacnew/pacsave files, services requiring a post update restart as well as pending kernel update requiring a reboot to be applied and, if there are, offers to process them.
.br
Those functions are launched when you click on the systray applet.

Expand Down Expand Up @@ -227,6 +227,10 @@ Error when calling the reboot command to apply a pending kernel update
.B 10
.RB "Error when creating the autostart desktop file for the systray applet with the " "--tray --enable " "option"

.TP
.B 11
Error when restarting services that require a post upgrade restart

.SH SEE ALSO
.BR checkupdates (8),
.BR pacman (8),
Expand Down
6 changes: 5 additions & 1 deletion doc/man/fr/arch-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Si aucune option n'est passée, lance la série de fonctions adéquates pour eff
.br
Avant d'effectuer la mise à jour, propose d'afficher les dernières Arch news à l'utilisateur. Par défaut, les Arch news sont seulement affichées si au moins une nouvelle news a été publiée depuis la dernière exécution. Les Arch news publiées depuis la dernière exécution ou à la même date sont étiquetées comme '[NOUVEAU]'.
.br
Arch-Update vérifie aussi la présence de paquets orphelins/inutilisés, d'anciens paquets mis en cache, de fichiers pacnew/pacsave et de mise à jour du noyau en attente et, s'il y en a, propose de les traiter.
Arch-Update vérifie aussi la présence de paquets orphelins/inutilisés, d'anciens paquets mis en cache, de fichiers pacnew/pacsave, de services nécessitant un redémarrage après mise à jour, ainsi que les mises à jour du noyau en attente et, s'il y en a, propose de les traiter.
.br
Ces fonctions sont lancées quand vous cliquez sur l'applet systray.

Expand Down Expand Up @@ -227,6 +227,10 @@ Erreur lors de l'appel de la commande reboot pour appliquer une mise à jour du
.B 10
.RB "Erreur lors de la création du fichier desktop autostart pour l'applet systray avec l'option " "--tray --enable"

.TP
.B 11
Erreur lors du redémarrage des services nécessitant un redémarrage après mise à jour

.SH VOIR AUSSI
.BR checkupdates (8),
.BR pacman (8),
Expand Down
61 changes: 61 additions & 0 deletions src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,66 @@ pacnew_files() {
fi
}

# Definition of the restart_services function: Verify if any services require a post update restart
restart_services() {
services=$(yes No | sudo checkservices -FP 2> /dev/null | grep ".service" | grep -v -e "dbus-broker.service" -e "systemd-logind.service" | cut -f2 -d "'")
services_num=$(echo "${services}" | wc -l)

if [ -n "${services}" ]; then
if [ "${services_num}" -eq 1 ]; then
main_msg "$(eval_gettext "Services:\nThe following service requires a post upgrade restart\n")"
else
main_msg "$(eval_gettext "Services:\nThe following services require a post upgrade restart\n")"
fi

i=1
while IFS= read -r line; do
echo "${i} - ${line}"
((i=i+1))
done < <(printf '%s\n' "${services}")

ask_msg_array "$(eval_gettext "Select the service(s) to restart (e.g. 1 3 5), select 0 to restart them all or press \"enter\" to continue without restarting the service(s):")"

if [ "${answer_array[0]}" -eq 0 ] 2> /dev/null; then
if ! "${su_cmd}" systemctl restart ${services}; then
error_msg "$(eval_gettext "An error has occurred during service(s) restart\nPlease, verify the above service(s) status\n")" && quit_msg
exit 11
fi
else
array_to_string=$(printf "%s\n" "${answer_array[@]}")
mapfile -t answer_array < <(echo "${array_to_string}" | awk '!seen[$0]++')

for num in "${answer_array[@]}"; do
if [ "${num}" -le "${services_num}" ] 2> /dev/null && [ "${num}" -gt "0" ]; then
service_restarted="y"
service_selected=$(sed -n "${num}"p <<< "${services}")

if "${su_cmd}" systemctl restart "${service_selected}"; then
info_msg "$(eval_gettext "The \${service_selected} service has been successfully restarted")"
else
error_msg "$(eval_gettext "An error occurred during the restart of the \${service_selected} service")"
service_fail="y"
fi
fi
done

if [ -z "${service_fail}" ]; then
echo
info_msg "$(eval_gettext "Service(s) restarted succesfully\n")"
else
echo
error_msg "$(eval_gettext "An error occurred during the service(s) restart\nPlease, verify the status of the above service(s)\n")" && quit_msg
exit 11
fi

if [ -z "${service_restarted}" ]; then
warning_msg "$(eval_gettext "The service(s) restart hasn't been performed\nPlease, consider restarting services that have been updated to fully apply the upgrade\n")"
fi
fi
else
info_msg "$(eval_gettext "No service requiring a post upgrade restart found\n")"
fi
}
# Definition of the kernel_reboot function: Verify if there's a kernel update waiting for a reboot to be applied
kernel_reboot() {
kernel_compare=$(file /boot/vmlinuz* /usr/lib/modules/*/vmlinuz* | sed 's/^.*version\ //' | awk '{print $1}' | grep "$(uname -r)")
Expand Down Expand Up @@ -684,6 +744,7 @@ full_upgrade() {
orphan_packages
packages_cache
pacnew_files
restart_services
kernel_reboot
quit_msg
}
Expand Down

0 comments on commit 4355ab1

Please sign in to comment.