From aa77e7d21a732eef4005f930ca81077bb67153a2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 2 Jul 2009 04:43:08 +0100 Subject: prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop --- prosodyctl | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 642b12b8..0ddc6bcf 100755 --- a/prosodyctl +++ b/prosodyctl @@ -104,6 +104,7 @@ require "core.eventmanager".fire_event("server-starting"); require "core.modulemanager" require "util.prosodyctl" +require "socket" ----------------------- function show_message(msg, ...) @@ -291,7 +292,24 @@ function commands.start(arg) end local ok, ret = prosodyctl.start(); - if ok then return 0; end + if ok then + local i=1; + while true do + local ok, running = prosodyctl.isrunning(); + if ok and running then + break; + elseif i == 5 then + show_message("Still waiting..."); + elseif i >= 10 then + show_message("Prosody is still not running. Please give it some time or check your log files for errors."); + return 2; + end + socket.sleep(0.5); + i = i + 1; + end + show_message("Started"); + return 0; + end show_message("Failed to start Prosody"); show_message(error_messages[ret]) @@ -344,7 +362,24 @@ function commands.stop(arg) end local ok, ret = prosodyctl.stop(); - if ok then return 0; end + if ok then + local i=1; + while true do + local ok, running = prosodyctl.isrunning(); + if ok and not running then + break; + elseif i == 5 then + show_message("Still waiting..."); + elseif i >= 10 then + show_message("Prosody is still running. Please give it some time or check your log files for errors."); + return 2; + end + socket.sleep(0.5); + i = i + 1; + end + show_message("Stopped"); + return 0; + end show_message(error_messages[ret]); return 1; -- cgit v1.2.3 From 678d1273e3ac128724618e2862c317f2a1e670d6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 2 Jul 2009 04:53:31 +0100 Subject: prosodyctl: Use prosodyctl_timeout option if it exists in the config --- prosodyctl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 0ddc6bcf..980aa329 100755 --- a/prosodyctl +++ b/prosodyctl @@ -164,6 +164,8 @@ local function read_password() end return password; end + +local prosodyctl_timeout = (config.get("*", "core", "prosodyctl_timeout") or 5) * 2; ----------------------- local commands = {}; local command = arg[1]; @@ -300,7 +302,7 @@ function commands.start(arg) break; elseif i == 5 then show_message("Still waiting..."); - elseif i >= 10 then + elseif i >= prosodyctl_timeout then show_message("Prosody is still not running. Please give it some time or check your log files for errors."); return 2; end @@ -370,7 +372,7 @@ function commands.stop(arg) break; elseif i == 5 then show_message("Still waiting..."); - elseif i >= 10 then + elseif i >= prosodyctl_timeout then show_message("Prosody is still running. Please give it some time or check your log files for errors."); return 2; end -- cgit v1.2.3 From b9c0a4931de101141bcb2364b579d34844a3f5c9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 2 Jul 2009 04:54:46 +0100 Subject: prosodyctl: Add message for not-running error --- prosodyctl | 1 + 1 file changed, 1 insertion(+) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index 980aa329..0d687986 100755 --- a/prosodyctl +++ b/prosodyctl @@ -95,6 +95,7 @@ local error_messages = setmetatable({ ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; ["no-pidfile"] = "There is no pidfile option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; ["no-such-method"] = "This module has no commands"; + ["not-running"] = "Prosody is not running"; }, { __index = function (t,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); hosts = {}; -- cgit v1.2.3