Software /
code /
prosody
Annotate
util/prosodyctl.lua @ 7880:1d998891c967
migrator: Remove wrapper around envloadfile since envloadfile does the right thing in a compatible way
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Feb 2017 20:11:25 +0100 |
parent | 7457:5e18416881bb |
child | 8123:bd591c5fc1bf |
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 |
442c87de8e2d
util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents:
1123
diff
changeset
|
27 local CFG_SOURCEDIR = _G.CFG_SOURCEDIR; |
442c87de8e2d
util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents:
1123
diff
changeset
|
28 |
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
|
29 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
|
30 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
|
31 |
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 -- 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
|
33 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
|
34 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
|
35 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
|
36 |
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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 |
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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
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 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
|
57 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
|
58 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
|
59 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
|
60 |
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
|
61 local function getline() |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
62 local ok, line = pcall(io.read, "*l"); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
63 if ok then |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
64 return line; |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
65 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
66 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
67 |
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
|
68 local function getpass() |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
69 local stty_ret = os.execute("stty -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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
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 |
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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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 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
|
94 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
|
95 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
96 local function 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
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 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
|
115 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
|
116 |
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
|
117 local function show_prompt(prompt) |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
118 io.write(prompt, " "); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
119 local line = getline(); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
120 line = line and line:gsub("\n$",""); |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
121 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
|
122 end |
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
123 |
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
|
124 -- 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
|
125 local function adduser(params) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 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
|
127 if not user then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 return false, "invalid-username"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 elseif not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 return false, "invalid-hostname"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 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
|
132 |
4501
eacc93e23f21
util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents:
4499
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
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 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
|
139 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
|
140 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
|
141 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
|
142 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
143 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3771
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
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
|
151 local function user_exists(params) |
7262
751a4832adb4
util.prosodyctl: Remove unused variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
7259
diff
changeset
|
152 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
|
153 |
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 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
|
155 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
|
156 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
|
157 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
|
158 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
159 |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
160 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
|
161 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 |
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
|
163 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
|
164 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
|
165 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
167 |
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
|
168 return adduser(params); |
1087
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 |
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
|
171 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
|
172 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
|
173 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 end |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
175 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
|
176 |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
177 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
|
178 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 |
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
|
180 local function getpid() |
5379
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5102
diff
changeset
|
181 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
|
182 if not pidfile then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 return false, "no-pidfile"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 end |
6356
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
185 |
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
186 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
|
187 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
|
188 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
189 |
6062
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
190 local modules_enabled = set.new(config.get("*", "modules_disabled")); |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
191 if prosody.platform ~= "posix" or modules_enabled: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
|
192 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
|
193 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
194 |
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
|
195 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
|
196 if not file then |
1515
9991329e6b67
util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents:
1130
diff
changeset
|
197 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
|
198 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
199 |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
205 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 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
|
207 file:close(); |
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 if not pid then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 return false, "invalid-pid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
212 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 return true, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 |
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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 -- 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
|
221 -- (it probably doesn't exist) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 return true, false; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 return ok, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 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
|
227 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 |
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
|
229 local function 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
|
230 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 return false, "already-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 if not CFG_SOURCEDIR then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 os.execute("./prosody"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 else |
2386
bfb093a0df1e
util.prosodyctl: Saner determination of Prosody executable path
Brian Cully <bjc@junctionnetworks.com>
parents:
1522
diff
changeset
|
240 os.execute(CFG_SOURCEDIR.."/../../bin/prosody"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 |
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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 |
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 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
|
255 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
|
256 |
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 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
|
258 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
|
259 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 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
|
262 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 if not ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 return false, "not-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
269 |
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 local ok, pid = getpid() |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
271 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
|
272 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
273 signal.kill(pid, signal.SIGHUP); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
274 return true; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
275 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
|
276 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 }; |