mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Add support for OpenBSD (#46147)
This commit is contained in:
2
changelogs/fragments/reboot_openbsd_support.yaml
Normal file
2
changelogs/fragments/reboot_openbsd_support.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- reboot - add support for OpenBSD
|
||||||
@@ -20,7 +20,7 @@ options:
|
|||||||
pre_reboot_delay:
|
pre_reboot_delay:
|
||||||
description:
|
description:
|
||||||
- Seconds for shutdown to wait before requesting reboot.
|
- Seconds for shutdown to wait before requesting reboot.
|
||||||
- On Linux and macOS, this is converted to minutes and rounded down. If less than 60, it will be set to 0.
|
- On Linux, macOS and OpenBSD, this is converted to minutes and rounded down. If less than 60, it will be set to 0.
|
||||||
- On Solaris and FreeBSD, this will be seconds.
|
- On Solaris and FreeBSD, this will be seconds.
|
||||||
default: 0
|
default: 0
|
||||||
type: int
|
type: int
|
||||||
|
|||||||
@@ -42,18 +42,24 @@ class ActionModule(ActionBase):
|
|||||||
|
|
||||||
DEPRECATED_ARGS = {}
|
DEPRECATED_ARGS = {}
|
||||||
|
|
||||||
|
BOOT_TIME_COMMANDS = {
|
||||||
|
'openbsd': "/sbin/sysctl kern.boottime",
|
||||||
|
}
|
||||||
|
|
||||||
SHUTDOWN_COMMANDS = {
|
SHUTDOWN_COMMANDS = {
|
||||||
'linux': DEFAULT_SHUTDOWN_COMMAND,
|
'linux': DEFAULT_SHUTDOWN_COMMAND,
|
||||||
'freebsd': DEFAULT_SHUTDOWN_COMMAND,
|
'freebsd': DEFAULT_SHUTDOWN_COMMAND,
|
||||||
'sunos': '/usr/sbin/shutdown',
|
'sunos': '/usr/sbin/shutdown',
|
||||||
'darwin': '/sbin/shutdown',
|
'darwin': '/sbin/shutdown',
|
||||||
|
'openbsd': DEFAULT_SHUTDOWN_COMMAND,
|
||||||
}
|
}
|
||||||
|
|
||||||
SHUTDOWN_COMMAND_ARGS = {
|
SHUTDOWN_COMMAND_ARGS = {
|
||||||
'linux': '-r {delay_min} "{message}"',
|
'linux': '-r {delay_min} "{message}"',
|
||||||
'freebsd': '-r +{delay_sec}s "{message}"',
|
'freebsd': '-r +{delay_sec}s "{message}"',
|
||||||
'sunos': '-y -g {delay_sec} -r "{message}"',
|
'sunos': '-y -g {delay_sec} -r "{message}"',
|
||||||
'darwin': '-r +{delay_min_macos} "{message}"'
|
'darwin': '-r +{delay_min_macos} "{message}"',
|
||||||
|
'openbsd': '-r +{delay_min} "{message}"',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -96,7 +102,13 @@ class ActionModule(ActionBase):
|
|||||||
def get_system_boot_time(self):
|
def get_system_boot_time(self):
|
||||||
stdout = u''
|
stdout = u''
|
||||||
stderr = u''
|
stderr = u''
|
||||||
command_result = self._low_level_execute_command(self.DEFAULT_BOOT_TIME_COMMAND, sudoable=self.DEFAULT_SUDOABLE)
|
|
||||||
|
# Determine the system distribution in order to use the correct shutdown command arguments
|
||||||
|
uname_result = self._low_level_execute_command('uname')
|
||||||
|
distribution = uname_result['stdout'].strip().lower()
|
||||||
|
|
||||||
|
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
|
# 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.
|
# launched by systemd, the update of utmp/wtmp is not done correctly.
|
||||||
|
|||||||
Reference in New Issue
Block a user