-
-
Notifications
You must be signed in to change notification settings - Fork 414
[WIP] Add RebootRequired fact for detecting system reboot needs #1310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Changes from all commits
ac84b59
c5fd309
7cfa239
f114972
5b5e618
83377a1
adffeb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -899,3 +899,52 @@ def process(self, output): | |||||||
) | ||||||||
|
||||||||
return limits | ||||||||
|
||||||||
|
||||||||
class RebootRequired(FactBase[bool]): | ||||||||
""" | ||||||||
Returns a boolean indicating whether the system requires a reboot. | ||||||||
|
||||||||
On Linux systems: | ||||||||
- Checks /var/run/reboot-required and /var/run/reboot-required.pkgs | ||||||||
- On Alpine Linux, compares installed kernel with running kernel | ||||||||
|
||||||||
On FreeBSD systems: | ||||||||
- Compares running kernel version with installed kernel version | ||||||||
""" | ||||||||
|
||||||||
def command(self) -> str: | ||||||||
return """ | ||||||||
# Get OS type | ||||||||
OS_TYPE=$(uname -s) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, the problem of facts being unable to call each other. Unfortunately I think this is the best way we can currently do this. |
||||||||
|
||||||||
if [ "$OS_TYPE" = "Linux" ]; then | ||||||||
# Check if it's Alpine Linux | ||||||||
if [ -f /etc/alpine-release ]; then | ||||||||
RUNNING_KERNEL=$(uname -r) | ||||||||
INSTALLED_KERNEL=$(ls -1 /lib/modules | sort -V | tail -n1) | ||||||||
if [ "$RUNNING_KERNEL" != "$INSTALLED_KERNEL" ]; then | ||||||||
echo "reboot_required" | ||||||||
exit 0 | ||||||||
fi | ||||||||
else | ||||||||
# Check standard Linux reboot required files | ||||||||
if [ -f /var/run/reboot-required ] || [ -f /var/run/reboot-required.pkgs ]; then | ||||||||
echo "reboot_required" | ||||||||
exit 0 | ||||||||
fi | ||||||||
fi | ||||||||
elif [ "$OS_TYPE" = "FreeBSD" ]; then | ||||||||
RUNNING_VERSION=$(freebsd-version -r) | ||||||||
INSTALLED_VERSION=$(freebsd-version -k) | ||||||||
if [ "$RUNNING_VERSION" != "$INSTALLED_VERSION" ]; then | ||||||||
echo "reboot_required" | ||||||||
exit 0 | ||||||||
fi | ||||||||
fi | ||||||||
|
||||||||
echo "no_reboot_required" | ||||||||
""" | ||||||||
|
||||||||
def process(self, output) -> bool: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return list(output)[0].strip() == "reboot_required" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"command": "\n# Get OS type\nOS_TYPE=$(uname -s)\n\nif [ \"$OS_TYPE\" = \"Linux\" ]; then\n # Check if it's Alpine Linux\n if [ -f /etc/alpine-release ]; then\n RUNNING_KERNEL=$(uname -r)\n INSTALLED_KERNEL=$(ls -1 /lib/modules | sort -V | tail -n1)\n if [ \"$RUNNING_KERNEL\" != \"$INSTALLED_KERNEL\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\n else\n # Check standard Linux reboot required files\n if [ -f /var/run/reboot-required ] || [ -f /var/run/reboot-required.pkgs ]; then\n echo \"reboot_required\"\n exit 0\n fi\n fi\nelif [ \"$OS_TYPE\" = \"FreeBSD\" ]; then\n RUNNING_VERSION=$(freebsd-version -r)\n INSTALLED_VERSION=$(freebsd-version -k)\n if [ \"$RUNNING_VERSION\" != \"$INSTALLED_VERSION\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\nfi\n\necho \"no_reboot_required\"\n", | ||
"output": [ | ||
"reboot_required" | ||
], | ||
"fact": true, | ||
"setup": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this key does anything? |
||
["touch", "/etc/alpine-release"], | ||
["uname", "-r", "5.15.0-1-alpine"], | ||
["mkdir", "-p", "/lib/modules"], | ||
["touch", "/lib/modules/5.15.0-2-alpine"] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"command": "\n# Get OS type\nOS_TYPE=$(uname -s)\n\nif [ \"$OS_TYPE\" = \"Linux\" ]; then\n # Check if it's Alpine Linux\n if [ -f /etc/alpine-release ]; then\n RUNNING_KERNEL=$(uname -r)\n INSTALLED_KERNEL=$(ls -1 /lib/modules | sort -V | tail -n1)\n if [ \"$RUNNING_KERNEL\" != \"$INSTALLED_KERNEL\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\n else\n # Check standard Linux reboot required files\n if [ -f /var/run/reboot-required ] || [ -f /var/run/reboot-required.pkgs ]; then\n echo \"reboot_required\"\n exit 0\n fi\n fi\nelif [ \"$OS_TYPE\" = \"FreeBSD\" ]; then\n RUNNING_VERSION=$(freebsd-version -r)\n INSTALLED_VERSION=$(freebsd-version -k)\n if [ \"$RUNNING_VERSION\" != \"$INSTALLED_VERSION\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\nfi\n\necho \"no_reboot_required\"\n", | ||
"output": [ | ||
"reboot_required" | ||
], | ||
"fact": true, | ||
"setup": [ | ||
["uname", "-s", "FreeBSD"], | ||
["freebsd-version", "-r", "13.2-RELEASE"], | ||
["freebsd-version", "-k", "13.2-RELEASE-p1"] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"command": "\n# Get OS type\nOS_TYPE=$(uname -s)\n\nif [ \"$OS_TYPE\" = \"Linux\" ]; then\n # Check if it's Alpine Linux\n if [ -f /etc/alpine-release ]; then\n RUNNING_KERNEL=$(uname -r)\n INSTALLED_KERNEL=$(ls -1 /lib/modules | sort -V | tail -n1)\n if [ \"$RUNNING_KERNEL\" != \"$INSTALLED_KERNEL\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\n else\n # Check standard Linux reboot required files\n if [ -f /var/run/reboot-required ] || [ -f /var/run/reboot-required.pkgs ]; then\n echo \"reboot_required\"\n exit 0\n fi\n fi\nelif [ \"$OS_TYPE\" = \"FreeBSD\" ]; then\n RUNNING_VERSION=$(freebsd-version -r)\n INSTALLED_VERSION=$(freebsd-version -k)\n if [ \"$RUNNING_VERSION\" != \"$INSTALLED_VERSION\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\nfi\n\necho \"no_reboot_required\"\n", | ||
"output": [ | ||
"no_reboot_required" | ||
], | ||
"fact": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"command": "\n# Get OS type\nOS_TYPE=$(uname -s)\n\nif [ \"$OS_TYPE\" = \"Linux\" ]; then\n # Check if it's Alpine Linux\n if [ -f /etc/alpine-release ]; then\n RUNNING_KERNEL=$(uname -r)\n INSTALLED_KERNEL=$(ls -1 /lib/modules | sort -V | tail -n1)\n if [ \"$RUNNING_KERNEL\" != \"$INSTALLED_KERNEL\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\n else\n # Check standard Linux reboot required files\n if [ -f /var/run/reboot-required ] || [ -f /var/run/reboot-required.pkgs ]; then\n echo \"reboot_required\"\n exit 0\n fi\n fi\nelif [ \"$OS_TYPE\" = \"FreeBSD\" ]; then\n RUNNING_VERSION=$(freebsd-version -r)\n INSTALLED_VERSION=$(freebsd-version -k)\n if [ \"$RUNNING_VERSION\" != \"$INSTALLED_VERSION\" ]; then\n echo \"reboot_required\"\n exit 0\n fi\nfi\n\necho \"no_reboot_required\"\n", | ||
"output": [ | ||
"reboot_required" | ||
], | ||
"fact": true, | ||
"setup": [ | ||
["touch", "/var/run/reboot-required"] | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.