def stop(self): try: pf = file(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except IOError: pid = None if not pid: print Color.colorear(MSG_PID_NO_EXISTE % self.pidfile, color=Color.WARNING) return # no es error en 'restart' # Matar el demonio try: while 1: os.kill(pid, SIGTERM) time.sleep(0.1) except OSError, err: codigo_error, msg_error = err if codigo_error == CODIGO_NO_SUCH_PROCESS: if os.path.exists(self.pidfile): os.remove(self.pidfile) else: print Color.colorear(msg_error) sys.exit(1)
def status(self): try: pf = file(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except IOError: pid = None print Color.colorear(MSJ_STATUS(self.__str__(), pid and 'running' or 'stopped', pid and ' with pid: {pid}.'.format(pid=pid) or '.'), color=pid and Color.OKGREEN or Color.WARNING) sys.exit()
def start(self): try: pf = file(self.pidfile, 'r') pid = int(pf.read().strip()) pf.close() except Exception as e: pid = None if pid: print Color.colorear(MSG_PID_EXISTE % self.pidfile) sys.exit(1) # start the daemon self.daemonize() self.run()