def viewerOn(self, localdisp, localgeom, remotedisp, passwd, viewonly): self.muteOff() passwd = binascii.a2b_base64(passwd) passwd_file = '/tmp/v__%d' % os.getpid() with open(passwd_file, 'wb') as out_f: out_f.write(passwd) # VNC window cmdstr = "vncviewer -display %s -geometry=%s %s -passwd %s RemoteResize=0" % ( localdisp, localgeom, remotedisp, passwd_file) if viewonly: cmdstr += " -viewonly" self.logger.info("viewer ON (-display %s -geometry=%s %s)" % (localdisp, localgeom, remotedisp)) key = localdisp + localgeom try: self.procs[key].killpg() except Exception as e: pass try: self.procs[key] = myproc.myproc(cmdstr, usepg=True) except Exception as e: self.logger.error("viewer on error: %s" % (str(e))) #os.remove(passwd_file) return 0
def main(options, args): if options.conffile is None: raise RuntimeError("Please specify a configuration file with -f") config = initialize.read_config(options.conffile) pidfile = config.get('pidfile', "/tmp/datasink.pid") if options.kill: try: try: with open(pidfile, 'r') as pid_f: pid = int(pid_f.read().strip()) print("Killing %d..." % (pid)) os.kill(pid, signal.SIGKILL) print("Killed.") except IOError as e: print("Cannot read pid file (%s): %s" % (pidfile, str(e))) sys.exit(1) except OSError as e: print("Error killing pid (%d): %s" % (pid, str(e))) sys.exit(1) finally: sys.exit(0) detach = config.get('detach', False) if detach: print("Detaching from this process...") sys.stdout.flush() try: try: output = '/dev/null' child = myproc.myproc(server, args=[options, config], pidfile=pidfile, detach=True, stdout=output, stderr=output) child.wait() except Exception as e: print("Error detaching process: %s" % (str(e))) # TODO: check status of process and report error if necessary finally: sys.exit(0) # non-detach operation server(options, config)
def stop(self): with self.lock: self.logger.info("Stopping process associated with '%s'..." % self.name) # if self.proc and self.proc.status() == 'running': if self.proc: self.stopcount += 1 if self.stop_cmd: self.logger.info("Attempting stop command associated with '%s'..." % self.name) try: self.logger.info(self.stop_cmd) stop_proc = myproc.myproc(self.stop_cmd, stdout=self.stdout, stderr=self.stderr) # Wait a bit time.sleep(self.killwait) stop_proc.kill() except myproc.myprocError, e: pass self.logger.info("Sending SIGTERM to top process associated with '%s'..." % self.name) try: # Try to terminate gracefully by sending a SIGTERM to # the top-level process self.proc.signal(signal.SIGTERM) # Wait a bit status = self.proc.waitpg(timeout=self.killwait) # if status == 'exited': # self.proc = None # return ro.OK except myproc.myprocError, e: self.logger.error("Error sending SIGTERM to process: %s" % str(e)) # Just to be sure we've cleaned up any mess, send SIGKILL # to the entire process group... try: self.logger.info("Killing process group for '%s'." % self.name) self.proc.killpg() # Wait some more status = self.proc.waitpg(timeout=2.0) if status == "exited": self.proc = None return ro.OK except myproc.myprocError, e: pass
def start(self): with self.lock: self.logger.info("Starting process associated with '%s'..." % self.name) if self.proc and self.proc.status() == "running": # Should we raise an error here? # raise managerSvcError("process already running: '%s'" % self.name) return ro.OK self.startcount += 1 self.logger.info(self.start_cmd) self.proc = myproc.myproc(self.start_cmd, stdout=self.stdout, stderr=self.stderr, usepg=True) self.timestart = time.time() if self.proc.status() != "running": return ro.ERROR return ro.OK
optprs.add_option( "--port", dest="port", type="int", default=ro.managerServicePort, help="Register using PORT", metavar="PORT" ) optprs.add_option("--secure", dest="secure", action="store_true", default=False, help="Use SSL encryption") ssdlog.addlogopts(optprs) (options, args) = optprs.parse_args(sys.argv[1:]) if len(args) != 0: optprs.error("incorrect number of arguments") if options.detach: print "Detaching from this process..." sys.stdout.flush() try: child = myproc.myproc(main, args=[options, args], pidfile=options.pidfile, detach=True) child.wait() # TODO: check status of process and report error if necessary finally: sys.exit(0) # Are we debugging this? elif options.debug: import pdb pdb.run("main(options, args)") # Are we profiling this? elif options.profile: import profile