Beispiel #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]')
Beispiel #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]')
Beispiel #3
0
 def show( self ):
     index = 1
     for name in self.get_names( ):
         if index % 2 == 1:
             print("%s :%s" %( index, termcolor.purple(name) ))
         else:
             print("%s :%s" %( index, termcolor.blue(name) ))
         index += 1
Beispiel #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]')
Beispiel #5
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]')
Beispiel #6
0
    def session(self):
        env_default = os.environ[ 'HOME' ] + '/Dropbox/flocal.py'
        cmd =  "sshpass -p '%s' scp -o StrictHostKeyChecking=no -P %s %s %s@%s:/dev/shm/"\
                % (self.password, self.port, env_default, self.user, self.host)

        res = os.system(cmd)

        cmd =  "echo  -e '\e]2;{host}\a';sshpass -p '{pwd}' ssh  -o \
        StrictHostKeyChecking=no -p {port} {user}@{host} ".format(
                pwd = self.password,
                port = self.port,
                user = self.user,
                host = self.host,
                cmd = cmd
                )

        print "User:   %s" % termcolor.blue( self.user )
        print "Addr:   %s" % termcolor.blue( self.host )
        print "Port:   %s" % termcolor.blue( self.port )
        os.system(cmd)
Beispiel #7
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)
Beispiel #8
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))
Beispiel #9
0
         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 += '\t(deps: ' + ', '.join(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 = start_order(name)
            if len(names) > 1:
               print 'dependency resolution order:', names
            for name in names:
               start(name, config[name][2], config[name][0], args[2])
         else:
            running = running_processes()
            names = []
            for service in restart_order(name):
Beispiel #10
0
            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 += '\t(deps: ' + ', '.join(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 = start_order(name)
                if len(names) > 1:
                    print 'dependency resolution order:', names
                for name in names:
                    start(name, config[name][2], config[name][0], args[2])
            else:
                running = running_processes()
                names = []
                for service in restart_order(name):