Mercurial > prosody-hg
comparison util/prosodyctl.lua @ 10411:db2a06b9ff98
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 16 Nov 2019 16:52:31 +0100 |
| parents | 649acbfbf7fe |
| children | a469d2bcea96 |
comparison
equal
deleted
inserted
replaced
| 10410:659b577f280c | 10411:db2a06b9ff98 |
|---|---|
| 35 local function show_usage(usage, desc) | 35 local function show_usage(usage, desc) |
| 36 print("Usage: ".._G.arg[0].." "..usage); | 36 print("Usage: ".._G.arg[0].." "..usage); |
| 37 if desc then | 37 if desc then |
| 38 print(" "..desc); | 38 print(" "..desc); |
| 39 end | 39 end |
| 40 end | |
| 41 | |
| 42 local function show_module_configuration_help(mod_name) | |
| 43 print("Done.") | |
| 44 print("If you installed a prosody plugin, don't forget to add its name under the 'modules_enabled' section inside your configuration file.") | |
| 45 print("Depending on the module, there might be further configuration steps required.") | |
| 46 print("") | |
| 47 print("More info about: ") | |
| 48 print(" modules_enabled: https://prosody.im/doc/modules_enabled") | |
| 49 print(" "..mod_name..": https://modules.prosody.im/"..mod_name..".html") | |
| 40 end | 50 end |
| 41 | 51 |
| 42 local function getchar(n) | 52 local function getchar(n) |
| 43 local stty_ret = os.execute("stty raw -echo 2>/dev/null"); | 53 local stty_ret = os.execute("stty raw -echo 2>/dev/null"); |
| 44 local ok, char; | 54 local ok, char; |
| 122 return (line and #line > 0) and line or nil; | 132 return (line and #line > 0) and line or nil; |
| 123 end | 133 end |
| 124 | 134 |
| 125 -- Server control | 135 -- Server control |
| 126 local function adduser(params) | 136 local function adduser(params) |
| 127 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; | 137 local user, host, password = nodeprep(params.user, true), nameprep(params.host), params.password; |
| 128 if not user then | 138 if not user then |
| 129 return false, "invalid-username"; | 139 return false, "invalid-username"; |
| 130 elseif not host then | 140 elseif not host then |
| 131 return false, "invalid-hostname"; | 141 return false, "invalid-hostname"; |
| 132 end | 142 end |
| 227 return ok, pid; | 237 return ok, pid; |
| 228 end | 238 end |
| 229 return true, signal.kill(pid, 0) == 0; | 239 return true, signal.kill(pid, 0) == 0; |
| 230 end | 240 end |
| 231 | 241 |
| 232 local function start(source_dir) | 242 local function start(source_dir, lua) |
| 243 lua = lua and lua .. " " or ""; | |
| 233 local ok, ret = isrunning(); | 244 local ok, ret = isrunning(); |
| 234 if not ok then | 245 if not ok then |
| 235 return ok, ret; | 246 return ok, ret; |
| 236 end | 247 end |
| 237 if ret then | 248 if ret then |
| 238 return false, "already-running"; | 249 return false, "already-running"; |
| 239 end | 250 end |
| 240 if not source_dir then | 251 if not source_dir then |
| 241 os.execute("./prosody"); | 252 os.execute(lua .. "./prosody"); |
| 242 else | 253 else |
| 243 os.execute(source_dir.."/../../bin/prosody"); | 254 os.execute(lua .. source_dir.."/../../bin/prosody"); |
| 244 end | 255 end |
| 245 return true; | 256 return true; |
| 246 end | 257 end |
| 247 | 258 |
| 248 local function stop() | 259 local function stop() |
| 273 local ok, pid = getpid() | 284 local ok, pid = getpid() |
| 274 if not ok then return false, pid; end | 285 if not ok then return false, pid; end |
| 275 | 286 |
| 276 signal.kill(pid, signal.SIGHUP); | 287 signal.kill(pid, signal.SIGHUP); |
| 277 return true; | 288 return true; |
| 289 end | |
| 290 | |
| 291 local function get_path_custom_plugins(plugin_paths) | |
| 292 -- I'm considering that the custom plugins' path is the first one at prosody.paths.plugins | |
| 293 -- luacheck: ignore 512 | |
| 294 for path in plugin_paths:gmatch("[^;]+") do | |
| 295 return path; | |
| 296 end | |
| 297 end | |
| 298 | |
| 299 local function call_luarocks(mod, operation) | |
| 300 local dir = get_path_custom_plugins(prosody.paths.plugins); | |
| 301 if operation == "install" then | |
| 302 show_message("Installing %s at %s", mod, dir); | |
| 303 elseif operation == "remove" then | |
| 304 show_message("Removing %s from %s", mod, dir); | |
| 305 end | |
| 306 if operation == "list" then | |
| 307 os.execute("luarocks list --tree='"..dir.."'") | |
| 308 else | |
| 309 os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); | |
| 310 end | |
| 311 if operation == "install" then | |
| 312 show_module_configuration_help(mod); | |
| 313 end | |
| 278 end | 314 end |
| 279 | 315 |
| 280 return { | 316 return { |
| 281 show_message = show_message; | 317 show_message = show_message; |
| 282 show_warning = show_message; | 318 show_warning = show_message; |
| 283 show_usage = show_usage; | 319 show_usage = show_usage; |
| 320 show_module_configuration_help = show_module_configuration_help; | |
| 284 getchar = getchar; | 321 getchar = getchar; |
| 285 getline = getline; | 322 getline = getline; |
| 286 getpass = getpass; | 323 getpass = getpass; |
| 287 show_yesno = show_yesno; | 324 show_yesno = show_yesno; |
| 288 read_password = read_password; | 325 read_password = read_password; |
| 294 getpid = getpid; | 331 getpid = getpid; |
| 295 isrunning = isrunning; | 332 isrunning = isrunning; |
| 296 start = start; | 333 start = start; |
| 297 stop = stop; | 334 stop = stop; |
| 298 reload = reload; | 335 reload = reload; |
| 336 get_path_custom_plugins = get_path_custom_plugins; | |
| 337 call_luarocks = call_luarocks; | |
| 299 }; | 338 }; |
