Software /
code /
prosody
Annotate
util/prosodyctl.lua @ 13491:cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Previously, prosodyctl only waits for the pidfile to appear, which does
not necessarily mean that Prosody is fully ready to receive traffic.
By waiting until Prosody says it's ready via the systemd notify socket
we know for sure that Prosody is really ready.
Notably this should ensure that when running `make integration-test`
Prosody is really ready when Scansion starts running tests.
Not sure if this timeout handling is optimal.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 19 May 2024 13:06:55 +0200 |
parent | 12975:d10957394a3c |
child | 13647:2b3d49936518 |
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"; |
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 |
8883
3f975bbfec3b
util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8668
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
140 |
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
|
141 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
|
142 if not file then |
1515
9991329e6b67
util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents:
1130
diff
changeset
|
143 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
|
144 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
145 |
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 |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
148 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
|
149 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
|
150 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
151 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 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
|
153 file:close(); |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
154 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 if not pid then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 return false, "invalid-pid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
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 return true, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 |
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
|
162 local function isrunning() |
10536
a469d2bcea96
util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
10367
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 -- 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
|
167 -- (it probably doesn't exist) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 return true, false; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 return ok, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 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
|
173 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
9781
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
175 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
|
176 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
|
177 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 return ok, ret; |
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 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 return false, "already-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 end |
13491
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 else |
10627
88be11e9f9b9
util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents:
10536
diff
changeset
|
196 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
|
197 end |
13491
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
198 |
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 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
|
203 return true; |
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
204 end |
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
205 end |
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
206 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
|
207 end |
cf367ab36fcc
util.prosodyctl: Use notify socket to wait for Prosody to be ready
Kim Alvefur <zash@zash.se>
parents:
12975
diff
changeset
|
208 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 |
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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 |
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 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
|
222 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
|
223 |
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 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
|
225 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
|
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 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
|
229 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 if not ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 return false, "not-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
236 |
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
|
237 local ok, pid = getpid() |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
238 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
|
239 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
240 signal.kill(pid, signal.SIGHUP); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
241 return true; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
242 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
|
243 |
11132
287d0d80aa57
util.prosodyctl: Construct luarocks command line with templates
Kim Alvefur <zash@zash.se>
parents:
10871
diff
changeset
|
244 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
|
245 |
11134
3e3f22043552
util.prosodyctl: Move hardcoded luarocks server into prosodyctl
Kim Alvefur <zash@zash.se>
parents:
11133
diff
changeset
|
246 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
|
247 local dir = prosody.paths.installer; |
11490
34d4e4a01ef8
util.prosodyctl: Install plugins for current Lua version
Kim Alvefur <zash@zash.se>
parents:
11299
diff
changeset
|
248 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
|
249 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
|
250 })); |
12785
123d74bf60e3
util.prosodyctl: Remove Lua 5.1 os.execute() return value compat
Kim Alvefur <zash@zash.se>
parents:
11490
diff
changeset
|
251 return ok and code; |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
252 end |
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
253 |
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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 reload = reload; |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
268 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
|
269 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
|
270 }; |