prosodyctl

Wed, 05 May 2010 20:14:03 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 05 May 2010 20:14:03 +0100
changeset 3013
518e3f6f9946
parent 2706
c2dde8bda3fe
child 3014
169d096988e1
permissions
-rwxr-xr-x

prosodyctl: Relocate global prosody object creation (see fff153f7f4de)

1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env lua
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1501
diff changeset
2 -- Prosody IM
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2009 Matthew Wild
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 -- Copyright (C) 2008-2009 Waqas Hussain
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 --
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 --
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 -- prosodyctl - command-line controller for Prosody XMPP server
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 -- Will be modified by configure script if run --
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 CFG_SOURCEDIR=nil;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 CFG_PLUGINDIR=nil;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 CFG_DATADIR=os.getenv("PROSODY_DATADIR");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 if CFG_SOURCEDIR then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 if CFG_DATADIR then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 if os.getenv("HOME") then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME"));
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31
3013
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
32 -- Global 'prosody' object
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
33 prosody = {
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
34 hosts = {},
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
35 events = require "util.events".new(),
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
36 platform = "posix"
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
37 };
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
38 local prosody = prosody;
518e3f6f9946 prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents: 2706
diff changeset
39
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 config = require "core.configmanager"
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 do
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 -- TODO: Check for other formats when we add support for them
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 -- Use lfs? Make a new conf/ dir?
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 local ok, level, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 print("\n");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 print("**************************");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 if level == "parser" then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 print("A problem occured while reading the config file "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local err_line, err_message = tostring(err):match("%[string .-%]:(%d*): (.*)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err)));
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 print("");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 elseif level == "file" then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 print("Prosody was unable to find the configuration file.");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 print("More help on configuring Prosody can be found at http://prosody.im/doc/configure");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 print("Good luck!");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 print("**************************");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 print("");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 os.exit(1);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67
2587
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
68 require "core.loggingmanager"
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
69
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
70 if not require "util.dependencies".check_dependencies() then
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
71 os.exit(1);
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
72 end
c37f971f0fe6 prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents: 2566
diff changeset
73
1120
23fa69b911f7 prosodyctl: Use correct path for the data directory
Matthew Wild <mwild1@gmail.com>
parents: 1115
diff changeset
74 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data";
23fa69b911f7 prosodyctl: Use correct path for the data directory
Matthew Wild <mwild1@gmail.com>
parents: 1115
diff changeset
75 require "util.datamanager".set_data_path(data_path);
23fa69b911f7 prosodyctl: Use correct path for the data directory
Matthew Wild <mwild1@gmail.com>
parents: 1115
diff changeset
76
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
77 -- Switch away from root and into the prosody user --
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
78 local switched_user, current_uid;
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
79
2455
0b3184f3c9e4 util.pposix, mod_posix, prosodyctl: Bump pposix version to 0.3.3 for mkdir
Matthew Wild <mwild1@gmail.com>
parents: 2442
diff changeset
80 local want_pposix_version = "0.3.3";
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
81 local ok, pposix = pcall(require, "util.pposix");
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
82
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
83 if ok and pposix then
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
84 if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
85 current_uid = pposix.getuid();
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
86 if current_uid == 0 then
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
87 -- We haz root!
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
88 local desired_user = config.get("*", "core", "prosody_user") or "prosody";
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
89 local desired_group = config.get("*", "core", "prosody_group") or desired_user;
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
90 local ok, err = pposix.setgid(desired_group);
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
91 if ok then
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
92 ok, err = pposix.setuid(desired_user);
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
93 if ok then
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
94 -- Yay!
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
95 switched_user = true;
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
96 end
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
97 end
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
98 if not switched_user then
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
99 -- Boo!
1580
5be6dc582df3 prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
100 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err));
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
101 end
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
102 end
2439
511ba389147a prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents: 2410
diff changeset
103
511ba389147a prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents: 2410
diff changeset
104 -- Set our umask to protect data files
511ba389147a prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents: 2410
diff changeset
105 pposix.umask(config.get("*", "core", "umask") or "027");
1114
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
106 else
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
107 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
108 print("For more help send the below error to us through http://prosody.im/discuss");
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
109 print(tostring(pposix))
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
110 end
c463e30da312 prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents: 1102
diff changeset
111
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 local error_messages = setmetatable({
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 ["invalid-username"] = "The given username is invalid in a Jabber ID";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 ["invalid-hostname"] = "The given hostname is invalid";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 ["no-password"] = "No password was supplied";
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 ["no-such-user"] = "The given user does not exist on the server";
1124
055cfdc96afa prosodyctl: Add message for unable-to-save-data error
Matthew Wild <mwild1@gmail.com>
parents: 1122
diff changeset
117 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?";
2065
c384ae8ee17a prosodyctl: Put 'pidfile' in quotes to make more clear that it is the literal name of the option
Matthew Wild <mwild1@gmail.com>
parents: 2020
diff changeset
118 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help";
1390
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
119 ["no-such-method"] = "This module has no commands";
1460
5882ed6219ff prosodyctl: Add message for not-running error
Matthew Wild <mwild1@gmail.com>
parents: 1459
diff changeset
120 ["not-running"] = "Prosody is not running";
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 }, { __index = function (t,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end });
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122
2020
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
123 local events = require "util.events".new();
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
124
2442
94c676b585c0 prosodyctl: Move definition of prosody singleton to prior to loading datamanager, and add platform
Matthew Wild <mwild1@gmail.com>
parents: 2439
diff changeset
125 hosts = prosody.hosts;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
2020
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
127 for hostname, config in pairs(config.getconfig()) do
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
128 hosts[hostname] = { events = events };
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
129 end
24f54340a670 prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents: 1580
diff changeset
130
1390
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
131 require "core.modulemanager"
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 require "util.prosodyctl"
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
134 require "socket"
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 -----------------------
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 function show_message(msg, ...)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 print(msg:format(...));
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 show_warning(msg, ...)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 print(msg:format(...));
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 function show_usage(usage, desc)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 print("Usage: "..arg[0].." "..usage);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 if desc then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 print(" "..desc);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 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 local function getchar(n)
2410
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
153 local stty_ret = os.execute("stty raw -echo 2>/dev/null");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
154 local ok, char;
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
155 if stty_ret == 0 then
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
156 ok, char = pcall(io.read, n or 1);
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
157 os.execute("stty sane");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
158 else
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
159 ok, char = pcall(io.read, "*l");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
160 if ok then
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
161 char = char:sub(1, n or 1);
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
162 end
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
163 end
1500
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
164 if ok then
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
165 return char;
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
166 end
1087
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 local function getpass()
2410
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
170 local stty_ret = os.execute("stty -echo 2>/dev/null");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
171 if stty_ret ~= 0 then
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
172 io.write("\027[08m"); -- ANSI 'hidden' text attribute
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
173 end
1500
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
174 local ok, pass = pcall(io.read, "*l");
2410
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
175 if stty_ret == 0 then
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
176 os.execute("stty sane");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
177 else
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
178 io.write("\027[00m");
ce912b648741 prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences
Matthew Wild <mwild1@gmail.com>
parents: 2327
diff changeset
179 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 io.write("\n");
1500
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
181 if ok then
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
182 return pass;
56d05ba00169 prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
Matthew Wild <mwild1@gmail.com>
parents: 1499
diff changeset
183 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 function show_yesno(prompt)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 io.write(prompt, " ");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 local choice = getchar():lower();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 io.write("\n");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 if not choice:match("%a") then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 choice = prompt:match("%[.-(%U).-%]$");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 if not choice then return nil; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 return (choice == "y");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 local function read_password()
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 local password;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 while true do
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 io.write("Enter new password: ");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 password = getpass();
1501
330b8437ac35 prosodyctl: Quit when user pressed ^C in password prompts
Matthew Wild <mwild1@gmail.com>
parents: 1500
diff changeset
202 if not password then
330b8437ac35 prosodyctl: Quit when user pressed ^C in password prompts
Matthew Wild <mwild1@gmail.com>
parents: 1500
diff changeset
203 show_message("No password - cancelled");
330b8437ac35 prosodyctl: Quit when user pressed ^C in password prompts
Matthew Wild <mwild1@gmail.com>
parents: 1500
diff changeset
204 return;
330b8437ac35 prosodyctl: Quit when user pressed ^C in password prompts
Matthew Wild <mwild1@gmail.com>
parents: 1500
diff changeset
205 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 io.write("Retype new password: ");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 if getpass() ~= password then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 if not show_yesno [=[Passwords did not match, try again? [Y/n]]=] then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 return;
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 else
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 break;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 end
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 return password;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 end
1459
545208bc0e84 prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents: 1458
diff changeset
217
545208bc0e84 prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents: 1458
diff changeset
218 local prosodyctl_timeout = (config.get("*", "core", "prosodyctl_timeout") or 5) * 2;
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 -----------------------
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 local commands = {};
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221 local command = arg[1];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223 function commands.adduser(arg)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 if not arg[1] or arg[1] == "--help" then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 return 1;
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 local user, host = arg[1]:match("([^@]+)@(.+)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 if not user and host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 show_message [[Failed to understand JID, please supply the JID you want to create]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 show_usage [[adduser user@host]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 return 1;
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
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 if not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 if prosodyctl.user_exists{ user = user, host = host } then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 show_message [[That user already exists]];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 return 1;
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 if not hosts[host] then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 show_warning("The user will not be able to log in until this is changed.");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 local password = read_password();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 if not password then return 1; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 if ok then return 0; 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 show_message(error_messages[msg])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 function commands.passwd(arg)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 if not arg[1] or arg[1] == "--help" then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 local user, host = arg[1]:match("([^@]+)@(.+)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267 if not user and host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268 show_message [[Failed to understand JID, please supply the JID you want to set the password for]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269 show_usage [[passwd user@host]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 if not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 if not prosodyctl.user_exists { user = user, host = host } then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279 show_message [[That user does not exist, use prosodyctl adduser to create a new user]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 local password = read_password();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 if not password then return 1; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 if ok then return 0; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 show_message(error_messages[msg])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 function commands.deluser(arg)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 if not arg[1] or arg[1] == "--help" then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 show_usage([[deluser JID]], [[Permanently remove the specified user account from Prosody]]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
299 local user, host = arg[1]:match("([^@]+)@(.+)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
300 if not user and host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301 show_message [[Failed to understand JID, please supply the JID you want to set the password for]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 show_usage [[passwd user@host]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 if not host then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 if not prosodyctl.user_exists { user = user, host = host } then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 show_message [[That user does not exist on this server]]
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
316 local ok, msg = prosodyctl.passwd { user = user, host = host };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
318 if ok then return 0; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 show_message(error_messages[msg])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
324 function commands.start(arg)
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
325 if arg[1] == "--help" then
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
326 show_usage([[start]], [[Start Prosody]]);
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
327 return 1;
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
328 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 local ok, ret = prosodyctl.isrunning();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331 show_message(error_messages[ret]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 if ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 local ok, ret = prosodyctl.getpid();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 show_message("Couldn't get running Prosody's PID");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339 show_message(error_messages[ret]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 show_message("Prosody is already running with PID %s", ret or "(unknown)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 local ok, ret = prosodyctl.start();
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
347 if ok then
2511
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
348 if config.get("*", "core", "daemonize") ~= false then
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
349 local i=1;
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
350 while true do
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
351 local ok, running = prosodyctl.isrunning();
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
352 if ok and running then
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
353 break;
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
354 elseif i == 5 then
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
355 show_message("Still waiting...");
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
356 elseif i >= prosodyctl_timeout then
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
357 show_message("Prosody is still not running. Please give it some time or check your log files for errors.");
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
358 return 2;
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
359 end
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
360 socket.sleep(0.5);
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
361 i = i + 1;
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
362 end
2511
a81c710b1708 prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
363 show_message("Started");
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
364 end
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
365 return 0;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
366 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 show_message("Failed to start Prosody");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
369 show_message(error_messages[ret])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
371 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
372
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
373 function commands.status(arg)
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
374 if arg[1] == "--help" then
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
375 show_usage([[status]], [[Reports the running status of Prosody]]);
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
376 return 1;
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
377 end
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
378
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
379 local ok, ret = prosodyctl.isrunning();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
380 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
381 show_message(error_messages[ret]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
383 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
384
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
385 if ret then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
386 local ok, ret = prosodyctl.getpid();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
387 if not ok then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
388 show_message("Couldn't get running Prosody's PID");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
389 show_message(error_messages[ret]);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
390 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
391 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
392 show_message("Prosody is running with PID %s", ret or "(unknown)");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
393 return 0;
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
394 else
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
395 show_message("Prosody is not running");
1115
8a7bc1a5eae6 prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user
Matthew Wild <mwild1@gmail.com>
parents: 1114
diff changeset
396 if not switched_user and current_uid ~= 0 then
1122
07b2b5942957 prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents: 1120
diff changeset
397 print("\nNote:")
07b2b5942957 prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents: 1120
diff changeset
398 print(" You will also see this if prosodyctl is not running under");
07b2b5942957 prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents: 1120
diff changeset
399 print(" the same user account as Prosody. Try running as root (e.g. ");
07b2b5942957 prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents: 1120
diff changeset
400 print(" with 'sudo' in front) to gain access to Prosody's real status.");
1115
8a7bc1a5eae6 prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user
Matthew Wild <mwild1@gmail.com>
parents: 1114
diff changeset
401 end
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
402 return 2
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
403 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
404 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
405 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
406
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
407 function commands.stop(arg)
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
408 if arg[1] == "--help" then
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
409 show_usage([[stop]], [[Stop a running Prosody server]]);
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
410 return 1;
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
411 end
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
412
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
413 if not prosodyctl.isrunning() then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
414 show_message("Prosody is not running");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
415 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
416 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
417
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
418 local ok, ret = prosodyctl.stop();
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
419 if ok then
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
420 local i=1;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
421 while true do
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
422 local ok, running = prosodyctl.isrunning();
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
423 if ok and not running then
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
424 break;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
425 elseif i == 5 then
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
426 show_message("Still waiting...");
1459
545208bc0e84 prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents: 1458
diff changeset
427 elseif i >= prosodyctl_timeout then
1458
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
428 show_message("Prosody is still running. Please give it some time or check your log files for errors.");
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
429 return 2;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
430 end
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
431 socket.sleep(0.5);
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
432 i = i + 1;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
433 end
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
434 show_message("Stopped");
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
435 return 0;
fce75b4efda9 prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents: 1390
diff changeset
436 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
437
1089
a817cbaa0f46 prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents: 1087
diff changeset
438 show_message(error_messages[ret]);
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
439 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
440 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
441
2696
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
442 function commands.restart(arg)
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
443 if arg[1] == "--help" then
2705
8a5af6f14c07 prosodyctl: Fix 'restart' command to not report itself as the 'stop' command (thanks albert!)
Matthew Wild <mwild1@gmail.com>
parents: 2696
diff changeset
444 show_usage([[restart]], [[Restart a running Prosody server]]);
2696
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
445 return 1;
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
446 end
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
447
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
448 local ret = commands.stop(arg);
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
449 if ret == 0 then
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
450 ret = commands.start(arg);
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
451 end
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
452 return ret;
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
453 end
cb5acafbec62 prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents: 2587
diff changeset
454
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
455 -- ejabberdctl compatibility
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
456
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
457 function commands.register(arg)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
458 local user, host, password = unpack(arg);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
459 if (not (user and host)) or arg[1] == "--help" then
1102
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
460 if user ~= "--help" then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
461 if not user then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
462 show_message [[No username specified]]
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
463 elseif not host then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
464 show_message [[Please specify which host you want to register the user on]];
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
465 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
466 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
467 show_usage("register USER HOST [PASSWORD]", "Register a user on the server, with the given password");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
468 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
469 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
470 if not password then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
471 password = read_password();
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
472 if not password then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
473 show_message [[Unable to register user with no password]];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
474 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
475 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
476 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
477
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
478 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
479
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
480 if ok then return 0; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
481
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
482 show_message(error_messages[msg])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
483 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
484 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
485
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
486 function commands.unregister(arg)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
487 local user, host = unpack(arg);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
488 if (not (user and host)) or arg[1] == "--help" then
1102
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
489 if user ~= "--help" then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
490 if not user then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
491 show_message [[No username specified]]
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
492 elseif not host then
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
493 show_message [[Please specify which host you want to unregister the user from]];
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
494 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
495 end
1102
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
496 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server");
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
497 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
498 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
499
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
500 local ok, msg = prosodyctl.deluser { user = user, host = host };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
501
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
502 if ok then return 0; end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
503
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
504 show_message(error_messages[msg])
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
505 return 1;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
506 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
507
2327
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
508 local http_errors = {
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
509 [404] = "Plugin not found, did you type the address correctly?"
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
510 };
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
511
2292
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
512 function commands.addplugin(arg)
2706
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
513 if not arg[1] or arg[1] == "--help" then
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
514 show_usage("addplugin URL", "Download and install a plugin from a URL");
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
515 return 1;
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
516 end
2292
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
517 local url = arg[1];
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
518 if url:match("^http://") then
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
519 local http = require "socket.http";
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
520 show_message("Fetching...");
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
521 local code, err = http.request(url);
2327
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
522 if not code or not tostring(err):match("^[23]") then
e497718194a3 prosodyctl: Nicer errors when addplugin command fails
Matthew Wild <mwild1@gmail.com>
parents: 2292
diff changeset
523 show_message("Failed: "..(http_errors[err] or ("HTTP error "..err)));
2292
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
524 return 1;
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
525 end
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
526 if url:match("%.lua$") then
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
527 local ok, err = datamanager.store(url:match("/mod_([^/]+)$"), "*", "plugins", {code});
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
528 if not ok then
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
529 show_message("Failed to save to data store: "..err);
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
530 return 1;
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
531 end
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
532 end
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
533 show_message("Saved. Don't forget to load the module using the config file or admin console!");
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
534 else
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
535 show_message("Sorry, I don't understand how to fetch plugins from there.");
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
536 end
c5d3905c98a6 prosodyctl: Experimental 'addplugin' command
Matthew Wild <mwild1@gmail.com>
parents: 2065
diff changeset
537 end
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
538
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
539 ---------------------
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
540
1499
51e3e22b5316 prosodyctl: Fix traceback when issued with no parameters
Matthew Wild <mwild1@gmail.com>
parents: 1460
diff changeset
541 if command and command:match("^mod_") then -- Is a command in a module
1390
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
542 local module_name = command:match("^mod_(.+)");
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
543 local ret, err = modulemanager.load("*", module_name);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
544 if not ret then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
545 show_message("Failed to load module '"..module_name.."': "..err);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
546 os.exit(1);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
547 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
548
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
549 table.remove(arg, 1);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
550
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
551 local module = modulemanager.get_module("*", module_name);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
552 if not module then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
553 show_message("Failed to load module '"..module_name.."': Unknown error");
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
554 os.exit(1);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
555 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
556
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
557 if not modulemanager.module_has_method(module, "command") then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
558 show_message("Fail: mod_"..module_name.." does not support any commands");
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
559 os.exit(1);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
560 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
561
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
562 local ok, ret = modulemanager.call_module_method(module, "command", arg);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
563 if ok then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
564 if type(ret) == "number" then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
565 os.exit(ret);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
566 elseif type(ret) == "string" then
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
567 show_message(ret);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
568 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
569 os.exit(0); -- :)
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
570 else
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
571 show_message("Failed to execute command: "..error_messages[ret]);
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
572 os.exit(1); -- :(
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
573 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
574 end
ef672c9fe7c9 prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents: 1205
diff changeset
575
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
576 if not commands[command] then -- Show help for all commands
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
577 function show_usage(usage, desc)
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
578 print(" "..usage);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
579 print(" "..desc);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
580 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
581
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
582 print("prosodyctl - Manage a Prosody server");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
583 print("");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
584 print("Usage: "..arg[0].." COMMAND [OPTIONS]");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
585 print("");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
586 print("Where COMMAND may be one of:\n");
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
587
2706
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
588 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" };
c2dde8bda3fe prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents: 2705
diff changeset
589 local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart" };
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
590
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
591 local done = {};
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
592
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
593 for _, command_name in ipairs(commands_order) do
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
594 local command = commands[command_name];
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
595 if command then
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
596 command{ "--help" };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
597 print""
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
598 done[command_name] = true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
599 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
600 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
601
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
602 for command_name, command in pairs(commands) do
1102
c81df501fd38 prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents: 1089
diff changeset
603 if not done[command_name] and not hidden_commands:contains(command_name) then
1087
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
604 command{ "--help" };
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
605 print""
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
606 done[command_name] = true;
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
607 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
608 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
609
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
610
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
611 os.exit(0);
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
612 end
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
613
5e9475bec571 prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
614 os.exit(commands[command]({ select(2, unpack(arg)) }));

mercurial