Software /
code /
prosody
Annotate
prosodyctl @ 11295:50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Better than having a non-working default.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 21 Jan 2021 19:11:27 +0100 |
parent | 11294:a1939b261f67 |
child | 11297:2e9d4c517919 |
rev | line source |
---|---|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env lua |
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1501
diff
changeset
|
2 -- Prosody IM |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
3 -- Copyright (C) 2008-2010 Matthew Wild |
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
4 -- Copyright (C) 2008-2010 Waqas Hussain |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
5 -- |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 -- prosodyctl - command-line controller for Prosody XMPP server |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 -- Will be modified by configure script if run -- |
7297
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
13 CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
14 CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
15 CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
16 CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
18 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
20 local function is_relative(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
21 local path_sep = package.config:sub(1,1); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
22 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
23 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
24 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
25 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
26 -- Tell Lua where to find our libraries |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if CFG_SOURCEDIR then |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
28 local function filter_relative_paths(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
29 if is_relative(path) then return ""; end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
30 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
31 local function sanitise_paths(paths) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
32 return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";")); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
33 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
34 package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
35 package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
38 -- Substitute ~ with path to home directory in data path |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if CFG_DATADIR then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 if os.getenv("HOME") then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
8635
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
45 ----------- |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
46 |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
47 local startup = require "util.startup"; |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
48 startup.prosodyctl(); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
49 |
8635
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
50 ----------- |
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
51 |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
52 local configmanager = require "core.configmanager"; |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
53 local modulemanager = require "core.modulemanager" |
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
54 local prosodyctl = require "util.prosodyctl" |
6784
4da860edc27c
prosodyctl: Import LuaSocket to a local, don't assume that a global will be set
Kim Alvefur <zash@zash.se>
parents:
6751
diff
changeset
|
55 local socket = require "socket" |
8635
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
56 local dependencies = require "util.dependencies"; |
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
57 local lfs = dependencies.softreq "lfs"; |
8198
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
58 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
61 local human_io = require "util.human.io"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
62 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
4095
diff
changeset
|
63 local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning; |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
4095
diff
changeset
|
64 local show_usage = prosodyctl.show_usage; |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
65 local read_password = human_io.read_password; |
10207
4c755c2e6305
prosodyctl: Install, remove and list commands now use the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10202
diff
changeset
|
66 local call_luarocks = prosodyctl.call_luarocks; |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
67 local error_messages = prosodyctl.error_messages; |
1459
545208bc0e84
prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents:
1458
diff
changeset
|
68 |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
69 local jid_split = require "util.jid".prepped_split; |
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
70 |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
71 local prosodyctl_timeout = (configmanager.get("*", "prosodyctl_timeout") or 5) * 2; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local commands = {}; |
9780
c7727c13260f
prosodyctl: Pass the original argv table to subcommands (with first argument removed)
Kim Alvefur <zash@zash.se>
parents:
9709
diff
changeset
|
74 local command = table.remove(arg, 1); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 |
10141
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
76 function commands.install(arg) |
10147
1a35b3a2b11b
prosodyctl: Corrected indentation on my code
João Duarte <jvsDuarte08@gmail.com>
parents:
10146
diff
changeset
|
77 if arg[1] == "--help" then |
10172
5da519ef2d51
prosodyctl: Corrected the help output of the install and remove commands
João Duarte <jvsDuarte08@gmail.com>
parents:
10170
diff
changeset
|
78 show_usage([[install]], [[Installs a prosody/luarocks plugin]]); |
10147
1a35b3a2b11b
prosodyctl: Corrected indentation on my code
João Duarte <jvsDuarte08@gmail.com>
parents:
10146
diff
changeset
|
79 return 1; |
1a35b3a2b11b
prosodyctl: Corrected indentation on my code
João Duarte <jvsDuarte08@gmail.com>
parents:
10146
diff
changeset
|
80 end |
11294
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
81 show_message("Installing %s in %s", arg[1], prosody.paths.installer); |
11135
56490ffde93f
util.prosodyctl: Get Luarocks server from config
Kim Alvefur <zash@zash.se>
parents:
11134
diff
changeset
|
82 -- TODO finalize config option name |
11295
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
83 local server = configmanager.get("*", "plugin_server"); |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
84 if not server then |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
85 show_warning("There is no 'plugin_server' option in the configuration file"); |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
86 -- see https://prosody.im/doc/TODO documentation |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
87 return 1; |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
88 end |
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
89 local ret = call_luarocks("install", arg[1], server); |
11294
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
90 if ret == 0 and operation == "install" then |
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
91 show_module_configuration_help(mod); |
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
92 end |
11293
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
93 return ret; |
10141
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
94 end |
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
95 |
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
96 function commands.remove(arg) |
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
97 if arg[1] == "--help" then |
10202
d3764eed7ded
prosodyctl: Fixed a typo
João Duarte <jvsDuarte08@gmail.com>
parents:
10190
diff
changeset
|
98 show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]); |
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
99 return 1; |
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
100 end |
11294
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
101 show_message("Removing %s from %s", arg[1], prosody.paths.installer); |
11293
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
102 local ret = call_luarocks("remove", arg[1]); |
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
103 return ret; |
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
104 end |
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
105 |
10126
ad640c2e072e
prosodyctl: Implemented the 'list' command, which is a bridge to 'luarocks list'
João Duarte <jvsDuarte08@gmail.com>
parents:
10125
diff
changeset
|
106 function commands.list(arg) |
10147
1a35b3a2b11b
prosodyctl: Corrected indentation on my code
João Duarte <jvsDuarte08@gmail.com>
parents:
10146
diff
changeset
|
107 if arg[1] == "--help" then |
10135
3ae2809030dd
prosodyctl: added help support to all my functions
João Duarte <jvsDuarte08@gmail.com>
parents:
10134
diff
changeset
|
108 show_usage([[list]], [[Shows installed rocks]]); |
3ae2809030dd
prosodyctl: added help support to all my functions
João Duarte <jvsDuarte08@gmail.com>
parents:
10134
diff
changeset
|
109 return 1; |
3ae2809030dd
prosodyctl: added help support to all my functions
João Duarte <jvsDuarte08@gmail.com>
parents:
10134
diff
changeset
|
110 end |
11293
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
111 local ret = call_luarocks("list", arg[1]); |
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
112 return ret; |
10126
ad640c2e072e
prosodyctl: Implemented the 'list' command, which is a bridge to 'luarocks list'
João Duarte <jvsDuarte08@gmail.com>
parents:
10125
diff
changeset
|
113 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 function commands.adduser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 end |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
120 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 if not user and host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 show_message [[Failed to understand JID, please supply the JID you want to create]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 show_usage [[adduser user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
126 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
131 |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
132 if not prosody.hosts[host] then |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
133 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
134 show_warning("The user will not be able to log in until this is changed."); |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
135 prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
136 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
137 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 if prosodyctl.user_exists{ user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 show_message [[That user already exists]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
142 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 if not password then return 1; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
145 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
147 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
149 |
10369
9d20fca6a485
prosodyctl: Print friendly version of error messages
Kim Alvefur <zash@zash.se>
parents:
10270
diff
changeset
|
150 show_message(error_messages[msg]) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 function commands.passwd(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
159 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 if not user and host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
165 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
170 |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
171 if not prosody.hosts[host] then |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
172 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
173 show_warning("The user will not be able to log in until this is changed."); |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
174 prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
175 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
176 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 if not prosodyctl.user_exists { user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 show_message [[That user does not exist, use prosodyctl adduser to create a new user]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
181 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 if not password then return 1; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
184 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
186 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
188 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 function commands.deluser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 show_usage([[deluser JID]], [[Permanently remove the specified user account from Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 end |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
198 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 if not user and host then |
7676
7311dc843718
prosodyctl: Fix copy/paste error in help text for deluser command
Matthew Wild <mwild1@gmail.com>
parents:
6498
diff
changeset
|
200 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] |
7311dc843718
prosodyctl: Fix copy/paste error in help text for deluser command
Matthew Wild <mwild1@gmail.com>
parents:
6498
diff
changeset
|
201 show_usage [[deluser user@host]] |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
204 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
209 |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
210 if not prosody.hosts[host] then |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
211 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
8718
c23cdeac5b61
prosodyctl: Use prosody.hosts instead of _G.hosts
Kim Alvefur <zash@zash.se>
parents:
8701
diff
changeset
|
212 prosody.hosts[host] = startup.make_host(host); --luacheck: ignore 122 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
213 end |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
214 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 if not prosodyctl.user_exists { user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 show_message [[That user does not exist on this server]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
219 |
5101
a94c43cad081
prosodyctl: Use util.prosodyctl.deluser
Kim Alvefur <zash@zash.se>
parents:
5024
diff
changeset
|
220 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
221 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
223 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 |
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
228 local function service_command_warning(service_command) |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
229 if prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
230 show_warning("WARNING: Use of prosodyctl start/stop/restart/reload is not recommended"); |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
231 show_warning(" if Prosody is managed by an init system - use that directly instead."); |
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
232 lfs = lfs or require |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
233 if lfs.attributes("/etc/systemd") then |
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
234 show_warning(" e.g. systemctl %s prosody", service_command); |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
235 elseif lfs.attributes("/etc/init.d/prosody") then |
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
236 show_warning(" e.g. /etc/init.d/prosody %s", service_command); |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
237 end |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
238 show_warning(""); |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
239 end |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
240 end |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
241 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
242 function commands.start(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
243 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
244 show_usage([[start]], [[Start Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
245 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
246 end |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
247 service_command_warning("start"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
253 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 if ret then |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
255 --luacheck: ignore 421/ret |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 show_message("Couldn't get running Prosody's PID"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 show_message("Prosody is already running with PID %s", ret or "(unknown)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
265 |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
266 --luacheck: ignore 411/ret |
10064
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
267 local lua; |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
268 do |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
269 local i = 0; |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
270 repeat |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
271 i = i - 1; |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
272 until arg[i-1] == nil |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
273 lua = arg[i]; |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
274 end |
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
275 local ok, ret = prosodyctl.start(prosody.paths.source, lua); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
276 if ok then |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
277 local daemonize = configmanager.get("*", "daemonize"); |
6062
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
278 if daemonize == nil then |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
279 daemonize = prosody.installed; |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
280 end |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
281 if daemonize then |
2511
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
282 local i=1; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
283 while true do |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
284 local ok, running = prosodyctl.isrunning(); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
285 if ok and running then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
286 break; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
287 elseif i == 5 then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
288 show_message("Still waiting..."); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
289 elseif i >= prosodyctl_timeout then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
290 show_message("Prosody is still not running. Please give it some time or check your log files for errors."); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
291 return 2; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
292 end |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
293 socket.sleep(0.5); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
294 i = i + 1; |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
295 end |
2511
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
296 show_message("Started"); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
297 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
298 return 0; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
299 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 show_message("Failed to start Prosody"); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
302 show_message(error_messages[ret]) |
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
303 return 1; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
306 function commands.status(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
307 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
308 show_usage([[status]], [[Reports the running status of Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
309 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
310 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
311 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
317 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 if ret then |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
319 --luacheck: ignore 421/ret |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 show_message("Couldn't get running Prosody's PID"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 show_message("Prosody is running with PID %s", ret or "(unknown)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 return 0; |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
328 else |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
329 show_message("Prosody is not running"); |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
330 if not prosody.switched_user and prosody.current_uid ~= 0 then |
1122
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
331 print("\nNote:") |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
332 print(" You will also see this if prosodyctl is not running under"); |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
333 print(" the same user account as Prosody. Try running as root (e.g. "); |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
334 print(" with 'sudo' in front) to gain access to Prosody's real status."); |
1115
8a7bc1a5eae6
prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user
Matthew Wild <mwild1@gmail.com>
parents:
1114
diff
changeset
|
335 end |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
336 return 2 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
340 function commands.stop(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
341 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
342 show_usage([[stop]], [[Stop a running Prosody server]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
343 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
344 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
345 |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
346 service_command_warning("stop"); |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
347 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 if not prosodyctl.isrunning() then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 show_message("Prosody is not running"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
352 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 local ok, ret = prosodyctl.stop(); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
354 if ok then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
355 local i=1; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
356 while true do |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
357 local ok, running = prosodyctl.isrunning(); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
358 if ok and not running then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
359 break; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
360 elseif i == 5 then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
361 show_message("Still waiting..."); |
1459
545208bc0e84
prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents:
1458
diff
changeset
|
362 elseif i >= prosodyctl_timeout then |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
363 show_message("Prosody is still running. Please give it some time or check your log files for errors."); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
364 return 2; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
365 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
366 socket.sleep(0.5); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
367 i = i + 1; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
368 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
369 show_message("Stopped"); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
370 return 0; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
371 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
373 show_message(error_messages[ret]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
377 function commands.restart(arg) |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
378 if arg[1] == "--help" then |
2705
8a5af6f14c07
prosodyctl: Fix 'restart' command to not report itself as the 'stop' command (thanks albert!)
Matthew Wild <mwild1@gmail.com>
parents:
2696
diff
changeset
|
379 show_usage([[restart]], [[Restart a running Prosody server]]); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
380 return 1; |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
381 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
382 |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
383 service_command_warning("restart"); |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
384 |
3724
c12ebbd4ab61
prosodyctl: Make the 'restart' command start Prosody even if it wasn't already running
Matthew Wild <mwild1@gmail.com>
parents:
3630
diff
changeset
|
385 commands.stop(arg); |
c12ebbd4ab61
prosodyctl: Make the 'restart' command start Prosody even if it wasn't already running
Matthew Wild <mwild1@gmail.com>
parents:
3630
diff
changeset
|
386 return commands.start(arg); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
387 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
388 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
389 function commands.about(arg) |
4331
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
390 if arg[1] == "--help" then |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
391 show_usage([[about]], [[Show information about this Prosody installation]]); |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
392 return 1; |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
393 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
394 |
6584
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
395 local pwd = "."; |
11002
b0766f2603e9
prosodyctl about: Use library function for sorted listing of lua modules
Kim Alvefur <zash@zash.se>
parents:
10964
diff
changeset
|
396 local sorted_pairs = require "util.iterators".sorted_pairs; |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
397 local hg = require"util.mercurial"; |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
398 local relpath = configmanager.resolve_relative_path; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
399 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
400 print("Prosody "..(prosody.version or "(unknown version)")); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
401 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
402 print("# Prosody directories"); |
8635
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
403 print("Data directory: "..relpath(pwd, prosody.paths.data)); |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
404 print("Config directory: "..relpath(pwd, prosody.paths.config or ".")); |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
8561
diff
changeset
|
405 print("Source directory: "..relpath(pwd, prosody.paths.source or ".")); |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
406 print("Plugin directories:") |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
407 print(" "..(prosody.paths.plugins:gsub("([^;]+);?", function(path) |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
408 path = configmanager.resolve_relative_path(pwd, path); |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
409 local hgid, hgrepo = hg.check_id(path); |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
410 if not hgid and hgrepo then |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
411 return path.." - "..hgrepo .."!\n "; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
412 end |
6611
65dd3770bcb0
prosodyctl: Document magic commit ID
Paul Aurich <paul@darkrain42.org>
parents:
6587
diff
changeset
|
413 -- 010452cfaf53 is the first commit in the prosody-modules repository |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
414 hgrepo = hgrepo == "010452cfaf53" and "prosody-modules"; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
415 return path..(hgid and " - "..(hgrepo or "HG").." rev: "..hgid or "") |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
416 .."\n "; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
417 end))); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
418 print(""); |
9826
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
419 local have_pposix, pposix = pcall(require, "util.pposix"); |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
420 if have_pposix and pposix.uname then |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
421 print("# Operating system"); |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
422 local uname, err = pposix.uname(); |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
423 print(uname and uname.sysname .. " " .. uname.release or "Unknown POSIX", err or ""); |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
424 print(""); |
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
425 end |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
426 print("# Lua environment"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
427 print("Lua version: ", _G._VERSION); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
428 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
429 print("Lua module search paths:"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
430 for path in package.path:gmatch("[^;]+") do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
431 print(" "..path); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
432 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
433 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
434 print("Lua C module search paths:"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
435 for path in package.cpath:gmatch("[^;]+") do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
436 print(" "..path); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
437 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
438 print(""); |
8701
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
439 local luarocks_status = "Not installed" |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
440 if pcall(require, "luarocks.loader") then |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
441 luarocks_status = "Installed (2.x+)"; |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
442 if package.loaded["luarocks.cfg"] then |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
443 luarocks_status = "Installed ("..(package.loaded["luarocks.cfg"].program_version or "2.x+")..")"; |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
444 end |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
445 elseif pcall(require, "luarocks.require") then |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
446 luarocks_status = "Installed (1.x)"; |
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
447 end |
4333
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
448 print("LuaRocks: ", luarocks_status); |
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
449 print(""); |
9856
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
450 print("# Network"); |
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
451 print(""); |
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
452 print("Backend: "..require "net.server".get_backend()); |
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
453 print(""); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
454 print("# Lua module versions"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
455 local module_versions, longest_name = {}, 8; |
11003
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
456 local library_versions = {}; |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
457 dependencies.softreq"ssl"; |
9991
8cd180dc18a8
prosodyctl: Include version of LuaDBI in 'about'
Kim Alvefur <zash@zash.se>
parents:
9856
diff
changeset
|
458 dependencies.softreq"DBI"; |
11004
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
459 local friendly_names = { |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
460 DBI = "LuaDBI"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
461 lfs = "LuaFileSystem"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
462 lunbound = "luaunbound"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
463 lxp = "LuaExpat"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
464 socket = "LuaSocket"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
465 ssl = "LuaSec"; |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
466 }; |
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
467 local lunbound = dependencies.softreq"lunbound"; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
468 for name, module in pairs(package.loaded) do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
469 if type(module) == "table" and rawget(module, "_VERSION") |
11004
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
470 and name ~= "_G" and not name:match("%.") then |
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
471 name = friendly_names[name] or name; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
472 if #name > longest_name then |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
473 longest_name = #name; |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
474 end |
11005
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
475 local mod_version = module._VERSION; |
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
476 if tostring(mod_version):sub(1, #name+1) == name .. " " then |
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
477 mod_version = mod_version:sub(#name+2); |
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
478 end |
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
479 module_versions[name] = mod_version; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
480 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
481 end |
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
482 if lunbound then |
11006
8ac958938e0f
prosodyctl about: Show longer name for luaunbound
Kim Alvefur <zash@zash.se>
parents:
11005
diff
changeset
|
483 if not module_versions["luaunbound"] then |
8ac958938e0f
prosodyctl about: Show longer name for luaunbound
Kim Alvefur <zash@zash.se>
parents:
11005
diff
changeset
|
484 module_versions["luaunbound"] = "0.5 (?)"; |
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
485 end |
11003
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
486 library_versions["libunbound"] = lunbound._LIBVER; |
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
487 end |
11002
b0766f2603e9
prosodyctl about: Use library function for sorted listing of lua modules
Kim Alvefur <zash@zash.se>
parents:
10964
diff
changeset
|
488 for name, version in sorted_pairs(module_versions) do |
b0766f2603e9
prosodyctl about: Use library function for sorted listing of lua modules
Kim Alvefur <zash@zash.se>
parents:
10964
diff
changeset
|
489 print(name..":"..string.rep(" ", longest_name-#name), version); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
490 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
491 print(""); |
11003
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
492 print("# library versions"); |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
493 if require "net.server".event_base then |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
494 library_versions["libevent"] = require"luaevent".core.libevent_version(); |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
495 end |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
496 for name, version in sorted_pairs(library_versions) do |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
497 print(name..":"..string.rep(" ", longest_name-#name), version); |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
498 end |
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
499 print(""); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
500 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
501 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
502 function commands.reload(arg) |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
503 if arg[1] == "--help" then |
4476
53ce21286b8c
prosodyctl: Adjust description of 'reload' command (thanks crocket)
Matthew Wild <mwild1@gmail.com>
parents:
4336
diff
changeset
|
504 show_usage([[reload]], [[Reload Prosody's configuration and re-open log files]]); |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
505 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
506 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
507 |
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
508 service_command_warning("reload"); |
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
509 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
510 if not prosodyctl.isrunning() then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
511 show_message("Prosody is not running"); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
512 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
513 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
514 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
515 local ok, ret = prosodyctl.reload(); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
516 if ok then |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
517 |
4336
abcbcb15205c
prosodyctl: Update message on reload success
Matthew Wild <mwild1@gmail.com>
parents:
4335
diff
changeset
|
518 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
519 return 0; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
520 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
521 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
522 show_message(error_messages[ret]); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
523 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
524 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
525 -- ejabberdctl compatibility |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
526 |
7920
1db51061342b
prosodyctl: Handle move of 'unpack' in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
7679
diff
changeset
|
527 local unpack = table.unpack or unpack; -- luacheck: ignore 113 |
1db51061342b
prosodyctl: Handle move of 'unpack' in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
7679
diff
changeset
|
528 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
529 function commands.register(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
530 local user, host, password = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
531 if (not (user and host)) or arg[1] == "--help" then |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
532 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
533 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
534 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
535 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
536 show_message [[Please specify which host you want to register the user on]]; |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
537 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
539 show_usage("register USER HOST [PASSWORD]", "Register a user on the server, with the given password"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
540 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
541 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
542 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
543 password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
544 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
545 show_message [[Unable to register user with no password]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
546 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
547 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
548 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
549 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
550 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
551 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
552 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
553 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
554 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
555 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
556 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
557 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
558 function commands.unregister(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
559 local user, host = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
560 if (not (user and host)) or arg[1] == "--help" then |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
561 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
562 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
563 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
564 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
565 show_message [[Please specify which host you want to unregister the user from]]; |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
566 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
567 end |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
568 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
569 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
570 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
571 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
572 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
573 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
574 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
575 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
576 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
577 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
578 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
579 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
580 --------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
581 |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
582 local async = require "util.async"; |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
583 local server = require "net.server"; |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
584 local watchers = { |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
585 error = function (_, err) |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
586 error(err); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
587 end; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
588 waiting = function () |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
589 server.loop(); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
590 end; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
591 }; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
592 local command_runner = async.runner(function () |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
593 if command and command:match("^mod_") then -- Is a command in a module |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
594 local module_name = command:match("^mod_(.+)"); |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
595 do |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
596 local ret, err = modulemanager.load("*", module_name); |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
597 if not ret then |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
598 show_message("Failed to load module '"..module_name.."': "..err); |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
599 os.exit(1); |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
600 end |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
601 end |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
602 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
603 local module = modulemanager.get_module("*", module_name); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
604 if not module then |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
605 show_message("Failed to load module '"..module_name.."': Unknown error"); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
606 os.exit(1); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
607 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
609 if not modulemanager.module_has_method(module, "command") then |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
610 show_message("Fail: mod_"..module_name.." does not support any commands"); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
611 os.exit(1); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
612 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
613 |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
614 local ok, ret = modulemanager.call_module_method(module, "command", arg); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
615 if ok then |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
616 if type(ret) == "number" then |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
617 os.exit(ret); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
618 elseif type(ret) == "string" then |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
619 show_message(ret); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
620 end |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
621 os.exit(0); -- :) |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
622 else |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
623 show_message("Failed to execute command: "..error_messages[ret]); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
624 os.exit(1); -- :( |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
625 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
626 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
627 |
10905
709255e332d8
prosodyctl: Fix traceback when no command provided (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
10871
diff
changeset
|
628 if command and not commands[command] then |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
629 local ok, command_module = pcall(require, "util.prosodyctl."..command); |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
630 if ok and command_module[command] then |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
631 commands[command] = command_module[command]; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
632 end |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
633 end |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
634 |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
635 if not commands[command] then -- Show help for all commands |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
636 function show_usage(usage, desc) |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
637 print(" "..usage); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
638 print(" "..desc); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
639 end |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
640 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
641 print("prosodyctl - Manage a Prosody server"); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
642 print(""); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
643 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
644 print(""); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
645 print("Where COMMAND may be one of:\n"); |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
646 |
11247
4e803e80d7b1
prosodyctl: Remove non-existant command from hidden commands
Kim Alvefur <zash@zash.se>
parents:
11135
diff
changeset
|
647 local hidden_commands = require "util.set".new{ "register", "unregister" }; |
10190
f506964a1123
prosodyctl: Removed the auxiliary command 'enabled_plugins'
João Duarte <jvsDuarte08@gmail.com>
parents:
10188
diff
changeset
|
648 local commands_order = { "install", "remove", "list", "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", |
10170
882ca2f965d5
prosodyctl: Removed the list duplicate at the commands_order variable
João Duarte <jvsDuarte08@gmail.com>
parents:
10169
diff
changeset
|
649 "about" }; |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
650 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
651 local done = {}; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
652 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
653 for _, command_name in ipairs(commands_order) do |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
654 local command_func = commands[command_name]; |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
655 if command_func then |
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
656 command_func{ "--help" }; |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
657 print"" |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
658 done[command_name] = true; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
659 end |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
660 end |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
661 |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
662 for command_name, command_func in pairs(commands) do |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
663 if not done[command_name] and not hidden_commands:contains(command_name) then |
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
664 command_func{ "--help" }; |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
665 print"" |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
666 done[command_name] = true; |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
667 end |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
668 end |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
669 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
670 |
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
671 os.exit(0); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
672 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
673 |
9780
c7727c13260f
prosodyctl: Pass the original argv table to subcommands (with first argument removed)
Kim Alvefur <zash@zash.se>
parents:
9709
diff
changeset
|
674 os.exit(commands[command](arg)); |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
675 end, watchers); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
676 |
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
677 command_runner:run(true); |