Compare commits

..

6 Commits

Author SHA1 Message Date
3f97a899f3 Merge pull request 'fix(script): Trigger restart only on FDs for binaries (#3)' (#4) from 3/fix-3-only-reboot-when-binaries-change into main
Reviewed-on: #4

Closes #3
2024-06-19 18:17:55 +00:00
3efdf550f9 fix(script): Trigger restart only on FDs for binaries (#3)
Rename variable and its echo output headline to something that
implies we're talking about binaries specifically, not all files.

Also add an awk condition that only outputs an lsof line if lsof
showed a file descriptor to a path somewhere in a /bin/ or /sbin/
directory. As a good enough approximation this will help us trigger a
system reboot when something in /usr/bin/foo or /usr/local/sbin/bar
was deleted while at the same time vastly reducing the amount of
unnecessary system reboots for random /memfd anonymous files and
shared memory objects in /dev/shm.

An awk program has multiple repetitions of 'condition { action }'
where the action is literally written inside curly braces.

Replace the pseudo-condition '1' (i.e. something that is always
truthy) with '$(NF-1) ~ /\/s?bin\//'.

To break it down the new condition is:

  - If the second to last field in a line ...
    $(NF-1)

  - Matches an expression ...
    $(NF-1) ~ /expression/

  - That is /s?bin/ ...
    /s?bin/

Then we want to do '{ action }' which will still print affected file
descriptors as before. An awk expression is encapsulated in a slash
pair like so: '/expression/'. We want to search for any string that
contains literal slashes like so: '/s?bin/'. We unfortunately have
to escape the slashes we want to find to make sure awk doesn't treat
them as the end of its awk expression string:

                      +------+------ Backslash-escape here
                      v      v
  - Right: $(NF-1) ~ /\/s?bin\//
  - Wrong: $(NF-1) ~ //s?bin//

The expression 's?' is probably self-explanatory. An awk expression
is related to a regular expression but not identical to it. Still, a
question mark means the same thing as in a PERL-compatible regular
expression, the preceding character is optional: we want either one
of '/sbin/' or '/bin/'.
2024-06-19 20:16:37 +02:00
dbcd6c3d3a Merge pull request 'feat/1-restart-check-on-open-file-desciptors-of-deleted-files' (#2) from feat/1-restart-check-on-open-file-desciptors-of-deleted-files into main
Reviewed-on: #2
2024-06-07 15:34:48 +00:00
9b62bcad6c refactor(script): Var name carries arbitrary files (#1) 2024-06-07 17:34:14 +02:00
5ba3bcc15c feat(meta): Add .gitignore (#1) 2024-06-07 17:32:39 +02:00
02ad69bb28 feat(script): Check deleted files held by an open fd (#1) 2024-06-07 17:30:52 +02:00
2 changed files with 87 additions and 0 deletions

80
.gitignore vendored Normal file
View File

@@ -0,0 +1,80 @@
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
.idea

View File

@@ -22,6 +22,13 @@ if [[ -n $libs ]]; then
rc=0
fi
binaries=$(lsof -n +c 0 2> /dev/null | grep -- '(deleted)' | awk '$(NF-1) ~ /\/s?bin\// { print $1 ": " $(NF-1) " " $NF }' | sort -u)
if [[ -n $binaries ]]; then
cat <<< $binaries
echo "# BINARIES: reboot required"
rc=0
fi
active_kernel=$(uname -r)
current_kernel=$(get_boot_kernel)
if [[ $active_kernel != $current_kernel ]]; then