Annotate

util/prosodyctl.lua @ 13745:994ea8d54b72 13.0

core.configmanager: Pass name and line number in context Delays the string interpolation until the warning is logged, which may slightly lower memory usage. Allows retrieving the filename and line number easily.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Feb 2025 00:04:51 +0100
parent 13647:2b3d49936518
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";
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
17 local set = require "prosody.util.set";
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
18 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
19 local lfs = require "lfs";
4485
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
20 local type = type;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
22 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
23 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
24
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 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
26
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 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
28 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
29 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
30
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
31 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
32 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
33
10871
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
34 local error_messages = setmetatable({
e5dee71d0ebb prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents: 10722
diff changeset
35 ["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
36 ["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
37 ["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
38 ["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
39 ["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
40 ["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
41 ["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
42 ["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
43 ["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
44 ["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
45 ["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
46 ["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
47 }, { __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
48
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
49 -- UI helpers
12975
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12785
diff changeset
50 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
51
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
52 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
53 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
54 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
55 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
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 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
58
10152
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
59 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
60 print("Done.")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
61 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
62 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
63 print("")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
64 print("More info about: ")
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
65 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
66 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
67 end
7e9c30eab11e util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents: 10148
diff changeset
68
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
69 -- 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
70 local function adduser(params)
10367
649acbfbf7fe util.prosodyctl: Enforce strict JID validation on user creation
Kim Alvefur <zash@zash.se>
parents: 10209
diff changeset
71 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
72 if not user then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 return false, "invalid-username";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 elseif not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 return false, "invalid-hostname";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 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
77
4501
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
78 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
79 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
80 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
81 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
82
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
83 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
84 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
85 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
86 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
87 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
88
3777
5ecbcef42ffb mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3771
diff changeset
89 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
90 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
91 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
92 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95
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
96 local function user_exists(params)
7262
751a4832adb4 util.prosodyctl: Remove unused variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 7259
diff changeset
97 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
98
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
99 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
100 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
101 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
102 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
103 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
104
3711
2a1cfaf3ee61 util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents: 3627
diff changeset
105 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
106 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107
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
108 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
109 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
110 return false, "no-such-user";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
112
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
113 return adduser(params);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115
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
116 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
117 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
118 return false, "no-such-user";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 end
5102
ae8a993b598d util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents: 5023
diff changeset
120 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
121
5102
ae8a993b598d util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents: 5023
diff changeset
122 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
123 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124
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
125 local function getpid()
5379
27de7cc94111 util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents: 5102
diff changeset
126 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
127 if not pidfile then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 return false, "no-pidfile";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 end
6356
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
130
fb1535328ac7 prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents: 5524
diff changeset
131 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
132 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
133 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
134
8123
bd591c5fc1bf util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents: 7457
diff changeset
135 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
136
8883
3f975bbfec3b util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8668
diff changeset
137 local modules_disabled = set.new(config.get("*", "modules_disabled"));
3f975bbfec3b util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents: 8668
diff changeset
138 if prosody.platform ~= "posix" or modules_disabled:contains("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
139 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
140 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
141
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
142 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
143 if not file then
1515
9991329e6b67 util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents: 1130
diff changeset
144 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
145 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
146
13647
2b3d49936518 util.prosodyctl: Add comments to explain logic and expected behaviour (#1688)
Matthew Wild <mwild1@gmail.com>
parents: 13491
diff changeset
147 -- Check for a lock on the file
10536
a469d2bcea96 util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10367
diff changeset
148 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
149 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
150 -- 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
151 -- 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
152 -- 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
153 -- 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
154 -- 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
155 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
156 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
157 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
158
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 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
160 file:close();
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
161
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 if not pid then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 return false, "invalid-pid";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
165
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 return true, pid;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168
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
169 local function isrunning()
10536
a469d2bcea96 util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents: 10367
diff changeset
170 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
171 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
172 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
173 -- 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
174 -- (it probably doesn't exist)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 return true, false;
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 ok, pid;
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 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
180 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181
9781
161411a41377 util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents: 8883
diff changeset
182 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
183 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
184 local ok, ret = isrunning();
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 return ok, ret;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 if ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 return false, "already-running";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 end
13491
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_socket;
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202 else
10627
88be11e9f9b9 util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents: 10536
diff changeset
203 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
204 end
13491
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
205
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
206 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
207 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
208 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
209 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
210 return true;
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
211 end
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 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
214 end
cf367ab36fcc util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents: 12975
diff changeset
215
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218
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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227
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 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
229 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
230
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 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
232 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
233 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
234
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
235 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
236 local ok, ret = isrunning();
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 return ok, ret;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 if not ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 return false, "not-running";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 end
6771
60957dd5b41b util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 6367
diff changeset
243
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
244 local ok, pid = getpid()
4335
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
245 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
246
4335
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
247 signal.kill(pid, signal.SIGHUP);
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
248 return true;
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
249 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
250
11132
287d0d80aa57 util.prosodyctl: Construct luarocks command line with templates
Kim Alvefur <zash@zash.se>
parents: 10871
diff changeset
251 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
252
11134
3e3f22043552 util.prosodyctl: Move hardcoded luarocks server into prosodyctl
Kim Alvefur <zash@zash.se>
parents: 11133
diff changeset
253 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
254 local dir = prosody.paths.installer;
11490
34d4e4a01ef8 util.prosodyctl: Install plugins for current Lua version
Kim Alvefur <zash@zash.se>
parents: 11299
diff changeset
255 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
256 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
257 }));
12785
123d74bf60e3 util.prosodyctl: Remove Lua 5.1 os.execute() return value compat
Kim Alvefur <zash@zash.se>
parents: 11490
diff changeset
258 return ok and code;
10181
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
259 end
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
260
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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270 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
271 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
272 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
273 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
274 reload = reload;
10181
c7d5cd766533 util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents: 10180
diff changeset
275 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
276 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
277 };