Skip to content
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

Always use /proc/sys/kernel/random/boot_id to confirm reboot on Linux #47017

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/reboot-change-default-boot-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- reboot - change default reboot time command to prevent hanging on certain systems (https://github.com/ansible/ansible/issues/46562)
25 changes: 6 additions & 19 deletions lib/ansible/plugins/action/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ class ActionModule(ActionBase):
DEFAULT_PRE_REBOOT_DELAY = 0
DEFAULT_POST_REBOOT_DELAY = 0
DEFAULT_TEST_COMMAND = 'whoami'
DEFAULT_BOOT_TIME_COMMAND = 'who -b'
DEFAULT_BOOT_TIME_COMMAND = 'cat /proc/sys/kernel/random/boot_id'
DEFAULT_REBOOT_MESSAGE = 'Reboot initiated by Ansible'
DEFAULT_SHUTDOWN_COMMAND = 'shutdown'
DEFAULT_SUDOABLE = True

DEPRECATED_ARGS = {}

BOOT_TIME_COMMANDS = {
'openbsd': "/sbin/sysctl kern.boottime",
'openbsd': '/sbin/sysctl kern.boottime',
'freebsd': '/sbin/sysctl kern.boottime',
'sunos': 'who -b',
'darwin': 'who -b',
}

SHUTDOWN_COMMANDS = {
'linux': DEFAULT_SHUTDOWN_COMMAND,
'freebsd': DEFAULT_SHUTDOWN_COMMAND,
'openbsd': DEFAULT_SHUTDOWN_COMMAND,
'sunos': '/usr/sbin/shutdown',
'darwin': '/sbin/shutdown',
'openbsd': DEFAULT_SHUTDOWN_COMMAND,
}

SHUTDOWN_COMMAND_ARGS = {
Expand Down Expand Up @@ -110,22 +113,6 @@ def get_system_boot_time(self):
boot_time_command = self.BOOT_TIME_COMMANDS.get(distribution, self.DEFAULT_BOOT_TIME_COMMAND)
command_result = self._low_level_execute_command(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:
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']
Expand Down