-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
reboot: Fix typo and support bare Linux systems #45607
Changes from all commits
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 |
---|---|---|
|
@@ -94,18 +94,31 @@ def construct_command(self): | |
return reboot_command | ||
|
||
def get_system_boot_time(self): | ||
stdout = '' | ||
stderr = '' | ||
command_result = self._low_level_execute_command(self.DEFAULT_BOOT_TIME_COMMAND, sudoable=self.DEFAULT_SUDOABLE) | ||
|
||
# For single board computers, e.g., Raspberry Pi, that lack a real time clock and are using fake-hwclock | ||
# launched by systemd, the update of utmp/wtmp is not done correctly. | ||
# Fall back to using uptime -s for those systems. | ||
# https://github.com/systemd/systemd/issues/6057 | ||
if '1970-01-01 00:00' in command_result['stdout']: | ||
stdout += command_result['stdout'] | ||
stderr += command_result['stderr'] | ||
command_result = self._low_level_execute_command('uptime -s', sudoable=self.DEFAULT_SUDOABLE) | ||
|
||
# This is a last resort for bare Linux systems (e.g. OpenELEC) where 'who -b' or 'uptime -s' are not supported. | ||
# Other options like parsing /proc/uptime or default uptime output are less reliable than this | ||
if command_result['rc'] != 0: | ||
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. One issue with this is that The previous conditional which runs This is the point where it would be helpful to have platform/dist as a class attribute, either as an additional check here, or to look up the correct boot time command based on platform/dist. I'm also open to other ideas. 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 mind if a fallback method fails though. As long as we cover all bases so in the end the function always works. For win_reboot it could be a lot easier if we have a list of commands, for both Windows and Unix. 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. In my WIP PR, I did change the "get the last boot time" command to be a variable, so that will remove the hard coding here. Will fix in future™. Still, I can see it being confusing to someone running
Evidently Windows has a 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. Well, the distinction between Windows and Unix is now easy because it's a different entry-point. So we don't need to do a So basically what I am saying is that in general the fallback mechanism is more efficient than targeting based on platform. 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. And yes, PowerShell has aliases for common Unix commands, which is freaking a lot of people out (because they are not drop-in replacements). https://daniel.haxx.se/blog/2016/08/19/removing-the-powershell-curl-alias/ |
||
stdout += command_result['stdout'] | ||
stderr += command_result['stderr'] | ||
command_result = self._low_level_execute_command('cat /proc/sys/kernel/random/boot_id', sudoable=self.DEFAULT_SUDOABLE) | ||
|
||
if command_result['rc'] != 0: | ||
stdout += command_result['stdout'] | ||
stderr += command_result['stderr'] | ||
raise AnsibleError("%s: failed to get host boot time info, rc: %d, stdout: %s, stderr: %s" | ||
% (self._task.action, command_result.rc, to_native(command_result['stdout']), to_native(command_result['stderr']))) | ||
% (self._task.action, command_result['rc'], to_native(stdout), to_native(stderr))) | ||
|
||
return command_result['stdout'].strip() | ||
|
||
|
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.
this might not be py2/py3 compatible, we might want to force bytes
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.
Yes, you are correct. One day I'll master that distinction. 😄