Skip to content

Commit

Permalink
osi functions enhancements and adds
Browse files Browse the repository at this point in the history
Refs to rockstor#735 rockstor#1306 rockstor#1036
system_shutdown and system_reboot run with a delta, default to now when
running from user input from WebUi and 3 mins when called via scheduled tasks
Added system_suspend function just running a systemctl suspend
Added wakeup functions set_system_rtc_wake and clean_system_rtc_wake:
set_system_rtc_wake is our core function to set system wakeup, writing to default
rtc0 wakealarm user wakeup time in epoch format, after flushing every wakeup value
with clean_system_rtc_wake (write 0 to clean every time or we raise a resurce busy err)
IMPORTANT: epoch can't be passed as a string, needed int -> write('%s' % epoch) fails

Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
  • Loading branch information
MFlyer committed Feb 28, 2017
1 parent 03e6616 commit b2721f3
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/rockstor/system/osi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
UDEVADM = '/usr/sbin/udevadm'
UMOUNT = '/bin/umount'
WIPEFS = '/usr/sbin/wipefs'
RTC_WAKE_FILE = '/sys/class/rtc/rtc0/wakealarm'

Disk = collections.namedtuple('Disk',
'name model serial size transport vendor '
Expand Down Expand Up @@ -1065,16 +1066,37 @@ def get_virtio_disk_serial(device_name):


def system_shutdown(delta='now'):
# new delta param default to now used to pass a 2 min delay
# New delta param default to now used to pass a 2 min delay
# for scheduled tasks reboot/shutdown
return run_command([SHUTDOWN, '-h', delta])


def system_reboot(delta='now'):
# new delta param default to now used to pass a 2 min delay
# New delta param default to now used to pass a 2 min delay
# for scheduled tasks reboot/shutdown
return run_command([SHUTDOWN, '-r', delta])

def system_suspend():
# This function perform system suspend to RAM via systemctl
# while reboot and shutdown, both via shutdown command, can be delayed
# systemctl suspend miss this option
return run_command([SYSTEMCTL_BIN, 'suspend'])

def clean_system_rtc_wake():
# Every time we write to rtc alarm file this get locked and
# we have to clean it with a 0 before writing another epoch
with open(RTC_WAKE_FILE, 'w') as rtc:
rtc.write('%d' % 0)

def set_system_rtc_wake(wakeup_epoch):
# This new function receive desired current and wake up time
# and set right epoch time to rtc alarm file.
# Epoch wake up time evaluated on every shutdown scheduled task
clean_system_rtc_wake()
with open(RTC_WAKE_FILE, 'w') as rtc:
rtc.write('%d' % int(wakeup_epoch))
return None


def md5sum(fpath):
# return the md5sum of the given file
Expand Down

0 comments on commit b2721f3

Please sign in to comment.