Software / code / prosody
Comparison
prosodyctl @ 10411:db2a06b9ff98
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 16 Nov 2019 16:52:31 +0100 |
| parent | 10369:9d20fca6a485 |
| child | 10434:8f709577fe8e |
comparison
equal
deleted
inserted
replaced
| 10410:659b577f280c | 10411:db2a06b9ff98 |
|---|---|
| 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", |
| 1307 show_message("Failed to load module '"..module_name.."': "..err); | 1346 show_message("Failed to load module '"..module_name.."': "..err); |
| 1308 os.exit(1); | 1347 os.exit(1); |
| 1309 end | 1348 end |
| 1310 end | 1349 end |
| 1311 | 1350 |
| 1312 table.remove(arg, 1); | |
| 1313 | |
| 1314 local module = modulemanager.get_module("*", module_name); | 1351 local module = modulemanager.get_module("*", module_name); |
| 1315 if not module then | 1352 if not module then |
| 1316 show_message("Failed to load module '"..module_name.."': Unknown error"); | 1353 show_message("Failed to load module '"..module_name.."': Unknown error"); |
| 1317 os.exit(1); | 1354 os.exit(1); |
| 1318 end | 1355 end |
| 1347 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); | 1384 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); |
| 1348 print(""); | 1385 print(""); |
| 1349 print("Where COMMAND may be one of:\n"); | 1386 print("Where COMMAND may be one of:\n"); |
| 1350 | 1387 |
| 1351 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; | 1388 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; |
| 1352 local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" }; | 1389 local commands_order = { "install", "remove", "list", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", |
| 1390 "about" }; | |
| 1353 | 1391 |
| 1354 local done = {}; | 1392 local done = {}; |
| 1355 | 1393 |
| 1356 for _, command_name in ipairs(commands_order) do | 1394 for _, command_name in ipairs(commands_order) do |
| 1357 local command_func = commands[command_name]; | 1395 local command_func = commands[command_name]; |
| 1372 | 1410 |
| 1373 | 1411 |
| 1374 os.exit(0); | 1412 os.exit(0); |
| 1375 end | 1413 end |
| 1376 | 1414 |
| 1377 os.exit(commands[command]({ select(2, unpack(arg)) })); | 1415 os.exit(commands[command](arg)); |
| 1378 end, watchers); | 1416 end, watchers); |
| 1379 | 1417 |
| 1380 command_runner:run(true); | 1418 command_runner:run(true); |