in ansible/roles/slurm/files/scripts/setup.py [0:0]
def run_custom_scripts():
"""run custom scripts based on instance_role"""
custom_dir = dirs.custom_scripts
if lkp.instance_role == "controller":
# controller has all scripts, but only runs controller.d
custom_dirs = [custom_dir / "controller.d"]
elif lkp.instance_role == "compute":
# compute setup with compute.d and nodeset.d
custom_dirs = [custom_dir / "compute.d", custom_dir / "nodeset.d"]
elif lkp.instance_role == "login":
# login setup with only login.d
custom_dirs = [custom_dir / "login.d"]
else:
# Unknown role: run nothing
custom_dirs = []
custom_scripts = [
p
for d in custom_dirs
for p in d.rglob("*")
if p.is_file() and not p.name.endswith(".disabled")
]
print_scripts = ",".join(str(s.relative_to(custom_dir)) for s in custom_scripts)
log.debug(f"custom scripts to run: {custom_dir}/({print_scripts})")
try:
for script in custom_scripts:
if "/controller.d/" in str(script):
timeout = lkp.cfg.get("controller_startup_scripts_timeout", 300)
elif "/compute.d/" in str(script) or "/nodeset.d/" in str(script):
timeout = lkp.cfg.get("compute_startup_scripts_timeout", 300)
elif "/login.d/" in str(script):
timeout = lkp.cfg.get("login_startup_scripts_timeout", 300)
else:
timeout = 300
timeout = None if not timeout or timeout < 0 else timeout
log.info(f"running script {script.name} with timeout={timeout}")
result = run(str(script), timeout=timeout, check=False, shell=True)
runlog = (
f"{script.name} returncode={result.returncode}\n"
f"stdout={result.stdout}stderr={result.stderr}"
)
log.info(runlog)
result.check_returncode()
except OSError as e:
log.error(f"script {script} is not executable")
raise e
except subprocess.TimeoutExpired as e:
log.error(f"script {script} did not complete within timeout={timeout}")
raise e
except Exception as e:
log.error(f"script {script} encountered an exception")
log.exception(e)
raise e