On Sat, Apr 29, 2023 at 5:38 AM Jeffrey Walton <noloa...@gmail.com> wrote: > > I have a script that fully updates a machine each night around 4:00 > AM. It also reboots the machine as required. > > I noticed Debian has checkrestart. The man page is at > https://manpages.debian.org/bullseye/debian-goodies/checkrestart.8.en.html. > I want to ensure I understand "Exit Status" correctly: > > Normally, the program will exit with error (1) if a non-root user tries > to run it. Otherwise, it will always exit with error status 0. > > If the --terse switch is given, the exit code is 1 when there are > deleted open files and 0 when there are none. This is intended for > consumption by Nagios and similar automated monitoring tools. > > I think the script should use --terse, as in: > > if command -v checkrestart >/dev/null 2>&1; > then > if ! checkrestart --terse >/dev/null 2>&1; > then > needs_reboot=1 > fi > fi > > I think using an option like --terse is unusual to get an exit code > that can be used in a script. I want to ensure it is correct. > > My question is, is that usage correct? > > Thanks in advance.
It looks like --terse alone is not enough. It reports files in use, even after a reboot: <QUOTE> # checkrestart -v Found 12 processes using old versions of upgraded files (2 distinct programs) [DEBUG] Process / (PID: 486) List of deleted files in use: / (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308922) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308926) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308928) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308929) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308930) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308933) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308936) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 308937) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 309004) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 309009) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Process /usr/sbin/apache2 (PID: 309126) List of deleted files in use: /var/lib/php/tmp/.ZendSem.koQtBp (deleted) [DEBUG] Running: dpkg-query --search / /usr/sbin/apache2 [DEBUG] Reading line from dpkg-query: apache2-bin: /usr/sbin/apache2 [DEBUG] Found package apache2-bin for program /usr/sbin/apache2 (1 distinct packages) [DEBUG] Running: dpkg-query --listfiles apache2-bin Of these, 1 seem to contain systemd service definitions or init scripts which can be used to restart them. The following packages seem to have definitions that could be used to restart their services: apache2-bin: 308922 /usr/sbin/apache2 308926 /usr/sbin/apache2 308928 /usr/sbin/apache2 308929 /usr/sbin/apache2 308930 /usr/sbin/apache2 308933 /usr/sbin/apache2 308936 /usr/sbin/apache2 308937 /usr/sbin/apache2 309004 /usr/sbin/apache2 309009 /usr/sbin/apache2 309126 /usr/sbin/apache2 These are the initd scripts: service apache2 restart </QUOTE> It looks like `checkrestart -p --terse` is what is needed. Jeff