Module: ProcessWanker::NetApi
- Includes:
- Log
- Defined in:
- lib/net/net_api.rb
Constant Summary
Constants included from Log
Log::DEBUG, Log::ERROR, Log::INFO, Log::WARN
Class Method Summary collapse
-
.execute(cmd, connection) ⇒ Object
execute a command from a remote client.
-
.execute_cmd_single(cmd, service, connection) ⇒ Object
execute a command from a remote client.
Methods included from Log
debug, error, info, log, set_level, warn
Class Method Details
.execute(cmd, connection) ⇒ Object
execute a command from a remote client. called from the client’s read thread.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/net/net_api.rb', line 49 def execute(cmd,connection) Log::info("received command #{cmd.inspect} from #{connection.user}") # execute if(cmd[:cmd] == :reload) ServiceMgr.instance.reload_config=true # wait for service manager to tick ticks=ServiceMgr.instance.tick_count sleep(0.5) while(ServiceMgr.instance.tick_count-ticks < 2) elsif(cmd[:cmd] == :debug) cls={} GC.start ObjectSpace.each_object do |o| cls[o.class.name] ||= 0 cls[o.class.name] += 1 end return({ :counts => cls }) elsif(cmd[:cmd] == :terminate) ServiceMgr.instance.terminate=true connection.inform("terminating") return(nil) elsif([:stop,:restart,:start,:ignore].include?(cmd[:cmd])) # get hash of services services=ServiceMgr::instance.match_services(cmd[:spec] || "all") threads=[] services.keys.sort.each do |sn| service=services[sn] if(cmd[:sequential]) execute_cmd_single(cmd,service,connection) sleep(cmd[:sequential]) else threads << Thread.new do ProcessWanker::with_logged_rescue("execute_cmd_single") do execute_cmd_single(cmd,service,connection) end end end end threads.each { |t| t.join } end # construct response services ||= ServiceMgr::instance.match_services(cmd[:spec] || "all") resp={ :services => {} } services.keys.sort.each do |sn| service=services[sn] resp[:services][sn] = { :name => service.name, :group_name => service.group_name, :tags => service.params[:tags], :want_state => service.want_state, :show_state => service.show_state, :suppress => service.suppress } end resp end |
.execute_cmd_single(cmd, service, connection) ⇒ Object
execute a command from a remote client. called from the client’s read thread.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/net/net_api.rb', line 133 def execute_cmd_single(cmd,service,connection) connection.inform("send #{cmd[:cmd].inspect} to #{service.name}") want={ :start => :up, :stop => :down, :restart => :restart, :ignore => :ignore }[cmd[:cmd]] if(want) Log::debug("sending #{want} to #{service.name}") service.set_want_state(want) end wait=cmd[:wait] return(false) if(!wait) start_time=Time.now # wait for service manager to tick at least once ticks=ServiceMgr.instance.tick_count sleep(0.5) while(ServiceMgr.instance.tick_count == ticks) return(true) if(want == :ignore) # wait for process to be in desired state while(service.current_state != service.want_state || service.want_state == :restart) sleep(0.5) # timeout? if((Time.now - start_time) >= wait) connection.inform("timed out waiting for #{service.name}") return(false) end end true end |