Пример #1
0
def start(name, prio, path, args):
   prio_map = {'sys_high': 99,
               'sys_medium': 93, 
               'sys_low': 92, 
               'app': 91}
   prio = prio_map[prio]
   if args:
      path += ' ' + args
   if validate(name):
      print green('note:') + ' %s is already running' % name
   else:
      print 'starting', blue(name), '...',
      ps = subprocess.Popen(path.split(' '), shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
      ps.stdout.close()
      ps.stderr.close()
      ps.wait()
      prio_fail = False
      if ps.returncode != 0:
         print red('[ERROR: service quit with code ' + str(ps.returncode) + ']')
      else:
         time.sleep(5)
         pid = validate(name)
         if not pid:
            raise Exception('process terminated')
         try:
            sched_set_prio(pid, prio)
         except:
            print red('warning:') + ' could not set process priority'
         print green('[OK]')
Пример #2
0
def start(name, prio, path, args):
    prio_map = {'sys_high': 99, 'sys_medium': 50, 'sys_low': 30, 'app': 0}
    prio = prio_map[prio]
    if args:
        path += ' ' + args
    if validate(name):
        print green('note:') + ' %s is already running' % name
    else:
        print 'starting', blue(name), '...',
        ps = subprocess.Popen(path.split(' '),
                              shell=False,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
        ps.stdout.close()
        ps.stderr.close()
        ps.wait()
        prio_fail = False
        if ps.returncode != 0:
            print red('[ERROR: service quit with code ' + str(ps.returncode) +
                      ']')
        else:
            for _ in range(30):
                time.sleep(0.1)
                try:
                    pid = validate(name)
                except:
                    pass
            if not pid:
                raise Exception('process terminated')
            try:
                sched_set_prio(pid, prio)
            except:
                print red('warning:') + ' could not set process priority'
            print green('[OK]')
Пример #3
0
def stop(name):
   print 'stopping', blue(name), '...',
   pid = validate(name)
   if pid:
      kill(pid)
      while validate(name):
         time.sleep(1.0)
      print green('[OK]')
   else:
      print red('[ERROR: no such process]')
Пример #4
0
def stop(name):
    print 'stopping', blue(name), '...',
    pid = validate(name)
    if pid:
        kill(pid)
        while validate(name):
            time.sleep(1.0)
        print green('[OK]')
    else:
        print red('[ERROR: no such process]')
Пример #5
0
def start(name, path, args):
    if args:
        path += ' ' + args
    if validate(name):
        print green('note:') + ' %s is already running' % name
    else:
        print 'starting', blue(name), '...',
        try:
            print path,
            ps = subprocess.Popen(path.split(' '),
                                  shell=False,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
            ps.stdout.close()
            ps.stderr.close()
            ps.wait()
            if ps.returncode != 0:
                print red('[ERROR: service quit with code ' +
                          str(ps.returncode) + ']')
            else:
                print green('[OK]')
        except Exception as e:
            print red('[ERROR]: ' + str(e))
Пример #6
0
 def show(self, root):
     if not isinstance(root, Node):
         return 
     
     os.system('clear')
     print "========%s============" % root.name
     lines = [item.display() for item in root]
     header = list_header()
     for i, line in enumerate(lines):
         context =  "%s %s" % (header.next(), line)
         if i%2  == 0:
             context = termcolor.blue(context)
         else:
             context = termcolor.red(context)
         print(context)
Пример #7
0
   return list


def start_order(name):
   topo = toposort()
   ordered = []
   deps = set(calc_deps(name))
   for level in [x for x in toposort()]:
      ordered.extend(deps & level)
   return ordered

plat_file_name = user_data_dir + '/config/platform'
try:
   platform = file(plat_file_name).read()
except:
   print red('platform not defined in ' + plat_file_name)
   sys.exit(1)

try:
   import sys
   import yaml
   import re, os
   import argparse
   from processes import start, stop, validate
   args = parse_args()
   config = read_config()
   if args == 'show':
      # show list and status of services
      max_name_len = 0
      for name in config:
         name_len = len(name)
Пример #8
0

def start_order(name):
    topo = toposort()
    ordered = []
    deps = set(calc_deps(name))
    for level in [x for x in toposort()]:
        ordered.extend(deps & level)
    return ordered


plat_file_name = user_data_dir + '/config/platform'
try:
    platform = file(plat_file_name).read()
except:
    print red('platform not defined in ' + plat_file_name)
    sys.exit(1)

try:
    import sys
    import yaml
    import re, os
    import argparse
    from processes import start, stop, validate
    args = parse_args()
    config = read_config()
    if args == 'show':
        # show list and status of services
        max_name_len = 0
        for name in config:
            name_len = len(name)
Пример #9
0
    args = parse_args()
    config = read_config()
    if args == 'show':
        # show list and status of services
        max_name_len = 0
        for name in config:
            name_len = len(name)
            if name_len > max_name_len:
                max_name_len = name_len
        for name, (path, _) in config.items():
            skip = ' ' * (max_name_len - len(name))
            pid = validate(name)
            if pid:
                ex_str = green('running [%d]' % pid)
            else:
                ex_str = red('not running')
            try:
                if len(config[name][1]) != 0:
                    ex_str += ', depends: ' + str(config[name][1])
            except:
                pass
            print '%s:%s %s' % (blue(name), skip, ex_str)

    elif args[0] in ['start', 'stop']:
        try:
            name = args[1]
            data = config[name]
            if args[0] == 'start':
                names = calc_deps_reverse_bfs(name)
                if len(names) > 1:
                    print 'dependency resolution order:', names
Пример #10
0
   args = parse_args()
   config = read_config()
   if args == 'show':
      # show list and status of services
      max_name_len = 0
      for name in config:
         name_len = len(name)
         if name_len > max_name_len:
            max_name_len = name_len
      for name, (path, _) in config.items():
         skip = ' ' * (max_name_len - len(name))
         pid = validate(name)
         if pid:
            ex_str = green('running [%d]' % pid)
         else:
            ex_str = red('not running')
         try:
            if len(config[name][1]) != 0:
               ex_str += ', depends: ' + str(config[name][1])
         except:
            pass
         print '%s:%s %s' % (blue(name), skip, ex_str)

   elif args[0] in ['start', 'stop']:
      try:
         name = args[1]
         data = config[name]
         if args[0] == 'start':
            names = calc_deps_reverse_bfs(name)
            if len(names) > 1:
               print 'dependency resolution order:', names