in VMExtension/hpcnodemanager.py [0:0]
def enable():
#Always restart daemon and clear PID file
hutil = parse_context('Enable')
if os.path.isfile(DaemonPidFilePath):
pid = waagent.GetFileContents(DaemonPidFilePath)
if os.path.isdir(os.path.join("/proc", pid)) and _is_nodemanager_daemon(pid):
waagent.Log("Stop old daemon: {0}".format(pid))
os.killpg(int(pid), 9)
os.remove(DaemonPidFilePath)
args = [get_python_executor(), os.path.join(os.getcwd(), __file__), "daemon"]
devnull = open(os.devnull, 'w')
child = subprocess.Popen(args, stdout=devnull, stderr=devnull, preexec_fn=os.setsid)
if child.pid is None or child.pid < 1:
hutil.do_exit(1, 'Enable', 'error', '1',
'Failed to launch HPC Linux node manager daemon')
else:
hutil.save_seq()
waagent.SetFileContents(DaemonPidFilePath, str(child.pid))
#Sleep 3 seconds to check if the process is still running
time.sleep(3)
if child.poll() is None:
waagent.Log("Daemon pid: {0}".format(child.pid))
hutil.do_exit(0, 'Enable', 'success', '0',
'HPC Linux node manager daemon is enabled')
else:
hutil.do_exit(1, 'Enable', 'error', '2',
'Failed to launch HPC Linux node manager daemon')