Software /
code /
prosody
Comparison
util/prosodyctl.lua @ 6367:769a3577dd85
Merge 0.9->0.10
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 28 Aug 2014 09:23:24 +0100 |
parent | 6062:6cc6b4d407df |
parent | 6356:fb1535328ac7 |
child | 6771:60957dd5b41b |
comparison
equal
deleted
inserted
replaced
6355:c2d144d3f8dd | 6367:769a3577dd85 |
---|---|
1 -- Prosody IM | 1 -- Prosody IM |
2 -- Copyright (C) 2008-2010 Matthew Wild | 2 -- Copyright (C) 2008-2010 Matthew Wild |
3 -- Copyright (C) 2008-2010 Waqas Hussain | 3 -- Copyright (C) 2008-2010 Waqas Hussain |
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 | 9 |
144 storagemanager.initialize_host(host); | 144 storagemanager.initialize_host(host); |
145 local provider = host_session.users; | 145 local provider = host_session.users; |
146 if not(provider) or provider.name == "null" then | 146 if not(provider) or provider.name == "null" then |
147 usermanager.initialize_host(host); | 147 usermanager.initialize_host(host); |
148 end | 148 end |
149 | 149 |
150 local ok, errmsg = usermanager.create_user(user, password, host); | 150 local ok, errmsg = usermanager.create_user(user, password, host); |
151 if not ok then | 151 if not ok then |
152 return false, errmsg; | 152 return false, errmsg; |
153 end | 153 end |
154 return true; | 154 return true; |
160 storagemanager.initialize_host(host); | 160 storagemanager.initialize_host(host); |
161 local provider = prosody.hosts[host].users; | 161 local provider = prosody.hosts[host].users; |
162 if not(provider) or provider.name == "null" then | 162 if not(provider) or provider.name == "null" then |
163 usermanager.initialize_host(host); | 163 usermanager.initialize_host(host); |
164 end | 164 end |
165 | 165 |
166 return usermanager.user_exists(user, host); | 166 return usermanager.user_exists(user, host); |
167 end | 167 end |
168 | 168 |
169 function passwd(params) | 169 function passwd(params) |
170 if not _M.user_exists(params) then | 170 if not _M.user_exists(params) then |
171 return false, "no-such-user"; | 171 return false, "no-such-user"; |
172 end | 172 end |
173 | 173 |
174 return _M.adduser(params); | 174 return _M.adduser(params); |
175 end | 175 end |
176 | 176 |
177 function deluser(params) | 177 function deluser(params) |
178 if not _M.user_exists(params) then | 178 if not _M.user_exists(params) then |
179 return false, "no-such-user"; | 179 return false, "no-such-user"; |
180 end | 180 end |
181 local user, host = nodeprep(params.user), nameprep(params.host); | 181 local user, host = nodeprep(params.user), nameprep(params.host); |
182 | 182 |
183 return usermanager.delete_user(user, host); | 183 return usermanager.delete_user(user, host); |
184 end | 184 end |
185 | 185 |
186 function getpid() | 186 function getpid() |
187 local pidfile = config.get("*", "pidfile"); | 187 local pidfile = config.get("*", "pidfile"); |
188 if not pidfile then | 188 if not pidfile then |
189 return false, "no-pidfile"; | 189 return false, "no-pidfile"; |
190 end | 190 end |
191 | 191 |
192 if type(pidfile) ~= "string" then | |
193 return false, "invalid-pidfile"; | |
194 end | |
195 | |
192 local modules_enabled = set.new(config.get("*", "modules_disabled")); | 196 local modules_enabled = set.new(config.get("*", "modules_disabled")); |
193 if prosody.platform ~= "posix" or modules_enabled:contains("posix") then | 197 if prosody.platform ~= "posix" or modules_enabled:contains("posix") then |
194 return false, "no-posix"; | 198 return false, "no-posix"; |
195 end | 199 end |
196 | 200 |
197 local file, err = io.open(pidfile, "r+"); | 201 local file, err = io.open(pidfile, "r+"); |
198 if not file then | 202 if not file then |
199 return false, "pidfile-read-failed", err; | 203 return false, "pidfile-read-failed", err; |
200 end | 204 end |
201 | 205 |
202 local locked, err = lfs.lock(file, "w"); | 206 local locked, err = lfs.lock(file, "w"); |
203 if locked then | 207 if locked then |
204 file:close(); | 208 file:close(); |
205 return false, "pidfile-not-locked"; | 209 return false, "pidfile-not-locked"; |
206 end | 210 end |
207 | 211 |
208 local pid = tonumber(file:read("*a")); | 212 local pid = tonumber(file:read("*a")); |
209 file:close(); | 213 file:close(); |
210 | 214 |
211 if not pid then | 215 if not pid then |
212 return false, "invalid-pid"; | 216 return false, "invalid-pid"; |
213 end | 217 end |
214 | 218 |
215 return true, pid; | 219 return true, pid; |
216 end | 220 end |
217 | 221 |
218 function isrunning() | 222 function isrunning() |
219 local ok, pid, err = _M.getpid(); | 223 local ok, pid, err = _M.getpid(); |
250 return ok, ret; | 254 return ok, ret; |
251 end | 255 end |
252 if not ret then | 256 if not ret then |
253 return false, "not-running"; | 257 return false, "not-running"; |
254 end | 258 end |
255 | 259 |
256 local ok, pid = _M.getpid() | 260 local ok, pid = _M.getpid() |
257 if not ok then return false, pid; end | 261 if not ok then return false, pid; end |
258 | 262 |
259 signal.kill(pid, signal.SIGTERM); | 263 signal.kill(pid, signal.SIGTERM); |
260 return true; | 264 return true; |
261 end | 265 end |
262 | 266 |
263 function reload() | 267 function reload() |
266 return ok, ret; | 270 return ok, ret; |
267 end | 271 end |
268 if not ret then | 272 if not ret then |
269 return false, "not-running"; | 273 return false, "not-running"; |
270 end | 274 end |
271 | 275 |
272 local ok, pid = _M.getpid() | 276 local ok, pid = _M.getpid() |
273 if not ok then return false, pid; end | 277 if not ok then return false, pid; end |
274 | 278 |
275 signal.kill(pid, signal.SIGHUP); | 279 signal.kill(pid, signal.SIGHUP); |
276 return true; | 280 return true; |
277 end | 281 end |
278 | 282 |
279 return _M; | 283 return _M; |