Package actions :: Module reboot
[hide private]
[frames] | no frames]

Source Code for Module actions.reboot

 1  #!/usr/bin/python2 
 2   
 3  # Client code for Update Agent 
 4  # Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2. 
 5  # 
 6  # Author: Adrian Likins <alikins@redhat.com 
 7  # 
 8   
 9  import os 
10   
11  __rhnexport__ = [ 
12      'reboot'] 
13   
14  from up2date_client import up2dateLog 
15  from up2date_client import config 
16   
17  cfg = config.initUp2dateConfig() 
18  log = up2dateLog.initLog() 
19   
20  # action version we understand 
21  ACTION_VERSION = 2 
22   
23 -def reboot(test=None, cache_only=None):
24 if cache_only: 25 return (0, "no-ops for caching", {}) 26 27 if cfg['noReboot']: 28 return (38, "Up2date is configured not to allow reboots", {}) 29 30 pid = os.fork() 31 data = {'version': '0'} 32 reboot_message = 'Reboot of system "' + os.uname()[1] + '" initiated by Spacewalk reboot action.' 33 if not pid: 34 try: 35 if test: 36 os.execvp("/sbin/shutdown", ['/sbin/shutdown','-r','-k', '+3', reboot_message]) 37 else: 38 os.execvp("/sbin/shutdown", ['/sbin/shutdown','-r', '+3', reboot_message]) 39 except OSError: 40 data['name'] = "reboot.reboot.shutdown_failed" 41 return (34, "Could not execute /sbin/shutdown", data) 42 43 log.log_me("Rebooting the system now") 44 # no point in waiting around 45 46 return (0, "Reboot sucessfully started", data)
47 48
49 -def main():
50 print(reboot(test=1))
51 52 if __name__ == "__main__": 53 main() 54