Mercurial > prosody-hg
comparison util/prosodyctl.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 09 Aug 2013 17:48:21 +0200 |
| parents | e9090966c803 |
| children | 6cc6b4d407df |
comparison
equal
deleted
inserted
replaced
| 5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
|---|---|
| 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 local modules_enabled = set.new(config.get("*", "modules_enabled")); | 192 local modules_enabled = set.new(config.get("*", "modules_enabled")); |
| 193 if not modules_enabled:contains("posix") then | 193 if not modules_enabled:contains("posix") then |
| 194 return false, "no-posix"; | 194 return false, "no-posix"; |
| 195 end | 195 end |
| 196 | 196 |
| 197 local file, err = io.open(pidfile, "r+"); | 197 local file, err = io.open(pidfile, "r+"); |
| 198 if not file then | 198 if not file then |
| 199 return false, "pidfile-read-failed", err; | 199 return false, "pidfile-read-failed", err; |
| 200 end | 200 end |
| 201 | 201 |
| 202 local locked, err = lfs.lock(file, "w"); | 202 local locked, err = lfs.lock(file, "w"); |
| 203 if locked then | 203 if locked then |
| 204 file:close(); | 204 file:close(); |
| 205 return false, "pidfile-not-locked"; | 205 return false, "pidfile-not-locked"; |
| 206 end | 206 end |
| 207 | 207 |
| 208 local pid = tonumber(file:read("*a")); | 208 local pid = tonumber(file:read("*a")); |
| 209 file:close(); | 209 file:close(); |
| 210 | 210 |
| 211 if not pid then | 211 if not pid then |
| 212 return false, "invalid-pid"; | 212 return false, "invalid-pid"; |
| 213 end | 213 end |
| 214 | 214 |
| 215 return true, pid; | 215 return true, pid; |
| 216 end | 216 end |
| 217 | 217 |
| 218 function isrunning() | 218 function isrunning() |
| 219 local ok, pid, err = _M.getpid(); | 219 local ok, pid, err = _M.getpid(); |
| 250 return ok, ret; | 250 return ok, ret; |
| 251 end | 251 end |
| 252 if not ret then | 252 if not ret then |
| 253 return false, "not-running"; | 253 return false, "not-running"; |
| 254 end | 254 end |
| 255 | 255 |
| 256 local ok, pid = _M.getpid() | 256 local ok, pid = _M.getpid() |
| 257 if not ok then return false, pid; end | 257 if not ok then return false, pid; end |
| 258 | 258 |
| 259 signal.kill(pid, signal.SIGTERM); | 259 signal.kill(pid, signal.SIGTERM); |
| 260 return true; | 260 return true; |
| 261 end | 261 end |
| 262 | 262 |
| 263 function reload() | 263 function reload() |
| 266 return ok, ret; | 266 return ok, ret; |
| 267 end | 267 end |
| 268 if not ret then | 268 if not ret then |
| 269 return false, "not-running"; | 269 return false, "not-running"; |
| 270 end | 270 end |
| 271 | 271 |
| 272 local ok, pid = _M.getpid() | 272 local ok, pid = _M.getpid() |
| 273 if not ok then return false, pid; end | 273 if not ok then return false, pid; end |
| 274 | 274 |
| 275 signal.kill(pid, signal.SIGHUP); | 275 signal.kill(pid, signal.SIGHUP); |
| 276 return true; | 276 return true; |
| 277 end | 277 end |
| 278 | 278 |
| 279 return _M; | 279 return _M; |
