Comparison

prosodyctl @ 10434:8f709577fe8e

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 23 Nov 2019 23:12:01 +0100
parent 10369:9d20fca6a485
parent 10432:7b5a3de26f57
child 10579:16099e8964d8
comparison
equal deleted inserted replaced
10433:7777f25d5266 10434:8f709577fe8e
8 -- 8 --
9 9
10 -- prosodyctl - command-line controller for Prosody XMPP server 10 -- prosodyctl - command-line controller for Prosody XMPP server
11 11
12 -- Will be modified by configure script if run -- 12 -- Will be modified by configure script if run --
13
14 CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); 13 CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR");
15 CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); 14 CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR");
16 CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); 15 CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR");
17 CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); 16 CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR");
18 17
75 local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning; 74 local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning;
76 local show_usage = prosodyctl.show_usage; 75 local show_usage = prosodyctl.show_usage;
77 local show_yesno = prosodyctl.show_yesno; 76 local show_yesno = prosodyctl.show_yesno;
78 local show_prompt = prosodyctl.show_prompt; 77 local show_prompt = prosodyctl.show_prompt;
79 local read_password = prosodyctl.read_password; 78 local read_password = prosodyctl.read_password;
79 local call_luarocks = prosodyctl.call_luarocks;
80 80
81 local jid_split = require "util.jid".prepped_split; 81 local jid_split = require "util.jid".prepped_split;
82 82
83 local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * 2; 83 local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * 2;
84 ----------------------- 84 -----------------------
85 local commands = {}; 85 local commands = {};
86 local command = arg[1]; 86 local command = table.remove(arg, 1);
87
88 function commands.install(arg)
89 if arg[1] == "--help" then
90 show_usage([[install]], [[Installs a prosody/luarocks plugin]]);
91 return 1;
92 end
93 call_luarocks(arg[1], "install")
94 end
95
96 function commands.remove(arg)
97 if arg[1] == "--help" then
98 show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]);
99 return 1;
100 end
101 call_luarocks(arg[1], "remove")
102 end
103
104 function commands.list(arg)
105 if arg[1] == "--help" then
106 show_usage([[list]], [[Shows installed rocks]]);
107 return 1;
108 end
109 call_luarocks(arg[1], "list")
110 end
87 111
88 function commands.adduser(arg) 112 function commands.adduser(arg)
89 if not arg[1] or arg[1] == "--help" then 113 if not arg[1] or arg[1] == "--help" then
90 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); 114 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]);
91 return 1; 115 return 1;
118 142
119 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; 143 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
120 144
121 if ok then return 0; end 145 if ok then return 0; end
122 146
123 show_message(msg) 147 show_message(error_messages[msg])
124 return 1; 148 return 1;
125 end 149 end
126 150
127 function commands.passwd(arg) 151 function commands.passwd(arg)
128 if not arg[1] or arg[1] == "--help" then 152 if not arg[1] or arg[1] == "--help" then
220 show_message("Prosody is already running with PID %s", ret or "(unknown)"); 244 show_message("Prosody is already running with PID %s", ret or "(unknown)");
221 return 1; 245 return 1;
222 end 246 end
223 247
224 --luacheck: ignore 411/ret 248 --luacheck: ignore 411/ret
225 local ok, ret = prosodyctl.start(prosody.paths.source); 249 local lua;
250 do
251 local i = 0;
252 repeat
253 i = i - 1;
254 until arg[i-1] == nil
255 lua = arg[i];
256 end
257 local ok, ret = prosodyctl.start(prosody.paths.source, lua);
226 if ok then 258 if ok then
227 local daemonize = configmanager.get("*", "daemonize"); 259 local daemonize = configmanager.get("*", "daemonize");
228 if daemonize == nil then 260 if daemonize == nil then
229 daemonize = prosody.installed; 261 daemonize = prosody.installed;
230 end 262 end
361 hgrepo = hgrepo == "010452cfaf53" and "prosody-modules"; 393 hgrepo = hgrepo == "010452cfaf53" and "prosody-modules";
362 return path..(hgid and " - "..(hgrepo or "HG").." rev: "..hgid or "") 394 return path..(hgid and " - "..(hgrepo or "HG").." rev: "..hgid or "")
363 .."\n "; 395 .."\n ";
364 end))); 396 end)));
365 print(""); 397 print("");
398 local have_pposix, pposix = pcall(require, "util.pposix");
399 if have_pposix and pposix.uname then
400 print("# Operating system");
401 local uname, err = pposix.uname();
402 print(uname and uname.sysname .. " " .. uname.release or "Unknown POSIX", err or "");
403 print("");
404 end
366 print("# Lua environment"); 405 print("# Lua environment");
367 print("Lua version: ", _G._VERSION); 406 print("Lua version: ", _G._VERSION);
368 print(""); 407 print("");
369 print("Lua module search paths:"); 408 print("Lua module search paths:");
370 for path in package.path:gmatch("[^;]+") do 409 for path in package.path:gmatch("[^;]+") do
809 end 848 end
810 if not what or what == "config" then 849 if not what or what == "config" then
811 print("Checking config..."); 850 print("Checking config...");
812 local deprecated = set.new({ 851 local deprecated = set.new({
813 "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", 852 "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption",
814 "vcard_compatibility", 853 "vcard_compatibility", "cross_domain_bosh", "cross_domain_websocket"
815 }); 854 });
816 local known_global_options = set.new({ 855 local known_global_options = set.new({
817 "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", 856 "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize",
818 "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings", 857 "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings",
819 "network_backend", "http_default_host", 858 "network_backend", "http_default_host",
1311 show_message("Failed to load module '"..module_name.."': "..err); 1350 show_message("Failed to load module '"..module_name.."': "..err);
1312 os.exit(1); 1351 os.exit(1);
1313 end 1352 end
1314 end 1353 end
1315 1354
1316 table.remove(arg, 1);
1317
1318 local module = modulemanager.get_module("*", module_name); 1355 local module = modulemanager.get_module("*", module_name);
1319 if not module then 1356 if not module then
1320 show_message("Failed to load module '"..module_name.."': Unknown error"); 1357 show_message("Failed to load module '"..module_name.."': Unknown error");
1321 os.exit(1); 1358 os.exit(1);
1322 end 1359 end
1351 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); 1388 print("Usage: "..arg[0].." COMMAND [OPTIONS]");
1352 print(""); 1389 print("");
1353 print("Where COMMAND may be one of:\n"); 1390 print("Where COMMAND may be one of:\n");
1354 1391
1355 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; 1392 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" };
1356 local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" }; 1393 local commands_order = { "install", "remove", "list", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload",
1394 "about" };
1357 1395
1358 local done = {}; 1396 local done = {};
1359 1397
1360 for _, command_name in ipairs(commands_order) do 1398 for _, command_name in ipairs(commands_order) do
1361 local command_func = commands[command_name]; 1399 local command_func = commands[command_name];
1376 1414
1377 1415
1378 os.exit(0); 1416 os.exit(0);
1379 end 1417 end
1380 1418
1381 os.exit(commands[command]({ select(2, unpack(arg)) })); 1419 os.exit(commands[command](arg));
1382 end, watchers); 1420 end, watchers);
1383 1421
1384 command_runner:run(true); 1422 command_runner:run(true);