annotate util/prosodyctl.lua @ 14184:d79ef7a38fe8 13.0

mod_carbons: Fix 'to' attribute of stanzas to own account This code intended to clarify the 'to' address on the forwarded stanza, however it updated the original stanza instead of the clone.
author Matthew Wild <mwild1@gmail.com>
date Mon, 25 May 2026 16:20:02 +0100
parents 0235fee459d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2796
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2796
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
4 --
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
8
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
10 local config = require "prosody.core.configmanager";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
11 local encodings = require "prosody.util.encodings";
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local stringprep = encodings.stringprep;
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
13 local storagemanager = require "prosody.core.storagemanager";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
14 local usermanager = require "prosody.core.usermanager";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
15 local interpolation = require "prosody.util.interpolation";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
16 local signal = require "prosody.util.signal";
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
17 local path = require"prosody.util.paths";
2794
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
18 local lfs = require "lfs";
4485
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
19 local type = type;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
21 local have_socket_unix, socket_unix = pcall(require, "socket.unix");
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
22 have_socket_unix = have_socket_unix and type(socket_unix) == "table"; -- was a function in older LuaSocket
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
23
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 local io, os = io, os;
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: 3777
diff changeset
27 local print = print;
7259
d8300985f2bb net.websocket.frames, util.datetime, util.json, util.prosodyctl, util.rfc6724: Remove unused variables [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 6777
diff changeset
28 local tonumber = tonumber;
1130
442c87de8e2d util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents: 1123
diff changeset
29
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: 3777
diff changeset
30 local _G = _G;
3294
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
31 local prosody = prosody;
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
32
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
33 local error_messages = setmetatable({
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
34 ["invalid-username"] = "The given username is invalid in a Jabber ID";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
35 ["invalid-hostname"] = "The given hostname is invalid";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
36 ["no-password"] = "No password was supplied";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
37 ["no-such-user"] = "The given user does not exist on the server";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
38 ["no-such-host"] = "The given hostname does not exist in the config";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
39 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
40 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see https://prosody.im/doc/prosodyctl#pidfile for help";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
41 ["invalid-pidfile"] = "The 'pidfile' option in the configuration file is not a string, see https://prosody.im/doc/prosodyctl#pidfile for help";
13647
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
42 ["pidfile-not-locked"] = "Stale pidfile found. Prosody is probably not running.";
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
43 ["no-posix"] = "The mod_posix module is not enabled in the Prosody config file, see https://prosody.im/doc/prosodyctl for more info";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
44 ["no-such-method"] = "This module has no commands";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
45 ["not-running"] = "Prosody is not running";
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
46 }, { __index = function (_,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end });
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
47
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: 3777
diff changeset
48 -- UI helpers
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
49 local show_message = require "prosody.util.human.io".printf;
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: 3777
diff changeset
50
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
51 local function show_usage(usage, desc)
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: 3777
diff changeset
52 print("Usage: ".._G.arg[0].." "..usage);
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: 3777
diff changeset
53 if desc then
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: 3777
diff changeset
54 print(" "..desc);
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: 3777
diff changeset
55 end
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: 3777
diff changeset
56 end
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: 3777
diff changeset
57
10152
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
58 local function show_module_configuration_help(mod_name)
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
59 print("Done.")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
60 print("If you installed a prosody plugin, don't forget to add its name under the 'modules_enabled' section inside your configuration file.")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
61 print("Depending on the module, there might be further configuration steps required.")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
62 print("")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
63 print("More info about: ")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
64 print(" modules_enabled: https://prosody.im/doc/modules_enabled")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
65 print(" "..mod_name..": https://modules.prosody.im/"..mod_name..".html")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
66 end
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
67
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: 3777
diff changeset
68 -- Server control
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
69 local function adduser(params)
10367
649acbfbf7fe util.prosodyctl: Enforce strict JID validation on user creation
Kim Alvefur <zash@zash.se>
parents: 10209
diff changeset
70 local user, host, password = nodeprep(params.user, true), nameprep(params.host), params.password;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 if not user then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 return false, "invalid-username";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 elseif not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 return false, "invalid-hostname";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 end
3294
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
76
4501
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
77 local host_session = prosody.hosts[host];
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
78 if not host_session then
4499
55ef5d83d00a util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
79 return false, "no-such-host";
55ef5d83d00a util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
80 end
5524
e9090966c803 util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents: 5379
diff changeset
81
e9090966c803 util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents: 5379
diff changeset
82 storagemanager.initialize_host(host);
4501
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
83 local provider = host_session.users;
3294
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
84 if not(provider) or provider.name == "null" then
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
85 usermanager.initialize_host(host);
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
86 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
87
3777
5ecbcef42ffb mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3771
diff changeset
88 local ok, errmsg = usermanager.create_user(user, password, host);
1123
da7ff11a03ee util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
89 if not ok then
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
90 return false, errmsg or "creating-user-failed";
1123
da7ff11a03ee util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
91 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
95 local function user_exists(params)
7262
751a4832adb4 util.prosodyctl: Remove unused variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 7259
diff changeset
96 local user, host = nodeprep(params.user), nameprep(params.host);
5524
e9090966c803 util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents: 5379
diff changeset
97
e9090966c803 util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents: 5379
diff changeset
98 storagemanager.initialize_host(host);
3711
2a1cfaf3ee61 util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents: 3627
diff changeset
99 local provider = prosody.hosts[host].users;
3294
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
100 if not(provider) or provider.name == "null" then
3711
2a1cfaf3ee61 util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents: 3627
diff changeset
101 usermanager.initialize_host(host);
3294
89dd67cc3689 util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
102 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
103
3711
2a1cfaf3ee61 util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents: 3627
diff changeset
104 return usermanager.user_exists(user, host);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
107 local function passwd(params)
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
108 if not user_exists(params) then
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 return false, "no-such-user";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
111
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
112 return adduser(params);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
115 local function deluser(params)
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
116 if not user_exists(params) then
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 return false, "no-such-user";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
5102
ae8a993b598d util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents: 5023
diff changeset
119 local user, host = nodeprep(params.user), nameprep(params.host);
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
120
5102
ae8a993b598d util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents: 5023
diff changeset
121 return usermanager.delete_user(user, host);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
124 local function getpid()
5379
27de7cc94111 util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents: 5102
diff changeset
125 local pidfile = config.get("*", "pidfile");
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 if not pidfile then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 return false, "no-pidfile";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 end
6356
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
129
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
130 if type(pidfile) ~= "string" then
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
131 return false, "invalid-pidfile";
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
132 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
133
8123
bd591c5fc1bf util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents: 7457
diff changeset
134 pidfile = config.resolve_relative_path(prosody.paths.data, pidfile);
bd591c5fc1bf util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents: 7457
diff changeset
135
14128
0235fee459d0 util.prosodyctl: Don't check for mod_posix being disabled, it's deprecated
Matthew Wild <mwild1@gmail.com>
parents: 13647
diff changeset
136 if prosody.platform ~= "posix" then
3627
9e62937c9757 prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents: 3307
diff changeset
137 return false, "no-posix";
9e62937c9757 prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents: 3307
diff changeset
138 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
139
2796
1e287badd033 prosodyctl: Use mode r+ for opening the file so 1) it fails if the file doesn't exist 2) we have write access to lock it
Matthew Wild <mwild1@gmail.com>
parents: 2794
diff changeset
140 local file, err = io.open(pidfile, "r+");
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 if not file then
1515
9991329e6b67 util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents: 1130
diff changeset
142 return false, "pidfile-read-failed", err;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
144
13647
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
145 -- Check for a lock on the file
10536
a469d2bcea96 util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10367
diff changeset
146 local locked, err = lfs.lock(file, "w"); -- luacheck: ignore 211/err
2794
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
147 if locked then
13647
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
148 -- Prosody keeps the pidfile locked while it is running.
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
149 -- We successfully locked the file, which means Prosody is not
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
150 -- running and the pidfile is stale (somehow it was not
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
151 -- cleaned up). We'll abort here, to avoid sending signals to
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
152 -- a non-Prosody PID.
2794
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
153 file:close();
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
154 return false, "pidfile-not-locked";
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
155 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
156
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 local pid = tonumber(file:read("*a"));
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 file:close();
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
159
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 if not pid then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 return false, "invalid-pid";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
163
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 return true, pid;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
167 local function isrunning()
10536
a469d2bcea96 util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10367
diff changeset
168 local ok, pid, err = getpid(); -- luacheck: ignore 211/err
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 if not ok then
2794
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
170 if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 -- Report as not running, since we can't open the pidfile
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 -- (it probably doesn't exist)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 return true, false;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 return ok, pid;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 return true, signal.kill(pid, 0) == 0;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179
9781
161411a41377 util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents: 8883
diff changeset
180 local function start(source_dir, lua)
161411a41377 util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents: 8883
diff changeset
181 lua = lua and lua .. " " or "";
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
182 local ok, ret = isrunning();
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 return ok, ret;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 if ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 return false, "already-running";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 end
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
189 local notify_socket;
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
190 if have_socket_unix then
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
191 local notify_path = path.join(prosody.paths.data, "notify.sock");
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
192 os.remove(notify_path);
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
193 lua = string.format("NOTIFY_SOCKET=%q %s", notify_path, lua);
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
194 notify_socket = socket_unix.dgram();
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
195 local ok = notify_socket:setsockname(notify_path);
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
196 if not ok then return false, "notify-failed"; end
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
197 end
8668
31c5abd49dfe prosodyctl, util.prosodyctl: Pass source path as a parameter instead of global variable
Matthew Wild <mwild1@gmail.com>
parents: 8634
diff changeset
198 if not source_dir then
10627
88be11e9f9b9 util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents: 10536
diff changeset
199 os.execute(lua .. "./prosody -D");
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 else
10627
88be11e9f9b9 util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents: 10536
diff changeset
201 os.execute(lua .. source_dir.."/../../bin/prosody -D");
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 end
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
203
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
204 if notify_socket then
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
205 for i = 1, 5 do
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
206 notify_socket:settimeout(i);
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
207 if notify_socket:receivefrom() == "READY=1" then
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
208 return true;
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
209 end
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
210 end
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
211 return false, "not-ready";
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
212 end
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
213
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
217 local function stop()
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
218 local ok, ret = isrunning();
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
219 if not ok then
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
220 return ok, ret;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
221 end
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
222 if not ret then
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
223 return false, "not-running";
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
224 end
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
225
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
226 local ok, pid = getpid()
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
227 if not ok then return false, pid; end
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
228
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
229 signal.kill(pid, signal.SIGTERM);
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
230 return true;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
231 end
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
232
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
233 local function reload()
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
234 local ok, ret = isrunning();
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 return ok, ret;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 if not ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 return false, "not-running";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
241
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
242 local ok, pid = getpid()
4335
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
243 if not ok then return false, pid; end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
244
4335
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
245 signal.kill(pid, signal.SIGHUP);
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
246 return true;
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
247 end
5023
dcc8e789df36 mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents: 4503
diff changeset
248
11132
287d0d80aa57 util.prosodyctl: Construct luarocks command line with templates
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
249 local render_cli = interpolation.new("%b{}", function (s) return "'"..s:gsub("'","'\\''").."'" end)
287d0d80aa57 util.prosodyctl: Construct luarocks command line with templates
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
250
11134
3e3f22043552 util.prosodyctl: Move hardcoded luarocks server into prosodyctl
Kim Alvefur <zash@zash.se>
parents: 11133
diff changeset
251 local function call_luarocks(operation, mod, server)
11290
7919ecdc4a72 util.prosodyctl: Use installer path prepared by util.startup
Kim Alvefur <zash@zash.se>
parents: 11136
diff changeset
252 local dir = prosody.paths.installer;
11490
34d4e4a01ef8 util.prosodyctl: Install plugins for current Lua version
Kim Alvefur <zash@zash.se>
parents: 11299
diff changeset
253 local ok, _, code = os.execute(render_cli("luarocks --lua-version={luav} {op} --tree={dir} {server&--server={server}} {mod?}", {
34d4e4a01ef8 util.prosodyctl: Install plugins for current Lua version
Kim Alvefur <zash@zash.se>
parents: 11299
diff changeset
254 dir = dir; op = operation; mod = mod; server = server; luav = _VERSION:match("5%.%d");
11136
d0d3e25b7300 util.prosodyctl: Simplify luarocks invocation
Kim Alvefur <zash@zash.se>
parents: 11134
diff changeset
255 }));
12785
123d74bf60e3 util.prosodyctl: Remove Lua 5.1 os.execute() return value compat
Kim Alvefur <zash@zash.se>
parents: 11490
diff changeset
256 return ok and code;
10181
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
257 end
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
258
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
259 return {
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
260 show_message = show_message;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
261 show_warning = show_message;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
262 show_usage = show_usage;
10152
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
263 show_module_configuration_help = show_module_configuration_help;
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
264 adduser = adduser;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
265 user_exists = user_exists;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
266 passwd = passwd;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
267 deluser = deluser;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
268 getpid = getpid;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
269 isrunning = isrunning;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
270 start = start;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
271 stop = stop;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
272 reload = reload;
10181
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
273 call_luarocks = call_luarocks;
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
274 error_messages = error_messages;
6777
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6771
diff changeset
275 };