def _start_one_ex(self, name, daemon): if self._getStatusOne(name): return config = self.getNodeConfig(name) cmd = [] if 'wrapper' in config: cmd = config['wrapper'].split(' ') command = self._cmd(name) cmd.extend(command) if daemon: cmd.append('-daemonize') logging.debug('calling: %s', str(cmd)) return subprocess.call(cmd, close_fds=True)
def _startOneEx(self, name, daemon): if self._getStatusOne(name): return config = self.getNodeConfig(name) cmd = [] if 'wrapper' in config: cmd = config['wrapper'].split(' ') command = self._cmd(name) cmd.extend(command) if daemon: cmd.append('-daemonize') logging.debug('calling: %s', str(cmd)) return subprocess.call(cmd, close_fds=True)
def _getStatusOne(self, name): line = self._cmdLine(name) cmd = ['pgrep', '-fn', line] proc = subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE) pids = proc.communicate()[0] pid_list = pids.split() lenp = len(pid_list) if lenp == 1: result = True elif lenp == 0: result = False else: for pid in pid_list: try: f = open('/proc/%s/cmdline' % pid, 'r') startup = f.read() f.close() logging.debug('pid=%s; cmdline=%s', pid, startup) except: pass raise Exception('multiple matches', pid_list) return result
def _getStatusOne(self, name): line = self._cmdLine(name) cmd = ['pgrep', '-fn', line] proc = subprocess.Popen(cmd, close_fds=True, stdout=subprocess.PIPE) pids = proc.communicate()[0] pid_list = pids.split() lenp = len(pid_list) if lenp == 1: result = True elif lenp == 0: result = False else: for pid in pid_list: try: f = open('/proc/%s/cmdline' % pid, 'r') startup = f.read() f.close() logging.debug('pid=%s; cmdline=%s', pid, startup) except: pass raise Exception('multiple matches', pid_list) return result
def _stopOne(self, name): line = self._cmdLine(name) cmd = ['pkill', '-f', line] logging.debug("stopping '%s' with: %s" % (name, ' '.join(cmd))) rc = subprocess.call(cmd, close_fds=True) logging.debug('%s=>rc=%i' % (cmd, rc)) i = 0 while self._getStatusOne(name): rc = subprocess.call(cmd, close_fds=True) logging.debug('%s=>rc=%i' % (cmd, rc)) time.sleep(1) i += 1 logging.debug("'%s' is still running... waiting" % name) if i == 10: msg = "Requesting '%s' to dump crash log information" % name logging.debug(msg) subprocess.call(['pkill', '-%d' % signal.SIGUSR2, '-f', line], close_fds=True) time.sleep(1) logging.debug("stopping '%s' with kill -9" % name) rc = subprocess.call(['pkill', '-9', '-f', line], close_fds=True) if rc == 0: rc = 9 cnt = 0 while self._getStatusOne(name): logging.debug("'%s' is STILL running... waiting" % name) time.sleep(1) cnt += 1 if cnt > 10: break break else: subprocess.call(cmd, close_fds=True) if rc < 9: rc = 0 # might be we looped one time too many. return rc
def _stopOne(self, name): line = self._cmdLine(name) cmd = ['pkill', '-f', line] logging.debug("stopping '%s' with: %s" % (name, ' '.join(cmd))) rc = subprocess.call(cmd, close_fds=True) logging.debug('%s=>rc=%i' % (cmd, rc)) i = 0 while self._getStatusOne(name): rc = subprocess.call(cmd, close_fds=True) logging.debug('%s=>rc=%i' % (cmd, rc)) time.sleep(1) i += 1 logging.debug("'%s' is still running... waiting" % name) if i == 10: msg = "Requesting '%s' to dump crash log information" % name logging.debug(msg) subprocess.call(['pkill', '-%d' % signal.SIGUSR2, '-f', line], close_fds=True) time.sleep(1) logging.debug("stopping '%s' with kill -9" % name) rc = subprocess.call(['pkill', '-9', '-f', line], close_fds=True) if rc == 0: rc = 9 cnt = 0 while self._getStatusOne(name): logging.debug("'%s' is STILL running... waiting" % name) time.sleep(1) cnt += 1 if cnt > 10: break break else: subprocess.call(cmd, close_fds=True) if rc < 9: rc = 0 # might be we looped one time too many. return rc