def update()

in nodemanager/scripts/setup.py [0:0]


def update():
	if len(sys.argv) > 2:
		Usage()
		sys.exit(1)

	setup_dir = os.path.dirname(os.path.abspath(__file__))
	if os.path.samefile(setup_dir, InstallRoot):
		Log("Nothing to update")
		sys.exit(1)

	srcpkg = os.path.join(setup_dir, 'hpcnodeagent.tar.gz')
	if not os.path.isfile(srcpkg):
		Log("Nothing to update: hpcnodeagent.tar.gz not found")
		sys.exit(1)

	if not is_hpcagent_installed():
		Log("No hpc agent installed")
		sys.exit(1)

	pemfile = os.path.join(InstallRoot, "certs/nodemanager.pem")
	rsakeyfile = os.path.join(InstallRoot, "certs/nodemanager_rsa.key")
	if not os.path.isfile(pemfile) or not os.path.isfile(rsakeyfile):
		Log("No certificates configured")
		sys.exit(1)

	configfile = os.path.join(InstallRoot, 'nodemanager.json')
	if not os.path.isfile(configfile):
		Log("nodemanager.json not found")
		sys.exit(1)

	Log("Stop the hpc node agent")
	if SupportSystemd:
		Run("systemctl stop hpcagent", chk_err=False)
	else:
		Run("service hpcagent stop", chk_err=False)

	with open(configfile, 'r') as F:
		configjson = json.load(F)

	Log("Update the binaries")
	extract_hpcagent_files(srcpkg)
	ReplaceFileContentsAtomic(configfile, json.dumps(configjson))
	os.chmod(configfile, 0o644)
	if UseSystemdServiceUnit:
		shutil.move(os.path.join(InstallRoot, "hpcagent.service"), "/etc/systemd/system/hpcagent.service")
		Run("systemctl daemon-reload")
	else:
		shutil.move(os.path.join(InstallRoot, "hpcagent.sh"), "/etc/init.d/hpcagent")

	Log("restart hpcagent")
	if SupportSystemd:
		Run("systemctl restart hpcagent")
	else:
		Run("service hpcagent restart")
	Log("hpc agent updated")