done prettifying
[bootmanager.git] / source / steps / StopRunlevelAgent.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2003 Intel Corporation
4 # All rights reserved.
5 #
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
7 # All rights reserved.
8
9
10 import os
11
12 from Exceptions import *
13 import BootAPI
14
15
16 def Run(vars, log):
17     """
18         Stop the RunlevelAgent.py script.  Should proceed
19         kexec to reset run_level to 'boot' before kexec
20     """
21
22     log.write("\n\nStep: Stopping RunlevelAgent.py\n")
23
24     try:
25         cmd = "{}/RunlevelAgent.py".format(vars['BM_SOURCE_DIR'])
26         # raise error if script is not present.
27         os.stat(cmd)
28         os.system("/usr/bin/python {} stop".format(cmd))
29     except KeyError as var:
30         raise BootManagerException("Missing variable in vars: {}\n".format(var))
31     except ValueError as var:
32         raise BootManagerException("Variable in vars, shouldn't be: {}\n".format(var))
33
34     try:
35         update_vals = {}
36         update_vals['run_level'] = 'boot'
37         BootAPI.call_api_function(vars, "ReportRunlevel", (update_vals,))
38     except BootManagerException as e:
39         log.write("Unable to update boot state for this node at PLC: {}.\n".format(e))
40
41     return 1
42     
43