Software /
code /
prosody
Comparison
prosodyctl @ 1458:fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 02 Jul 2009 04:43:08 +0100 |
parent | 1390:ef672c9fe7c9 |
child | 1459:545208bc0e84 |
comparison
equal
deleted
inserted
replaced
1457:4723bd466a54 | 1458:fce75b4efda9 |
---|---|
102 require "core.hostmanager" | 102 require "core.hostmanager" |
103 require "core.eventmanager".fire_event("server-starting"); | 103 require "core.eventmanager".fire_event("server-starting"); |
104 require "core.modulemanager" | 104 require "core.modulemanager" |
105 | 105 |
106 require "util.prosodyctl" | 106 require "util.prosodyctl" |
107 require "socket" | |
107 ----------------------- | 108 ----------------------- |
108 | 109 |
109 function show_message(msg, ...) | 110 function show_message(msg, ...) |
110 print(msg:format(...)); | 111 print(msg:format(...)); |
111 end | 112 end |
289 show_message("Prosody is already running with PID %s", ret or "(unknown)"); | 290 show_message("Prosody is already running with PID %s", ret or "(unknown)"); |
290 return 1; | 291 return 1; |
291 end | 292 end |
292 | 293 |
293 local ok, ret = prosodyctl.start(); | 294 local ok, ret = prosodyctl.start(); |
294 if ok then return 0; end | 295 if ok then |
296 local i=1; | |
297 while true do | |
298 local ok, running = prosodyctl.isrunning(); | |
299 if ok and running then | |
300 break; | |
301 elseif i == 5 then | |
302 show_message("Still waiting..."); | |
303 elseif i >= 10 then | |
304 show_message("Prosody is still not running. Please give it some time or check your log files for errors."); | |
305 return 2; | |
306 end | |
307 socket.sleep(0.5); | |
308 i = i + 1; | |
309 end | |
310 show_message("Started"); | |
311 return 0; | |
312 end | |
295 | 313 |
296 show_message("Failed to start Prosody"); | 314 show_message("Failed to start Prosody"); |
297 show_message(error_messages[ret]) | 315 show_message(error_messages[ret]) |
298 return 1; | 316 return 1; |
299 end | 317 end |
342 show_message("Prosody is not running"); | 360 show_message("Prosody is not running"); |
343 return 1; | 361 return 1; |
344 end | 362 end |
345 | 363 |
346 local ok, ret = prosodyctl.stop(); | 364 local ok, ret = prosodyctl.stop(); |
347 if ok then return 0; end | 365 if ok then |
366 local i=1; | |
367 while true do | |
368 local ok, running = prosodyctl.isrunning(); | |
369 if ok and not running then | |
370 break; | |
371 elseif i == 5 then | |
372 show_message("Still waiting..."); | |
373 elseif i >= 10 then | |
374 show_message("Prosody is still running. Please give it some time or check your log files for errors."); | |
375 return 2; | |
376 end | |
377 socket.sleep(0.5); | |
378 i = i + 1; | |
379 end | |
380 show_message("Stopped"); | |
381 return 0; | |
382 end | |
348 | 383 |
349 show_message(error_messages[ret]); | 384 show_message(error_messages[ret]); |
350 return 1; | 385 return 1; |
351 end | 386 end |
352 | 387 |