Added --dev option for developers to runsics.py
Also eliminated problems with inheriting environment when running on test and instrument hosts.
This commit is contained in:
@@ -42,28 +42,29 @@ def start_cmd(server, args):
|
||||
if status_cmd(server, args):
|
||||
print '%s is already running. Cowardly refusing to launch it twice' % server
|
||||
return
|
||||
if (args.sockoffset != 'none'):
|
||||
soffset = ':' + str(inst_test_sockoffset[args.sockoffset])
|
||||
else:
|
||||
soffset = ''
|
||||
sicsenv = {
|
||||
'none': None,
|
||||
'fullsim': {'SICS_SIMULATION': 'full'},
|
||||
'fakedev': {'SICS_SIMULATION': 'fakedev'},
|
||||
'scriptval': {'SICS_SIMULATION': 'script_validator'}
|
||||
'fullsim': 'SICS_SIMULATION=full%s' % soffset,
|
||||
'fakedev': 'SICS_SIMULATION=fakedev%s' % soffset,
|
||||
'scriptval': 'SICS_SIMULATION=script_validator%s' % soffset
|
||||
}
|
||||
execenv = os.environ
|
||||
if (args.sockoffset != 'none'):
|
||||
execenv['SOCKOFFSET'] = str(inst_test_sockoffset[args.sockoffset])
|
||||
# Set SICS_SIMULATION environment variable
|
||||
if (server == 'scriptval'):
|
||||
execenv.update(sicsenv['scriptval'])
|
||||
SIMENV = sicsenv['scriptval']
|
||||
else:
|
||||
execenv.update(sicsenv[args.test])
|
||||
start_str = 'sudo -u %s %s/SICServer -d %s' % (args.user, args.dir, args.config)
|
||||
SIMENV = sicsenv[args.test]
|
||||
start_str = 'sudo -u %s %s %s/SICServer -d %s' % (args.user, SIMENV, args.dir, args.config)
|
||||
# print "DEBUG: start_str:%s" % (start_str)
|
||||
# Suppress output if launching the script validator
|
||||
if (server == 'scriptval'):
|
||||
with open(os.devnull) as fp:
|
||||
subprocess.call(shlex.split(start_str), preexec_fn=sics_preexec, env=execenv, cwd=args.dir, stderr=fp, stdout=fp)
|
||||
subprocess.call(shlex.split(start_str), preexec_fn=sics_preexec, cwd=args.dir, stderr=fp, stdout=fp)
|
||||
else:
|
||||
subprocess.call(shlex.split(start_str), preexec_fn=sics_preexec, env=execenv, cwd=args.dir)
|
||||
subprocess.call(shlex.split(start_str), preexec_fn=sics_preexec, cwd=args.dir)
|
||||
status_cmd(server, args)
|
||||
|
||||
def stop_cmd(server, args):
|
||||
@@ -121,16 +122,13 @@ def status_cmd(server, args):
|
||||
def main(**kwargs):
|
||||
runsics_cmd = {'start': start_cmd, 'stop': stop_cmd, 'status': status_cmd}
|
||||
# Setup defaults. Use nice defaults in test environments.
|
||||
deflt_dir = '/usr/local/sics/server'
|
||||
deflt_sockoffset = 'none'
|
||||
deflt_user = inst_user
|
||||
if os.environ.has_key('TEST_SICS'):
|
||||
deflt_user = getpass.getuser()
|
||||
deflt_test = os.environ['TEST_SICS']
|
||||
deflt_dir = './'
|
||||
deflt_sockoffset = inst_name
|
||||
else:
|
||||
deflt_user = inst_user
|
||||
deflt_test = 'none'
|
||||
deflt_dir = '/usr/local/sics/server'
|
||||
deflt_sockoffset = 'none'
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser( description='SICS Server startup script.' )
|
||||
cmd_grp = parser.add_argument_group('Commands', 'Runsics commands')
|
||||
@@ -146,16 +144,21 @@ def main(**kwargs):
|
||||
exc_grp = parser.add_mutually_exclusive_group()
|
||||
exc_grp.add_argument('--sicsonly', help='Just run SICS without the script validator', action='store_true', default=False)
|
||||
exc_grp.add_argument('--scriptval', help='Launch script validator as well as SICServer. Use this to override the default action when the TEST_SICS environmant variable is set.', action='store_true', default=False)
|
||||
exc_grp.add_argument('--dev', help='Launch SICS only in current directory listening on socket %s and with simulation = fullsim' % (server_port['sics']['server'] + inst_test_sockoffset[inst_name]), action='store_true')
|
||||
args = parser.parse_args()
|
||||
# Don't launch script validator in development environments.
|
||||
if args.scriptval:
|
||||
deflt_sicsonly = False
|
||||
elif os.environ.has_key('TEST_SICS'):
|
||||
deflt_sicsonly = True
|
||||
else:
|
||||
deflt_sicsonly = args.sicsonly
|
||||
args.sicsonly = False
|
||||
elif args.dev:
|
||||
args.sicsonly = True
|
||||
args.sockoffset = inst_name
|
||||
if (args.test == 'none'):
|
||||
args.test = 'fullsim'
|
||||
if (args.dir == deflt_dir):
|
||||
args.dir = './'
|
||||
args.user = getpass.getuser()
|
||||
# Launch SICS
|
||||
if (deflt_sicsonly):
|
||||
if (args.sicsonly):
|
||||
runsics_cmd[args.cmd]('sics', args)
|
||||
else:
|
||||
runsics_cmd[args.cmd]('sics', args)
|
||||
|
||||
Reference in New Issue
Block a user