Mercurial > prosody-hg
comparison util/prosodyctl.lua @ 2794:5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 11 Jan 2010 00:14:33 +0000 |
| parents | 569d58d21612 |
| children | 1e287badd033 |
comparison
equal
deleted
inserted
replaced
| 2793:08892e3f24bd | 2794:5f14cd94a563 |
|---|---|
| 10 local config = require "core.configmanager"; | 10 local config = require "core.configmanager"; |
| 11 local encodings = require "util.encodings"; | 11 local encodings = require "util.encodings"; |
| 12 local stringprep = encodings.stringprep; | 12 local stringprep = encodings.stringprep; |
| 13 local usermanager = require "core.usermanager"; | 13 local usermanager = require "core.usermanager"; |
| 14 local signal = require "util.signal"; | 14 local signal = require "util.signal"; |
| 15 local lfs = require "lfs"; | |
| 15 | 16 |
| 16 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; | 17 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; |
| 17 | 18 |
| 18 local io, os = io, os; | 19 local io, os = io, os; |
| 19 local tostring, tonumber = tostring, tonumber; | 20 local tostring, tonumber = tostring, tonumber; |
| 62 local pidfile = config.get("*", "core", "pidfile"); | 63 local pidfile = config.get("*", "core", "pidfile"); |
| 63 if not pidfile then | 64 if not pidfile then |
| 64 return false, "no-pidfile"; | 65 return false, "no-pidfile"; |
| 65 end | 66 end |
| 66 | 67 |
| 67 local file, err = io.open(pidfile); | 68 local file, err = io.open(pidfile, "w"); |
| 68 if not file then | 69 if not file then |
| 69 return false, "pidfile-read-failed", err; | 70 return false, "pidfile-read-failed", err; |
| 71 end | |
| 72 | |
| 73 local locked, err = lfs.lock(file, "w"); | |
| 74 if locked then | |
| 75 file:close(); | |
| 76 return false, "pidfile-not-locked"; | |
| 70 end | 77 end |
| 71 | 78 |
| 72 local pid = tonumber(file:read("*a")); | 79 local pid = tonumber(file:read("*a")); |
| 73 file:close(); | 80 file:close(); |
| 74 | 81 |
| 80 end | 87 end |
| 81 | 88 |
| 82 function isrunning() | 89 function isrunning() |
| 83 local ok, pid, err = _M.getpid(); | 90 local ok, pid, err = _M.getpid(); |
| 84 if not ok then | 91 if not ok then |
| 85 if pid == "pidfile-read-failed" then | 92 if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then |
| 86 -- Report as not running, since we can't open the pidfile | 93 -- Report as not running, since we can't open the pidfile |
| 87 -- (it probably doesn't exist) | 94 -- (it probably doesn't exist) |
| 88 return true, false; | 95 return true, false; |
| 89 end | 96 end |
| 90 return ok, pid; | 97 return ok, pid; |
