Mercurial > prosody-hg
annotate prosodyctl @ 14057:312542dd184d 13.0
prosody: Fix loading local code when also installed system-wide
loader.lua is responsible for adjusting the Lua module loading behavior
to account for legacy code (mostly community modules) that don't load
resources with the 'prosody' namespace prefix, like
`require"prosody.util.json"` rather than `require"util.json"`, as well
as the opposite problem of finding resources with the namespace prefix
in a local source directory, where Lua would look for
`./prosody/util/json.lua` instead of `./util/json.lua`.
Which of these two behaviors is active depends on whether the loader is
loaded as `require"prosody.loader"` or `require"loader"`, the former
being intended for system-wide installations and the later for running
from source.
When you have a system-wide Prosody installed to the standard Lua search
paths, the first attempt to require "prosody.loader" would succeed,
leading to system-wide resources being preferred.
This makes it difficult to run Prosody from source, e.g. a different
version or with local patches, as those changes would be ignored.
This change should make it more likely that the loader is invoked as
just "loader" instead of "prosody.loader", which determines
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 01 Feb 2026 15:22:53 +0100 |
| parents | 5b4efb5b798a |
| children | f20b3f0d892b b085d32af140 |
| 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 |
|
14055
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
20 -- Check before first require, to preempt the probable failure |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
21 if _VERSION < "Lua 5.2" then |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
22 io.stderr:write("Prosody is no longer compatible with Lua 5.1\n") |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
23 io.stderr:write("See https://prosody.im/doc/depends#lua for more information\n") |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
24 return os.exit(1); |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
25 end |
|
f47b4baa7934
prosody: Abort earlier on incompatible Lua version
Kim Alvefur <zash@zash.se>
parents:
13800
diff
changeset
|
26 |
|
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
27 |
|
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
|
28 -- 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
|
29 if CFG_SOURCEDIR then |
|
14057
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
30 -- Installed instance |
|
14056
5b4efb5b798a
prosody: Move function only used once into block where it is used
Kim Alvefur <zash@zash.se>
parents:
14055
diff
changeset
|
31 local function is_relative(path) |
|
5b4efb5b798a
prosody: Move function only used once into block where it is used
Kim Alvefur <zash@zash.se>
parents:
14055
diff
changeset
|
32 local path_sep = package.config:sub(1,1); |
|
5b4efb5b798a
prosody: Move function only used once into block where it is used
Kim Alvefur <zash@zash.se>
parents:
14055
diff
changeset
|
33 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
|
5b4efb5b798a
prosody: Move function only used once into block where it is used
Kim Alvefur <zash@zash.se>
parents:
14055
diff
changeset
|
34 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) |
|
5b4efb5b798a
prosody: Move function only used once into block where it is used
Kim Alvefur <zash@zash.se>
parents:
14055
diff
changeset
|
35 end |
|
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
36 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
|
37 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
|
38 end |
|
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
39 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
|
40 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
|
41 end |
|
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
42 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
|
43 package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath); |
|
14057
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
44 |
|
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
45 require "prosody.loader"; |
|
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
46 else |
|
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
47 -- Not installed, e.g. running from a source checkout |
|
312542dd184d
prosody: Fix loading local code when also installed system-wide
Kim Alvefur <zash@zash.se>
parents:
14056
diff
changeset
|
48 require "loader"; |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 |
|
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
|
51 -- 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
|
52 if CFG_DATADIR then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 if os.getenv("HOME") then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 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
|
55 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
|
12578
10bb58ad5583
executables: Reject Lua 5.1 early
Kim Alvefur <zash@zash.se>
parents:
12452
diff
changeset
|
58 |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
59 local startup = require "prosody.util.startup"; |
|
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
60 startup.prosodyctl(); |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
61 |
|
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
|
62 ----------- |
|
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
63 |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
64 local configmanager = require "prosody.core.configmanager"; |
|
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
65 local modulemanager = require "prosody.core.modulemanager" |
|
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
66 local prosodyctl = require "prosody.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
|
67 local socket = require "socket" |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
68 local dependencies = require "prosody.util.dependencies"; |
|
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
69 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
|
70 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 ----------------------- |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
73 local parse_args = require "prosody.util.argparse".parse; |
|
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
74 local human_io = require "prosody.util.human.io"; |
|
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
75 |
|
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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 |
|
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
82 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
|
83 ----------------------- |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 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
|
85 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
|
86 |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
87 local only_help = { short_params = { h = "help"; ["?"] = "help" } } |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
88 |
|
10141
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
89 function commands.install(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
90 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
91 if opts.help or not arg[1] then |
|
10172
5da519ef2d51
prosodyctl: Corrected the help output of the install and remove commands
João Duarte <jvsDuarte08@gmail.com>
parents:
10170
diff
changeset
|
92 show_usage([[install]], [[Installs a prosody/luarocks plugin]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
93 return opts.help and 0 or 1; |
|
10147
1a35b3a2b11b
prosodyctl: Corrected indentation on my code
João Duarte <jvsDuarte08@gmail.com>
parents:
10146
diff
changeset
|
94 end |
|
11135
56490ffde93f
util.prosodyctl: Get Luarocks server from config
Kim Alvefur <zash@zash.se>
parents:
11134
diff
changeset
|
95 -- TODO finalize config option name |
|
12267
a52a0680fcd8
prosodyctl: Allow passing server on command line with --server
Kim Alvefur <zash@zash.se>
parents:
12266
diff
changeset
|
96 local server = opts.server or configmanager.get("*", "plugin_server"); |
|
12266
24b0c4c4e28a
prosodyctl: Allow install plugin via explicit path or URL
Kim Alvefur <zash@zash.se>
parents:
12265
diff
changeset
|
97 if not (arg[1]:match("^https://") or lfs.attributes(arg[1]) or server) then |
|
11295
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
98 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
|
99 -- see https://prosody.im/doc/TODO documentation |
|
11301
d7f0dc727a47
prosodyctl: Add reference to #1602 (plugin installer docs) in comment
Kim Alvefur <zash@zash.se>
parents:
11300
diff
changeset
|
100 -- #1602 |
|
11295
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
101 return 1; |
|
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
102 end |
|
11300
d0d64655e584
prosodyctl: Move message after condition
Kim Alvefur <zash@zash.se>
parents:
11297
diff
changeset
|
103 show_message("Installing %s in %s", arg[1], prosody.paths.installer); |
|
11295
50ea7d9143ad
prosodyctl: Abort if no plugin source specified for the installer
Kim Alvefur <zash@zash.se>
parents:
11294
diff
changeset
|
104 local ret = call_luarocks("install", arg[1], server); |
|
12266
24b0c4c4e28a
prosodyctl: Allow install plugin via explicit path or URL
Kim Alvefur <zash@zash.se>
parents:
12265
diff
changeset
|
105 if ret == 0 and arg[1]:match("^mod_") then |
|
11297
2e9d4c517919
prosodyctl: Fix copypaste oversight
Kim Alvefur <zash@zash.se>
parents:
11295
diff
changeset
|
106 prosodyctl.show_module_configuration_help(arg[1]); |
|
11294
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
107 end |
|
11293
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
108 return ret; |
|
10141
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
109 end |
|
cf70deac27f6
prosodyctl: Added the 'install' command
João Duarte <jvsDuarte08@gmail.com>
parents:
10140
diff
changeset
|
110 |
|
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
111 function commands.remove(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
112 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
113 if opts.help or not arg[1] then |
|
10202
d3764eed7ded
prosodyctl: Fixed a typo
João Duarte <jvsDuarte08@gmail.com>
parents:
10190
diff
changeset
|
114 show_usage([[remove]], [[Removes a module installed in the working directory's plugins folder]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
115 return opts.help and 0 or 1; |
|
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
116 end |
|
11294
a1939b261f67
prosodyctl: Move UI related calls out of util.prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11293
diff
changeset
|
117 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
|
118 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
|
119 return ret; |
|
10161
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
120 end |
|
ea10561e5566
prosodyctl: Corrected the remove and install commands' order
João Duarte <jvsDuarte08@gmail.com>
parents:
10160
diff
changeset
|
121 |
|
10126
ad640c2e072e
prosodyctl: Implemented the 'list' command, which is a bridge to 'luarocks list'
João Duarte <jvsDuarte08@gmail.com>
parents:
10125
diff
changeset
|
122 function commands.list(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
123 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
124 if opts.help then |
|
10135
3ae2809030dd
prosodyctl: added help support to all my functions
João Duarte <jvsDuarte08@gmail.com>
parents:
10134
diff
changeset
|
125 show_usage([[list]], [[Shows installed rocks]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
126 return 0; |
|
10135
3ae2809030dd
prosodyctl: added help support to all my functions
João Duarte <jvsDuarte08@gmail.com>
parents:
10134
diff
changeset
|
127 end |
|
12452
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
128 local server = opts.server or configmanager.get("*", "plugin_server"); |
|
12292
7fe5cd8a10e2
prosodyctl: Restore 'list --outdated'
Kim Alvefur <zash@zash.se>
parents:
12267
diff
changeset
|
129 if opts.outdated then |
|
7fe5cd8a10e2
prosodyctl: Restore 'list --outdated'
Kim Alvefur <zash@zash.se>
parents:
12267
diff
changeset
|
130 -- put this back for luarocks |
|
7fe5cd8a10e2
prosodyctl: Restore 'list --outdated'
Kim Alvefur <zash@zash.se>
parents:
12267
diff
changeset
|
131 arg[1] = "--outdated"; |
|
12452
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
132 |
|
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
133 if not server then |
|
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
134 show_warning("There is no 'plugin_server' option in the configuration file, but this is needed for 'list --outdated' to work."); |
|
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
135 return 1; |
|
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
136 end |
|
12292
7fe5cd8a10e2
prosodyctl: Restore 'list --outdated'
Kim Alvefur <zash@zash.se>
parents:
12267
diff
changeset
|
137 end |
|
12452
c475a7802169
prosodyctl: Pass server when listing (outdated) plugins (fix #1738)
Kim Alvefur <zash@zash.se>
parents:
12435
diff
changeset
|
138 local ret = call_luarocks("list", arg[1], server); |
|
11293
cd27ac5e5afe
prosodyctl: Use luarocks status code as exit code
Kim Alvefur <zash@zash.se>
parents:
11247
diff
changeset
|
139 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
|
140 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 function commands.adduser(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
143 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
144 if opts.help or not arg[1] then |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
146 return opts.help and 0 or 1; |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
148 |
|
13595
6fafe51df188
prosodyctl: adduser: use shell user:create() to provide the implementation
Matthew Wild <mwild1@gmail.com>
parents:
13167
diff
changeset
|
149 local shell = require "prosody.util.prosodyctl.shell"; |
|
6fafe51df188
prosodyctl: adduser: use shell user:create() to provide the implementation
Matthew Wild <mwild1@gmail.com>
parents:
13167
diff
changeset
|
150 return shell.shell({ ("user:create(%q, nil, %q)"):format(arg[1], "prosody:member") }); |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 function commands.passwd(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
154 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
155 if opts.help or not arg[1] then |
|
1087
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]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
157 return opts.help and 0 or 1; |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
159 |
|
13599
54803fb5b4d4
prosodyctl: passwd: Use user:password() shell command for implementation
Matthew Wild <mwild1@gmail.com>
parents:
13595
diff
changeset
|
160 local shell = require "prosody.util.prosodyctl.shell"; |
|
54803fb5b4d4
prosodyctl: passwd: Use user:password() shell command for implementation
Matthew Wild <mwild1@gmail.com>
parents:
13595
diff
changeset
|
161 return shell.shell({ ("user:password(%q, nil)"):format(arg[1]) }); |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 function commands.deluser(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
165 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
166 if opts.help or not arg[1] then |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 show_usage([[deluser JID]], [[Permanently remove the specified user account from Prosody]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
168 return opts.help and 0 or 1; |
|
1087
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 |
|
13600
854df134274f
prosodyctl: deluser: Use user:delete() shell command for implementation
Matthew Wild <mwild1@gmail.com>
parents:
13599
diff
changeset
|
171 local shell = require "prosody.util.prosodyctl.shell"; |
|
854df134274f
prosodyctl: deluser: Use user:delete() shell command for implementation
Matthew Wild <mwild1@gmail.com>
parents:
13599
diff
changeset
|
172 return shell.shell({ ("user:delete(%q)"):format(arg[1]) }); |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
|
12103
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
175 local function has_init_system() --> which |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
176 lfs = lfs or require"lfs"; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
177 if lfs.attributes("/etc/systemd") then |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
178 return "systemd"; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
179 elseif lfs.attributes("/etc/init.d/prosody") then |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
180 return "rc.d"; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
181 end |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
182 end |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
183 |
|
10610
b9a054ad38e7
prosodyctl: Fix some luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
10608
diff
changeset
|
184 local function service_command_warning(service_command) |
|
13653
e0bbf85edc21
prosodyctl: Fix check for whether to show init system warning
Matthew Wild <mwild1@gmail.com>
parents:
13651
diff
changeset
|
185 if prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
186 show_warning("ERROR: Use of 'prosodyctl %s' is disabled in this installation because", service_command); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
187 |
|
12103
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
188 local init = has_init_system() |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
189 if init then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
190 show_warning(" we detected that this system uses %s for managing services.", init); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
191 show_warning(""); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
192 show_warning(" To avoid problems, use that directly instead. For example:"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
193 show_warning(""); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
194 if init == "systemd" then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
195 show_warning(" systemctl %s prosody", service_command); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
196 elseif init == "rc.d" then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
197 show_warning(" /etc/init.d/prosody %s", service_command); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
198 end |
|
13800
883d9d0ccd64
prosodyctl: Fix spacing in warning message
Matthew Wild <mwild1@gmail.com>
parents:
13653
diff
changeset
|
199 show_warning(""); |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
200 else |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
201 show_warning(" it may conflict with your system's service manager."); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
202 show_warning(""); |
|
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
203 end |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
204 |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
205 show_warning(" Proceeding to use prosodyctl may cause process management issues."); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
206 show_warning(" You can pass --force to override this warning, or set"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
207 show_warning(" prosodyctl_service_warnings = false in your global config."); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
208 |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
209 os.exit(1); |
|
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
210 end |
|
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
211 end |
|
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
212 |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
213 function commands.start(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
214 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
215 if opts.help then |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
216 show_usage([[start]], [[Start Prosody]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
217 return 0; |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
218 end |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
219 if not opts.force then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
220 service_command_warning("start"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
221 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 local ok, ret = prosodyctl.isrunning(); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 if not ok then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 show_message(error_messages[ret]); |
|
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 |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
227 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 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
|
229 --luacheck: ignore 421/ret |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 local ok, ret = prosodyctl.getpid(); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 if not ok then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 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
|
233 show_message(error_messages[ret]); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 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
|
237 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
239 |
|
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
240 --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
|
241 local lua; |
|
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
242 do |
|
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
243 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
|
244 repeat |
|
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 end |
|
1acfd25cd507
prosodyctl: Fix extraction of interpreter from arg when additional arguments (fixes #1386)
Kim Alvefur <zash@zash.se>
parents:
9992
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 show_message("Failed to start Prosody"); |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
276 show_message(error_messages[ret]) |
|
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
277 return 1; |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
280 function commands.status(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
281 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
282 if opts.help then |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
283 show_usage([[status]], [[Reports the running status of Prosody]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
284 return 0; |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
285 end |
|
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
286 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 local ok, ret = prosodyctl.isrunning(); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 if not ok then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 show_message(error_messages[ret]); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
292 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 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
|
294 --luacheck: ignore 421/ret |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 local ok, ret = prosodyctl.getpid(); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 if not ok then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 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
|
298 show_message(error_messages[ret]); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 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
|
302 return 0; |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
303 else |
|
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
304 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
|
305 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
|
306 print("\nNote:") |
|
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 end |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
311 return 2 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
315 function commands.stop(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
316 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
317 if opts.help then |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
318 show_usage([[stop]], [[Stop a running Prosody server]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
319 return 0; |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
320 end |
|
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
321 |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
322 if not opts.force then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
323 service_command_warning("stop"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
324 end |
|
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
325 |
|
13646
4e7ac0e8dfc4
prosodyctl: stop: Fix detection of whether Prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13645
diff
changeset
|
326 local ok, running = prosodyctl.isrunning(); |
|
4e7ac0e8dfc4
prosodyctl: stop: Fix detection of whether Prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13645
diff
changeset
|
327 if not ok then |
|
4e7ac0e8dfc4
prosodyctl: stop: Fix detection of whether Prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13645
diff
changeset
|
328 show_message(error_messages[running]); |
|
4e7ac0e8dfc4
prosodyctl: stop: Fix detection of whether Prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13645
diff
changeset
|
329 return 1; |
|
4e7ac0e8dfc4
prosodyctl: stop: Fix detection of whether Prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13645
diff
changeset
|
330 elseif not running then |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 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
|
332 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
334 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 while true do |
|
13649
d2969e163656
prosodyctl: Fix luacheck warning
Matthew Wild <mwild1@gmail.com>
parents:
13648
diff
changeset
|
339 local ok, running = prosodyctl.isrunning(); --luacheck: ignore 421 |
|
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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 |
|
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
355 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
|
356 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 |
|
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
359 function commands.restart(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
360 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
361 if opts.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
|
362 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
|
363 return 1; |
|
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
364 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
365 |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
366 if not opts.force then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
367 service_command_warning("restart"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
368 end |
|
10608
87003b937672
Log warning when using prosodyctl start/stop/restart
Matthew Wild <mwild1@gmail.com>
parents:
10578
diff
changeset
|
369 |
|
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
|
370 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
|
371 return commands.start(arg); |
|
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
372 end |
|
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
373 |
|
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
374 function commands.about(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
375 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
376 if opts.help then |
|
4331
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
377 show_usage([[about]], [[Show information about this Prosody installation]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
378 return 0; |
|
4331
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
379 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
380 |
|
6584
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
381 local pwd = "."; |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
382 local sorted_pairs = require "prosody.util.iterators".sorted_pairs; |
|
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
383 local hg = require"prosody.util.mercurial"; |
|
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
384 local relpath = configmanager.resolve_relative_path; |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
385 |
|
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
386 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
|
387 print(""); |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 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
|
392 print("Plugin directories:") |
|
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 end |
|
6611
65dd3770bcb0
prosodyctl: Document magic commit ID
Paul Aurich <paul@darkrain42.org>
parents:
6587
diff
changeset
|
399 -- 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
|
400 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
|
401 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
|
402 .."\n "; |
|
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
403 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
|
404 print(""); |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
405 local have_pposix, pposix = pcall(require, "prosody.util.pposix"); |
|
9826
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
406 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
|
407 print("# Operating system"); |
|
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
408 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
|
409 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
|
410 print(""); |
|
bdc2a024933b
prosodyctl: about: Report the current operating system according to uname
Kim Alvefur <zash@zash.se>
parents:
9798
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 print(""); |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 end |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
419 print(""); |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
420 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
|
421 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
|
422 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
|
423 end |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
424 print(""); |
|
8701
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
425 local luarocks_status = "Not installed" |
|
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
426 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
|
427 luarocks_status = "Installed (2.x+)"; |
|
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
428 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
|
429 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
|
430 end |
|
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
431 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
|
432 luarocks_status = "Installed (1.x)"; |
|
b7a22baaf55f
prosodyctl: Increase robustness in luarocks version detection (fixes #1003)
Kim Alvefur <zash@zash.se>
parents:
8671
diff
changeset
|
433 end |
|
4333
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
434 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
|
435 print(""); |
|
9856
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
436 print("# Network"); |
|
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
437 print(""); |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
438 print("Backend: "..require "prosody.net.server".get_backend()); |
|
9856
4be2af104bf0
prosodyctl about: Report network backend in use
Matthew Wild <mwild1@gmail.com>
parents:
9709
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 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
|
443 dependencies.softreq"ssl"; |
|
9991
8cd180dc18a8
prosodyctl: Include version of LuaDBI in 'about'
Kim Alvefur <zash@zash.se>
parents:
9856
diff
changeset
|
444 dependencies.softreq"DBI"; |
|
12435
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
445 dependencies.softreq"readline"; |
|
11004
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
446 local friendly_names = { |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
447 DBI = "LuaDBI"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
448 lfs = "LuaFileSystem"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
449 lunbound = "luaunbound"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
450 lxp = "LuaExpat"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
451 socket = "LuaSocket"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
452 ssl = "LuaSec"; |
|
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
453 }; |
|
12435
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
454 local alternate_version_fields = { |
|
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
455 -- These diverge from the module._VERSION convention |
|
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
456 readline = "Version"; |
|
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
457 } |
|
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
458 local lunbound = dependencies.softreq"lunbound"; |
| 11560 | 459 local lxp = dependencies.softreq"lxp"; |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
460 local hashes = dependencies.softreq"prosody.util.hashes"; |
|
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
461 for name, module in pairs(package.loaded) do |
|
12435
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
462 local version_field = alternate_version_fields[name] or "_VERSION"; |
|
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
463 if type(module) == "table" and rawget(module, version_field) |
|
11004
d175de07dd73
prosodyctl about: Substitute better names for some Lua modules
Kim Alvefur <zash@zash.se>
parents:
11003
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 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
|
468 end |
|
12435
1ee72c0013f3
prosodyctl about: Report version of lua-readline
Kim Alvefur <zash@zash.se>
parents:
12292
diff
changeset
|
469 local mod_version = module[version_field]; |
|
11005
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
470 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
|
471 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
|
472 end |
|
cff243aafdce
prosodyctl about: Strip name from lua module _VERSION
Kim Alvefur <zash@zash.se>
parents:
11004
diff
changeset
|
473 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
|
474 end |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
475 end |
|
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
476 if lunbound then |
|
11006
8ac958938e0f
prosodyctl about: Show longer name for luaunbound
Kim Alvefur <zash@zash.se>
parents:
11005
diff
changeset
|
477 if not module_versions["luaunbound"] then |
|
8ac958938e0f
prosodyctl about: Show longer name for luaunbound
Kim Alvefur <zash@zash.se>
parents:
11005
diff
changeset
|
478 module_versions["luaunbound"] = "0.5 (?)"; |
|
10964
d6a3d652ca32
prosodyctl about: Report versions of luaunbound and libunbound
Kim Alvefur <zash@zash.se>
parents:
10905
diff
changeset
|
479 end |
|
11003
c82ede8892fc
prosodyctl about: Split out libraries into a separate section
Kim Alvefur <zash@zash.se>
parents:
11002
diff
changeset
|
480 library_versions["libunbound"] = lunbound._LIBVER; |
|
7249
c49f69bb68f7
prosodyctl: Include libevent version in "about" output if luaevent is available
Kim Alvefur <zash@zash.se>
parents:
7213
diff
changeset
|
481 end |
|
11552
d4b735272a61
prosodyctl about: Report libexpat version if known
Matthew Wild <mwild1@gmail.com>
parents:
11529
diff
changeset
|
482 if lxp then |
| 11560 | 483 library_versions["libexpat"] = lxp._EXPAT_VERSION; |
| 484 end | |
|
11563
0983653cbfdf
prosodyctl: Report OpenSSL version
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
485 if hashes then |
|
0983653cbfdf
prosodyctl: Report OpenSSL version
Kim Alvefur <zash@zash.se>
parents:
11560
diff
changeset
|
486 library_versions["libcrypto"] = hashes._LIBCRYPTO_VERSION; |
|
0983653cbfdf
prosodyctl: Report OpenSSL version
Kim Alvefur <zash@zash.se>
parents:
11560
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); |
|
11552
d4b735272a61
prosodyctl about: Report libexpat version if known
Matthew Wild <mwild1@gmail.com>
parents:
11529
diff
changeset
|
490 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
|
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"); |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
493 if require "prosody.net.server".event_base then |
|
11003
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); |
|
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
498 end |
|
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
499 print(""); |
|
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 |
|
13609
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
502 function commands.version(arg) |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
503 local flags = { short_params = { h = "help"; ["?"] = "help", v = "verbose" } }; |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
504 local opts = parse_args(arg, flags); |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
505 if opts.help then |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
506 show_usage("version [-v]", [[Show current Prosody version, or more]]); |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
507 return 0; |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
508 elseif opts.verbose then |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
509 return commands.about(arg); |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
510 end |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
511 |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
512 print("Prosody "..(prosody.version or "(unknown version)")); |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
513 end |
|
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
514 |
|
13610
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
515 function commands.lua_paths() |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
516 local function shell_escape(s) |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
517 return "'" .. tostring(s):gsub("'",[['\'']]) .. "'"; |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
518 end |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
519 |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
520 print("LUA_PATH="..shell_escape(package.path)); |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
521 print("LUA_CPATH="..shell_escape(package.cpath)); |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
522 end |
|
ff0f4d1f16c8
prosodyctl: Add lua_paths command to print the LUA_PATH and LUA_CPATH used
Matthew Wild <mwild1@gmail.com>
parents:
13609
diff
changeset
|
523 |
|
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
524 function commands.reload(arg) |
|
12264
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
525 local opts = parse_args(arg, only_help); |
|
ba712f7559dc
prosodyctl: Use argument parsing library to parse --help, -h, -?
Kim Alvefur <zash@zash.se>
parents:
12103
diff
changeset
|
526 if opts.help then |
|
4476
53ce21286b8c
prosodyctl: Adjust description of 'reload' command (thanks crocket)
Matthew Wild <mwild1@gmail.com>
parents:
4336
diff
changeset
|
527 show_usage([[reload]], [[Reload Prosody's configuration and re-open log files]]); |
|
12265
47d5233a1fc7
prosodyctl: Return success status code from --help
Kim Alvefur <zash@zash.se>
parents:
12264
diff
changeset
|
528 return 0; |
|
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
529 end |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
530 |
|
13644
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
531 local shell = require "prosody.util.prosodyctl.shell"; |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
532 if shell.available() then |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
533 if arg[1] and arg[1]:match"^mod_" then |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
534 -- TODO reword the usage text, document |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
535 arg[1] = arg[1]:match("^mod_(.*)"); -- strip mod_ prefix |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
536 table.insert(arg, 1, "module"); |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
537 table.insert(arg, 2, "reload"); |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
538 return shell.shell(arg); |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
539 end |
|
263ae995bc86
prosodyctl: reload: use admin socket to issue reload command, if available
Matthew Wild <mwild1@gmail.com>
parents:
13612
diff
changeset
|
540 return shell.shell({ "config", "reload" }); |
|
13650
9a66b53a5076
prosodyctl: reload: Assume reload-via-socket if any arguments passed
Matthew Wild <mwild1@gmail.com>
parents:
13649
diff
changeset
|
541 elseif arg[1] then |
|
9a66b53a5076
prosodyctl: reload: Assume reload-via-socket if any arguments passed
Matthew Wild <mwild1@gmail.com>
parents:
13649
diff
changeset
|
542 show_message("Admin socket not found - is it enabled and is Prosody running?"); |
|
9a66b53a5076
prosodyctl: reload: Assume reload-via-socket if any arguments passed
Matthew Wild <mwild1@gmail.com>
parents:
13649
diff
changeset
|
543 return 1; |
|
13167
6226f75f55a7
prosodyctl: Add experimental way to reload specific modules directly
Kim Alvefur <zash@zash.se>
parents:
13059
diff
changeset
|
544 end |
|
6226f75f55a7
prosodyctl: Add experimental way to reload specific modules directly
Kim Alvefur <zash@zash.se>
parents:
13059
diff
changeset
|
545 |
|
13645
7f6f0e47624a
prosodyctl: reload: Fix detection of whether prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13644
diff
changeset
|
546 local ok, running = prosodyctl.isrunning(); |
|
7f6f0e47624a
prosodyctl: reload: Fix detection of whether prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13644
diff
changeset
|
547 if not ok then |
|
7f6f0e47624a
prosodyctl: reload: Fix detection of whether prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13644
diff
changeset
|
548 show_message(error_messages[running]); |
|
7f6f0e47624a
prosodyctl: reload: Fix detection of whether prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13644
diff
changeset
|
549 return 1; |
|
7f6f0e47624a
prosodyctl: reload: Fix detection of whether prosody is running
Matthew Wild <mwild1@gmail.com>
parents:
13644
diff
changeset
|
550 elseif not running then |
|
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
551 show_message("Prosody is not running"); |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
552 return 1; |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
553 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
554 |
|
13651
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
555 if not opts.force then |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
556 service_command_warning("reload"); |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
557 end |
|
b9d369f77121
prosodyctl: Further deprecate start/stop/restart commands when installed
Matthew Wild <mwild1@gmail.com>
parents:
13650
diff
changeset
|
558 |
|
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
559 local ok, ret = prosodyctl.reload(); |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
560 if ok then |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
561 |
|
4336
abcbcb15205c
prosodyctl: Update message on reload success
Matthew Wild <mwild1@gmail.com>
parents:
4335
diff
changeset
|
562 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
|
563 return 0; |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
564 end |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
565 |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
566 show_message(error_messages[ret]); |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
567 return 1; |
|
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
568 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
569 -- ejabberdctl compatibility |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
570 |
|
12589
39ae08180c81
compat: Remove handling of Lua 5.1 location of 'unpack' function
Kim Alvefur <zash@zash.se>
parents:
12578
diff
changeset
|
571 local unpack = table.unpack; |
|
7920
1db51061342b
prosodyctl: Handle move of 'unpack' in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
7679
diff
changeset
|
572 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
573 function commands.register(arg) |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
574 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
|
575 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
|
576 if user ~= "--help" then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
577 if not user then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
578 show_message [[No username specified]] |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
579 elseif not host then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
580 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
|
581 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
582 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
583 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
|
584 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
585 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
586 if not password then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
587 password = read_password(); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
588 if not password then |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
589 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
|
590 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
591 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
593 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
594 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
|
595 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
596 if ok then return 0; end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
597 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 show_message(error_messages[msg]) |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
601 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
602 function commands.unregister(arg) |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
603 local user, host = unpack(arg); |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
604 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
|
605 if user ~= "--help" then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
606 if not user then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
607 show_message [[No username specified]] |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
608 elseif not host then |
|
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
609 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
|
610 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
611 end |
|
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
612 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
|
613 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
615 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
617 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
618 if ok then return 0; end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
619 |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
620 show_message(error_messages[msg]) |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 return 1; |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
622 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
624 --------------------- |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
625 |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
626 local async = require "prosody.util.async"; |
|
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
627 local server = require "prosody.net.server"; |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
628 local watchers = { |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
629 error = function (_, err) |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
630 error(err); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
631 end; |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
632 waiting = function () |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
633 server.loop(); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
634 end; |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
635 }; |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
636 local command_runner = async.runner(function () |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
637 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
|
638 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
|
639 do |
|
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 os.exit(1); |
|
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
644 end |
|
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
645 end |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
646 |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
647 local module = modulemanager.get_module("*", module_name); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
648 if not module then |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
649 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
|
650 os.exit(1); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
651 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
652 |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
653 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
|
654 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
|
655 os.exit(1); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
656 end |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
657 |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
658 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
|
659 if ok then |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
660 if type(ret) == "number" then |
|
12863
891edd1ebde6
util.startup: Close state on exit to ensure GC finalizers are called
Kim Alvefur <zash@zash.se>
parents:
12452
diff
changeset
|
661 os.exit(ret, true); |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
662 elseif type(ret) == "string" then |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
663 show_message(ret); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
664 end |
|
12863
891edd1ebde6
util.startup: Close state on exit to ensure GC finalizers are called
Kim Alvefur <zash@zash.se>
parents:
12452
diff
changeset
|
665 os.exit(0, true); -- :) |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
666 else |
|
13057
20b1526772d2
prosodyctl: Fix using variable content in a format string
Matthew Wild <mwild1@gmail.com>
parents:
12863
diff
changeset
|
667 show_message("Failed to execute command: %s", error_messages[ret]); |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
668 os.exit(1); -- :( |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
669 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
670 end |
|
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
671 |
|
10905
709255e332d8
prosodyctl: Fix traceback when no command provided (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
10871
diff
changeset
|
672 if command and not commands[command] then |
|
12971
7214baed9e9d
executables: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12954
diff
changeset
|
673 local ok, command_module = pcall(require, "prosody.util.prosodyctl."..command); |
|
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
674 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
|
675 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
|
676 end |
|
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
677 end |
|
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
678 |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
679 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
|
680 function show_usage(usage, desc) |
|
13609
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
681 print(string.format(" %-14s %s", usage, desc)); |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
682 end |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
683 |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
684 print("prosodyctl - Manage a Prosody server"); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
685 print(""); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
686 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
687 print(""); |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
688 print("Where COMMAND may be one of:"); |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
689 |
|
13612
8617f5962e47
prosodyctl: Hide the 'lua_paths' command from default command listing
Kim Alvefur <zash@zash.se>
parents:
13610
diff
changeset
|
690 local hidden_commands = require "prosody.util.set".new{ "register", "unregister", "lua_paths" }; |
|
12102
949c2b52f51e
prosodyctl: Reorder help sections
Kim Alvefur <zash@zash.se>
parents:
11884
diff
changeset
|
691 local commands_order = { |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
692 "Process management:", |
|
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
693 "start"; "stop"; "restart"; "reload"; "status"; |
|
11691
a6c18f434d7b
prosodyctl: Add 'shell' to command listing
Kim Alvefur <zash@zash.se>
parents:
11690
diff
changeset
|
694 "shell", |
|
12102
949c2b52f51e
prosodyctl: Reorder help sections
Kim Alvefur <zash@zash.se>
parents:
11884
diff
changeset
|
695 "User management:", |
|
949c2b52f51e
prosodyctl: Reorder help sections
Kim Alvefur <zash@zash.se>
parents:
11884
diff
changeset
|
696 "adduser"; "passwd"; "deluser"; |
|
949c2b52f51e
prosodyctl: Reorder help sections
Kim Alvefur <zash@zash.se>
parents:
11884
diff
changeset
|
697 "Plugin management:", |
|
949c2b52f51e
prosodyctl: Reorder help sections
Kim Alvefur <zash@zash.se>
parents:
11884
diff
changeset
|
698 "install"; "remove"; "list"; |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
699 "Informative:", |
|
11690
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
700 "check", |
|
13609
c0b6b6a12228
prosodyctl: 'about' becomes 'version -v', 'version' prints only version
Matthew Wild <mwild1@gmail.com>
parents:
13606
diff
changeset
|
701 "version", |
|
11692
d1e7f5b2f524
prosodyctl: Add cert to command listing
Kim Alvefur <zash@zash.se>
parents:
11691
diff
changeset
|
702 "Other:", |
|
d1e7f5b2f524
prosodyctl: Add cert to command listing
Kim Alvefur <zash@zash.se>
parents:
11691
diff
changeset
|
703 "cert", |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
704 }; |
|
11690
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
705 -- These live in util.prosodyctl.$command so we have their short help here. |
|
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
706 local external_commands = { |
|
11692
d1e7f5b2f524
prosodyctl: Add cert to command listing
Kim Alvefur <zash@zash.se>
parents:
11691
diff
changeset
|
707 cert = "Certificate management commands", |
|
11690
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
708 check = "Perform basic checks on your Prosody installation", |
|
11691
a6c18f434d7b
prosodyctl: Add 'shell' to command listing
Kim Alvefur <zash@zash.se>
parents:
11690
diff
changeset
|
709 shell = "Interact with a running Prosody", |
|
11690
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
710 } |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
711 |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
712 local done = {}; |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
713 |
|
12103
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
714 if prosody.installed and has_init_system() then |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
715 -- Hide start, stop, restart |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
716 done[table.remove(commands_order, 2)] = true; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
717 done[table.remove(commands_order, 2)] = true; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
718 done[table.remove(commands_order, 2)] = true; |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
719 end |
|
fc297128c33a
prosodyctl: Hide process management commands when init system should be used instead
Kim Alvefur <zash@zash.se>
parents:
12102
diff
changeset
|
720 |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
721 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
|
722 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
|
723 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
|
724 command_func{ "--help" }; |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
725 done[command_name] = true; |
|
11690
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
726 elseif external_commands[command_name] then |
|
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
727 show_usage(command_name, external_commands[command_name]); |
|
4e36a1e7222b
prosodyctl: Add 'check' to command listing (fixes #1622)
Kim Alvefur <zash@zash.se>
parents:
11587
diff
changeset
|
728 done[command_name] = true; |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
729 else |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
730 print"" |
|
11582
a3d48204ec95
prosodyctl: Reorganize help / command list
Kim Alvefur <zash@zash.se>
parents:
11563
diff
changeset
|
731 print(command_name); |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
732 end |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
733 end |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
734 |
|
8671
a4899174a894
prosodyctl: Large number of changes to satisfy [luacheck], includes bug fixes
Matthew Wild <mwild1@gmail.com>
parents:
8668
diff
changeset
|
735 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
|
736 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
|
737 command_func{ "--help" }; |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
738 done[command_name] = true; |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
739 end |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
740 end |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
741 |
|
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
742 |
|
12863
891edd1ebde6
util.startup: Close state on exit to ensure GC finalizers are called
Kim Alvefur <zash@zash.se>
parents:
12452
diff
changeset
|
743 os.exit(0, true); |
|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
744 end |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
745 |
|
12863
891edd1ebde6
util.startup: Close state on exit to ensure GC finalizers are called
Kim Alvefur <zash@zash.se>
parents:
12452
diff
changeset
|
746 os.exit(commands[command](arg), true); |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
747 end, watchers); |
|
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
748 |
|
8652
03bb534593cb
prosodyctl: Run commands inside async context
Matthew Wild <mwild1@gmail.com>
parents:
8635
diff
changeset
|
749 command_runner:run(true); |
