Software /
code /
prosody
Annotate
util/prosodyctl.lua @ 4499:55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 08 Feb 2012 15:33:36 +0100 |
parent | 4335:3a2a01432b5c |
child | 4500:bfa387f268e2 |
child | 4501:eacc93e23f21 |
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 |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
4 -- |
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; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 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
|
21 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 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
|
23 local print = print; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local tostring, tonumber = tostring, tonumber; |
1130
442c87de8e2d
util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents:
1123
diff
changeset
|
25 |
442c87de8e2d
util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents:
1123
diff
changeset
|
26 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
|
27 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
28 local _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
|
29 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
|
30 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 module "prosodyctl" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
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
|
33 -- UI helpers |
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 function show_message(msg, ...) |
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 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
|
36 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
|
37 |
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 function show_warning(msg, ...) |
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 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
|
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 |
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 function show_usage(usage, 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 |
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 function getchar(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
|
50 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
|
51 local ok, 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
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 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 |
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
|
66 function 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 |
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 function show_yesno(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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
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 |
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 function read_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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
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 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
|
112 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
|
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 |
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 -- Server control |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 function adduser(params) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 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
|
118 if not user then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 return false, "invalid-username"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 elseif not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 return false, "invalid-hostname"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 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
|
123 |
4499
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
124 local host = prosody.hosts[host]; |
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
125 if not host then |
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
126 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
|
127 end |
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
128 local provider = 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
|
129 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
|
130 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
|
131 end |
3771
428882c438bf
util.prosodyctl: Initialize storagemanager on hosts we modify
Matthew Wild <mwild1@gmail.com>
parents:
3711
diff
changeset
|
132 storagemanager.initialize_host(host); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3771
diff
changeset
|
134 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
|
135 if not ok then |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3771
diff
changeset
|
136 return false, errmsg; |
1123
da7ff11a03ee
util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
137 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 function user_exists(params) |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
142 local user, host, password = nodeprep(params.user), nameprep(params.host), params.password; |
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 end |
3771
428882c438bf
util.prosodyctl: Initialize storagemanager on hosts we modify
Matthew Wild <mwild1@gmail.com>
parents:
3711
diff
changeset
|
147 storagemanager.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
|
148 |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
149 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
|
150 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 function passwd(params) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 if not _M.user_exists(params) then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 return _M.adduser(params); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 function deluser(params) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 if not _M.user_exists(params) then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 params.password = nil; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 return _M.adduser(params); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 function getpid() |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 local pidfile = config.get("*", "core", "pidfile"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 if not pidfile then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 return false, "no-pidfile"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
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
|
175 local modules_enabled = set.new(config.get("*", "core", "modules_enabled")); |
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
|
176 if not modules_enabled:contains("posix") then |
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
|
177 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
|
178 end |
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
|
179 |
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
|
180 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
|
181 if not file then |
1515
9991329e6b67
util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents:
1130
diff
changeset
|
182 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
|
183 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 end |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
190 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 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
|
192 file:close(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 if not pid then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 return false, "invalid-pid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 return true, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 function isrunning() |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 local ok, pid, err = _M.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 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
|
204 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
|
205 -- 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
|
206 -- (it probably doesn't exist) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 return true, false; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 return ok, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 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
|
212 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 function start() |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 local ok, ret = _M.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 return false, "already-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 if not CFG_SOURCEDIR then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 os.execute("./prosody"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 else |
2386
bfb093a0df1e
util.prosodyctl: Saner determination of Prosody executable path
Brian Cully <bjc@junctionnetworks.com>
parents:
1522
diff
changeset
|
225 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
|
226 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 return true; |
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 function stop() |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 local ok, ret = _M.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 if not ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 return false, "not-running"; |
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 local ok, pid = _M.getpid() |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 if not ok then return false, pid; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 signal.kill(pid, signal.SIGTERM); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 end |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
245 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
246 function reload() |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
247 local ok, ret = _M.isrunning(); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
248 if not ok then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
249 return ok, ret; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
250 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
251 if not ret then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
252 return false, "not-running"; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
253 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
254 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
255 local ok, pid = _M.getpid() |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
256 if not ok then return false, pid; end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
257 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
258 signal.kill(pid, signal.SIGHUP); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
259 return true; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
260 end |