def c_restart(p, h, args): if len(args) == 0: p.info( "No processes restarted" ) return 1; while len(args) > 0: id = match_one_running( p, h, args.pop() ); if not id: continue; p.info( "Restarting:", id ) m = Monitor(h, id); if not m.send( commands.Restart() ): p.info( "Unable to restart, cleaning id:", id ) h.clean(id);
def c_stop(p, h, args): if len(args) == 0: p.info( "No processes stopped" ) return 1; while len(args) > 0: id = match_one_running( p, h, args.pop() ); if not id: continue; p.info( "Shutting down:", id ) m = Monitor(h, id); if not m.send( commands.Shutdown( commands.Shutdown.TERM ) ): p.info( "Unable to shutdown, cleaning id:", id ) m.clean();
def c_clean(p, h, args): if len(args) > 0: r = h.select_runs(args.pop()); else: r = h.select_runs(); for f in r: m = Monitor( h, f ); result = m.communicate( commands.Ping() ); if result and isinstance( result, commands.Pong ): p.info( "Got Pong:", f ) continue; p.info( "Timeout, removing:", f ) m.remove(); if len(r) == 0: p.info( "Nothing to clean" )
def c_info(p, h, args): if len(args) == 0: return 1; id = match_one_running( p, h, args.pop() ); if not id: return 1; m = Monitor(h, id); result = m.communicate(commands.Info()); if result: p.format("id: ?", result.id ); p.format("init: ?", h.get_init( result.init ).path ); p.format("pid: ?", result.pid ); p.format("running: ?", get_time( result.started ) ); else: p.info( "Unable to get info" )
def run(self): import signal init = self.args[0]; self.m = Monitor( self.home, init=init ); if not self.m.spawn(): self.m.remove(); sys.exit(1); try: self.m.run(); except Exception, e: import traceback self.m.log(traceback.format_exc());