Software /
code /
prosody
Annotate
util/prosodyctl.lua @ 9781:161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
By default the shebang is used. Being able to override it is useful in
cases where the shebang does not match the configured runtime.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 10 Jan 2019 14:57:26 +0100 |
parent | 8883:3f975bbfec3b |
child | 10132:b59535964e81 |
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local config = require "core.configmanager"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local encodings = require "util.encodings"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local stringprep = encodings.stringprep; |
3771
428882c438bf
util.prosodyctl: Initialize storagemanager on hosts we modify
Matthew Wild <mwild1@gmail.com>
parents:
3711
diff
changeset
|
13 local storagemanager = require "core.storagemanager"; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local usermanager = require "core.usermanager"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local signal = require "util.signal"; |
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
|
16 local set = require "util.set"; |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
17 local lfs = require "lfs"; |
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
|
18 local pcall = pcall; |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
19 local type = type; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 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
|
22 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
27 local _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
|
28 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
|
29 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
30 -- UI helpers |
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
|
31 local function show_message(msg, ...) |
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
|
32 print(msg:format(...)); |
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
|
33 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
|
34 |
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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 |
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
|
42 local function getchar(n) |
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
|
43 local stty_ret = os.execute("stty raw -echo 2>/dev/null"); |
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
|
44 local ok, char; |
7457
5e18416881bb
util.prosodyctl: Handle os.execute in Lua 5.2 returning true when command terminates successfully
Kim Alvefur <zash@zash.se>
parents:
7262
diff
changeset
|
45 if stty_ret == true or stty_ret == 0 then |
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
|
46 ok, char = pcall(io.read, n or 1); |
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
|
47 os.execute("stty sane"); |
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 else |
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 ok, char = pcall(io.read, "*l"); |
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 if ok 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
|
51 char = char:sub(1, n or 1); |
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 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
|
53 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
|
54 if ok 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 return char; |
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 |
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
|
59 local function getline() |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
60 local ok, line = pcall(io.read, "*l"); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
61 if ok then |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
62 return line; |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
63 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
64 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
65 |
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
|
66 local function getpass() |
8634
f6f62c92b642
util.prosodyctl: Fix getpass() for new return values of os.execute() in Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents:
8123
diff
changeset
|
67 local stty_ret, _, status_code = os.execute("stty -echo 2>/dev/null"); |
f6f62c92b642
util.prosodyctl: Fix getpass() for new return values of os.execute() in Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents:
8123
diff
changeset
|
68 if status_code then -- COMPAT w/ Lua 5.1 |
f6f62c92b642
util.prosodyctl: Fix getpass() for new return values of os.execute() in Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents:
8123
diff
changeset
|
69 stty_ret = status_code; |
f6f62c92b642
util.prosodyctl: Fix getpass() for new return values of os.execute() in Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents:
8123
diff
changeset
|
70 end |
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
|
71 if stty_ret ~= 0 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
|
72 io.write("\027[08m"); -- ANSI 'hidden' text attribute |
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
|
73 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
|
74 local ok, pass = pcall(io.read, "*l"); |
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
|
75 if stty_ret == 0 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
|
76 os.execute("stty sane"); |
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
|
77 else |
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
|
78 io.write("\027[00m"); |
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
|
79 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
|
80 io.write("\n"); |
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
|
81 if ok 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
|
82 return pass; |
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
|
83 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
|
84 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
|
85 |
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
|
86 local function show_yesno(prompt) |
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
|
87 io.write(prompt, " "); |
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
|
88 local choice = getchar():lower(); |
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
|
89 io.write("\n"); |
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
|
90 if not choice:match("%a") 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
|
91 choice = prompt:match("%[.-(%U).-%]$"); |
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
|
92 if not choice then return nil; 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
|
93 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
|
94 return (choice == "y"); |
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
|
95 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
|
96 |
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
|
97 local function read_password() |
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
|
98 local password; |
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
|
99 while true do |
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
|
100 io.write("Enter new password: "); |
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
|
101 password = getpass(); |
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
|
102 if not password 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
|
103 show_message("No password - cancelled"); |
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
|
104 return; |
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
|
105 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
|
106 io.write("Retype new password: "); |
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
|
107 if getpass() ~= password 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
|
108 if not show_yesno [=[Passwords did not match, try again? [Y/n]]=] 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
|
109 return; |
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
|
110 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
|
111 else |
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
|
112 break; |
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
|
113 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
|
114 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
|
115 return password; |
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
|
116 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
|
117 |
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
|
118 local function show_prompt(prompt) |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
119 io.write(prompt, " "); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
120 local line = getline(); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
121 line = line and line:gsub("\n$",""); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
122 return (line and #line > 0) and line or nil; |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
123 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
124 |
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
|
125 -- 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
|
126 local function adduser(params) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 if not user then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 return false, "invalid-username"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 elseif not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 return false, "invalid-hostname"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 |
4501
eacc93e23f21
util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents:
4499
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 |
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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
144 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3771
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 |
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
|
152 local function user_exists(params) |
7262
751a4832adb4
util.prosodyctl: Remove unused variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
7259
diff
changeset
|
153 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
|
154 |
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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
160 |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
161 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
|
162 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
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
|
164 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
|
165 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
|
166 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
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 return adduser(params); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 |
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
|
172 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
|
173 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
|
174 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 end |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
176 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
|
177 |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
178 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
|
179 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 |
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
|
181 local function getpid() |
5379
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5102
diff
changeset
|
182 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
|
183 if not pidfile then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 return false, "no-pidfile"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 end |
6356
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
186 |
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
187 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
|
188 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
|
189 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
190 |
8123
bd591c5fc1bf
util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents:
7457
diff
changeset
|
191 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
|
192 |
8883
3f975bbfec3b
util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8668
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
197 |
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
|
198 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
|
199 if not file then |
1515
9991329e6b67
util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents:
1130
diff
changeset
|
200 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
|
201 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
202 |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
203 local locked, err = lfs.lock(file, "w"); |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
208 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 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
|
210 file:close(); |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
211 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 if not pid then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 return false, "invalid-pid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
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, pid; |
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 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
|
220 local ok, pid, err = getpid(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 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
|
222 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
|
223 -- 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
|
224 -- (it probably doesn't exist) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 return true, false; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 return ok, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 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
|
230 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 |
9781
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
232 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
|
233 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
|
234 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 return false, "already-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 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
|
241 if not source_dir then |
9781
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
242 os.execute(lua .. "./prosody"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 else |
9781
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
244 os.execute(lua .. source_dir.."/../../bin/prosody"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 |
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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 |
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
|
258 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
|
259 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
|
260 |
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 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
|
262 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
|
263 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
|
264 |
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 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
|
266 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 if not ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 return false, "not-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
273 |
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
|
274 local ok, pid = getpid() |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
275 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
|
276 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
277 signal.kill(pid, signal.SIGHUP); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
278 return true; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
279 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
|
280 |
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
|
281 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
|
282 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
|
283 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
|
284 show_usage = show_usage; |
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
|
285 getchar = getchar; |
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
|
286 getline = getline; |
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
|
287 getpass = getpass; |
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
|
288 show_yesno = show_yesno; |
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
|
289 read_password = read_password; |
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
|
290 show_prompt = show_prompt; |
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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 reload = 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
|
300 }; |