Software /
code /
prosody
Comparison
util/prosodyctl.lua @ 6771:60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 17 Jul 2015 12:43:04 +0200 |
parent | 6367:769a3577dd85 |
child | 6777:5de6b93d0190 |
comparison
equal
deleted
inserted
replaced
6766:b38db4b634d3 | 6771:60957dd5b41b |
---|---|
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"); |
190 end | 190 end |
191 | 191 |
192 if type(pidfile) ~= "string" then | 192 if type(pidfile) ~= "string" then |
193 return false, "invalid-pidfile"; | 193 return false, "invalid-pidfile"; |
194 end | 194 end |
195 | 195 |
196 local modules_enabled = set.new(config.get("*", "modules_disabled")); | 196 local modules_enabled = set.new(config.get("*", "modules_disabled")); |
197 if prosody.platform ~= "posix" or modules_enabled:contains("posix") then | 197 if prosody.platform ~= "posix" or modules_enabled:contains("posix") then |
198 return false, "no-posix"; | 198 return false, "no-posix"; |
199 end | 199 end |
200 | 200 |
201 local file, err = io.open(pidfile, "r+"); | 201 local file, err = io.open(pidfile, "r+"); |
202 if not file then | 202 if not file then |
203 return false, "pidfile-read-failed", err; | 203 return false, "pidfile-read-failed", err; |
204 end | 204 end |
205 | 205 |
206 local locked, err = lfs.lock(file, "w"); | 206 local locked, err = lfs.lock(file, "w"); |
207 if locked then | 207 if locked then |
208 file:close(); | 208 file:close(); |
209 return false, "pidfile-not-locked"; | 209 return false, "pidfile-not-locked"; |
210 end | 210 end |
211 | 211 |
212 local pid = tonumber(file:read("*a")); | 212 local pid = tonumber(file:read("*a")); |
213 file:close(); | 213 file:close(); |
214 | 214 |
215 if not pid then | 215 if not pid then |
216 return false, "invalid-pid"; | 216 return false, "invalid-pid"; |
217 end | 217 end |
218 | 218 |
219 return true, pid; | 219 return true, pid; |
220 end | 220 end |
221 | 221 |
222 function isrunning() | 222 function isrunning() |
223 local ok, pid, err = _M.getpid(); | 223 local ok, pid, err = _M.getpid(); |
254 return ok, ret; | 254 return ok, ret; |
255 end | 255 end |
256 if not ret then | 256 if not ret then |
257 return false, "not-running"; | 257 return false, "not-running"; |
258 end | 258 end |
259 | 259 |
260 local ok, pid = _M.getpid() | 260 local ok, pid = _M.getpid() |
261 if not ok then return false, pid; end | 261 if not ok then return false, pid; end |
262 | 262 |
263 signal.kill(pid, signal.SIGTERM); | 263 signal.kill(pid, signal.SIGTERM); |
264 return true; | 264 return true; |
265 end | 265 end |
266 | 266 |
267 function reload() | 267 function reload() |
270 return ok, ret; | 270 return ok, ret; |
271 end | 271 end |
272 if not ret then | 272 if not ret then |
273 return false, "not-running"; | 273 return false, "not-running"; |
274 end | 274 end |
275 | 275 |
276 local ok, pid = _M.getpid() | 276 local ok, pid = _M.getpid() |
277 if not ok then return false, pid; end | 277 if not ok then return false, pid; end |
278 | 278 |
279 signal.kill(pid, signal.SIGHUP); | 279 signal.kill(pid, signal.SIGHUP); |
280 return true; | 280 return true; |
281 end | 281 end |
282 | 282 |
283 return _M; | 283 return _M; |