diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-06-02 08:28:39 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-06-02 08:28:39 +0100 |
commit | 5c3b43f01416ba31fa3f81b87c82e046e165a8e8 (patch) | |
tree | 821c1204b631d73fd3e5d3d143e189a45d7233f0 /util/prosodyctl/shell.lua | |
parent | 23cef5c6c53809c5be09581f1bfdab10f5af6bb8 (diff) | |
download | prosody-5c3b43f01416ba31fa3f81b87c82e046e165a8e8.tar.gz prosody-5c3b43f01416ba31fa3f81b87c82e046e165a8e8.zip |
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Diffstat (limited to 'util/prosodyctl/shell.lua')
-rw-r--r-- | util/prosodyctl/shell.lua | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/util/prosodyctl/shell.lua b/util/prosodyctl/shell.lua index 8c8769e2..bbf0c83a 100644 --- a/util/prosodyctl/shell.lua +++ b/util/prosodyctl/shell.lua @@ -1,11 +1,3 @@ -local have_unix, unix = pcall(require, "socket.unix"); - -if not have_unix or type(unix) ~= "table" then - print("** LuaSocket unix socket support not available or incompatible, ensure your"); - print("** version is up to date."); - os.exit(1); -end - local config = require "core.configmanager"; local server = require "net.server"; local st = require "util.stanza"; @@ -44,37 +36,6 @@ local function repl(client) send_line(client, line); end -local function connection(socket_path, listeners) - local conn, sock; - - return { - connect = function () - if sock or conn then - return nil, "already connected"; - end - sock = unix.stream(); - sock:settimeout(0); - local ok, err = sock:connect(socket_path); - if not ok then - return nil, err; - end - conn = server.wrapclient(sock, nil, nil, listeners, "*a"); - return true; - end; - disconnect = function () - if conn then - conn:close(); - conn = nil; - end - if sock then - sock:close(); - sock = nil; - end - return true; - end; - }; -end - local function printbanner() print([[ ____ \ / _ @@ -117,11 +78,16 @@ local function start(arg) --luacheck: ignore 212/arg end); local socket_path = path.resolve_relative_path(prosody.paths.data, opts.socket or config.get("*", "admin_socket") or "prosody.sock"); - local conn = connection(socket_path, client.listeners); + local conn = adminstream.connection(socket_path, client.listeners); local ok, err = conn:connect(); if not ok then - print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?"); - print("** Connection error: "..err); + if err == "no unix socket support" then + print("** LuaSocket unix socket support not available or incompatible, ensure your"); + print("** version is up to date."); + else + print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?"); + print("** Connection error: "..err); + end os.exit(1); end server.loop(); |