Commit fea3a0d5 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[LIMA_LAUNCHER] Add setup_script and ssh_agent environment options

parent b4515324
......@@ -74,40 +74,51 @@ class Environment:
cpu_affinity['config_file'].__exit__(*args)
def run_system_cmd(self, target, *args):
cmd = []
cmd_list = []
cpu_affinity = self.cpu_affinity
if cpu_affinity['config_fname']:
cmd += [cpu_affinity[x] for x in ('script', 'config_fname')]
cmd += [target] + list(args)
shell = False
cmd_list += [cpu_affinity[x] for x in ('script', 'config_fname')]
cmd_list += [target] + list(args)
def shell_str(s):
if not ("'" in s or '"' in s or ' ' in s):
return s
s = ''.join([r'\"' if x == '"' else x for x in s])
return f'"{s}"'
cmd = ' '.join([shell_str(x) for x in cmd_list])
ld_preload = self.config.get('ld_preload', '')
if ld_preload:
if os.path.exists(ld_preload) and os.access(ld_preload, os.X_OK):
if not shell:
cmd = ' '.join(cmd)
cmd = f'LD_PRELOAD={ld_preload} {cmd}'
shell = True
else:
print(f'Warning: error in EXEC access to {ld_preload}')
script = self.config.get('setup_script', {})
if script:
cmd = f'. {script} && {cmd}'
conda = self.config.get('conda', {})
if conda:
conda_base = conda.get('base', '')
env = conda.get('environment', '')
if conda_base and env:
if not shell:
cmd = ' '.join(cmd)
activate = os.path.join(conda_base, 'bin/activate')
cmd = f'. {activate} {env} && {cmd}'
shell = True
else:
print(f'Warning: missing conda base/environment')
cmd_str = cmd if shell else ' '.join(cmd)
cmd = ['bash', '-c', cmd_str] if shell else cmd
print(f'Executing: {cmd_str} ...')
return subprocess.run(cmd)
cmd = ['bash', '-c', cmd]
ssh_agent = self.config.get('ssh_agent', False)
if ssh_agent:
cmd.insert(0, 'ssh-agent')
print('Executing:', ' '.join(cmd), '...')
sys.stdout.flush()
global running_proc
running_proc = subprocess.Popen(cmd)
running_proc.communicate()
return running_proc
def get_tango_json_config(server, instance):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment