The runsics.py --dev option should launch SICS under the current user.
This commit is contained in:
@ -9,6 +9,7 @@ import shlex
|
||||
import argparse
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
from runsics_def import *
|
||||
|
||||
# Re-open stdout unbuffered because we want to see feedback live as it happens.
|
||||
@ -33,6 +34,16 @@ inst_test_sockoffset = {
|
||||
'bilby': 1000
|
||||
}
|
||||
|
||||
deflt_dir = '/usr/local/sics/server'
|
||||
deflt_sockoffset = 'none'
|
||||
deflt_user = inst_user
|
||||
sics_killer = 'root'
|
||||
sics_checker = inst_user
|
||||
if os.environ.has_key('TEST_SICS'):
|
||||
deflt_test = os.environ['TEST_SICS']
|
||||
else:
|
||||
deflt_test = 'none'
|
||||
|
||||
def sics_preexec():
|
||||
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
|
||||
os.umask(0022)
|
||||
@ -47,7 +58,7 @@ def start_cmd(server, args):
|
||||
else:
|
||||
soffset = ''
|
||||
sicsenv = {
|
||||
'none': '',
|
||||
'none': None,
|
||||
'fullsim': 'SICS_SIMULATION=full%s' % soffset,
|
||||
'fakedev': 'SICS_SIMULATION=fakedev%s' % soffset,
|
||||
'scriptval': 'SICS_SIMULATION=script_validator%s' % soffset
|
||||
@ -81,16 +92,25 @@ def stop_cmd(server, args):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.sendto( INTMSG + '\n\r', ('localhost', int_port) )
|
||||
sock.close()
|
||||
if status_cmd(server, args):
|
||||
for n in range(3):
|
||||
print 'Waiting'
|
||||
time.sleep(1)
|
||||
if status_cmd(server, args):
|
||||
continue
|
||||
else:
|
||||
break
|
||||
print ''
|
||||
if status_cmd(server, args):
|
||||
print 'Failed to stop %s' % server
|
||||
print "Fragging PID %d with default KILL" % (pid)
|
||||
subprocess.call(shlex.split('sudo -u root /bin/kill %d' % (pid)))
|
||||
subprocess.call(shlex.split('sudo -u %s /bin/kill %d' % (sics_killer, pid)))
|
||||
else:
|
||||
return
|
||||
if status_cmd(server, args):
|
||||
print 'Failed again!'
|
||||
print "Terminating PID %d with EXTREME PREJUDICE (-15)" % (pid)
|
||||
subprocess.call(shlex.split('sudo -u root /bin/kill -15 %d' % (pid)))
|
||||
subprocess.call(shlex.split('sudo -u %s /bin/kill -15 %d' % sics_killer, (pid)))
|
||||
else:
|
||||
return
|
||||
if status_cmd(server, args):
|
||||
@ -103,7 +123,7 @@ def status_cmd(server, args):
|
||||
sock = server_port[server]['server']
|
||||
else:
|
||||
sock = server_port[server]['server'] + inst_test_sockoffset[args.sockoffset]
|
||||
status_cmd = 'sudo -u %s netstat -nltp' % 'root'
|
||||
status_cmd = 'sudo -u %s netstat -nltp' % sics_checker
|
||||
netstat_str, err = subprocess.Popen(shlex.split(status_cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
# ffr: We can replace the previous Popen().communicate() line with the following two lines if Python is upgraded to V2.7
|
||||
# with open(os.devnull) as fp:
|
||||
@ -120,15 +140,10 @@ def status_cmd(server, args):
|
||||
return ''
|
||||
|
||||
def main(**kwargs):
|
||||
global sics_killer, sics_checker
|
||||
|
||||
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_test = os.environ['TEST_SICS']
|
||||
else:
|
||||
deflt_test = 'none'
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser( description='SICS Server startup script.' )
|
||||
cmd_grp = parser.add_argument_group('Commands', 'Runsics commands')
|
||||
@ -146,17 +161,20 @@ def main(**kwargs):
|
||||
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:
|
||||
args.sicsonly = False
|
||||
elif args.dev:
|
||||
args.sicsonly = True
|
||||
# By default don't launch script validator in development environments.
|
||||
if args.dev:
|
||||
if args.scriptval:
|
||||
args.sicsonly = False
|
||||
else:
|
||||
args.sicsonly = True
|
||||
args.sockoffset = inst_name
|
||||
args.user = getpass.getuser()
|
||||
sics_killer = getpass.getuser()
|
||||
sics_checker = getpass.getuser()
|
||||
if (args.test == 'none'):
|
||||
args.test = 'fullsim'
|
||||
if (args.dir == deflt_dir):
|
||||
args.dir = './'
|
||||
args.user = getpass.getuser()
|
||||
# Launch SICS
|
||||
if (args.sicsonly):
|
||||
runsics_cmd[args.cmd]('sics', args)
|
||||
|
Reference in New Issue
Block a user