Annotate

util/prosodyctl.lua @ 4953:24c2150cc8b0

Merge 0.9->trunk
author Matthew Wild <mwild1@gmail.com>
date Mon, 09 Jul 2012 02:36:09 +0100
parent 4503:6dc327809dfd
child 5023:dcc8e789df36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1515
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2796
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2796
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
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;
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;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 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
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
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 module "prosodyctl"
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
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 -- 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
35 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
36 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
37 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
38
caa78589598f prosodyctl, util.prosodyctl: 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 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
40 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
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
caa78589598f prosodyctl, util.prosodyctl: 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 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
44 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
45 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
46 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
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 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
49
caa78589598f prosodyctl, util.prosodyctl: 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 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
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 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
62 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
63 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
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 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
66
4485
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
67 function getline()
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
68 local ok, line = pcall(io.read, "*l");
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
69 if ok then
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
70 return line;
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
71 end
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
72 end
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
73
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
74 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
75 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
76 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
77 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
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 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
80 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
81 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
82 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
83 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
84 end
caa78589598f prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
85 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
86 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
87 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
88 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
89 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
caa78589598f prosodyctl, util.prosodyctl: 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 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101
caa78589598f prosodyctl, util.prosodyctl: 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 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
103 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
104 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
105 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
106 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
107 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
108 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
109 return;
caa78589598f prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
110 end
caa78589598f prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents: 3777
diff changeset
111 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
112 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
113 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
114 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
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 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
117 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
118 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
119 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
120 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
121 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
122
4485
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
123 function show_prompt(prompt)
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
124 io.write(prompt, " ");
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
125 local line = getline();
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
126 line = line and line:gsub("\n$","");
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
127 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
128 end
abfd27b59fa8 util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents: 4335
diff changeset
129
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
130 -- Server control
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 function adduser(params)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 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
133 if not user then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 return false, "invalid-username";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 elseif not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 return false, "invalid-hostname";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 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
138
4501
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
139 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
140 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
141 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
142 end
4501
eacc93e23f21 util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents: 4499
diff changeset
143 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
144 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
145 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
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);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
3777
5ecbcef42ffb mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3771
diff changeset
149 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
150 if not ok then
3777
5ecbcef42ffb mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents: 3771
diff changeset
151 return false, errmsg;
1123
da7ff11a03ee util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
152 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 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
157 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
158 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
159 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
160 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
161 end
3771
428882c438bf util.prosodyctl: Initialize storagemanager on hosts we modify
Matthew Wild <mwild1@gmail.com>
parents: 3711
diff changeset
162 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
163
3711
2a1cfaf3ee61 util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents: 3627
diff changeset
164 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
165 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 function passwd(params)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 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
169 return false, "no-such-user";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 return _M.adduser(params);
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 function deluser(params)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 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
177 return false, "no-such-user";
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 params.password = nil;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 return _M.adduser(params);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 function getpid()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 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
186 if not pidfile then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 return false, "no-pidfile";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189
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
190 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
191 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
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
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
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
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
5f14cd94a563 util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents: 1522
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();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 function isrunning()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 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
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 function start()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 local ok, ret = _M.isrunning();
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 function stop()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 local ok, ret = _M.isrunning();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 return ok, ret;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 if not ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 return false, "not-running";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254 local ok, pid = _M.getpid()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 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
256
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 signal.kill(pid, signal.SIGTERM);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 return true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 end
4335
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
260
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
261 function reload()
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
262 local ok, ret = _M.isrunning();
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
263 if not ok then
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
264 return ok, ret;
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
265 end
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
266 if not ret then
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
267 return false, "not-running";
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
268 end
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
269
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
270 local ok, pid = _M.getpid()
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
271 if not ok then return false, pid; end
3a2a01432b5c Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents: 4142
diff changeset
272
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