Mercurial > prosody-hg
comparison plugins/mod_posix.lua @ 11830:7fe2fbfbdb1c
mod_posix: Exit with non-zero status code on problems
Previously it would default to exit with 0 as status code, meaning
success, which is weird.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 30 Sep 2021 23:22:07 +0200 |
| parents | 96da09c771a1 |
| children | 249eb306f668 |
comparison
equal
deleted
inserted
replaced
| 11829:4fad0ca42f66 | 11830:7fe2fbfbdb1c |
|---|---|
| 33 -- Don't even think about it! | 33 -- Don't even think about it! |
| 34 if not prosody.start_time then -- server-starting | 34 if not prosody.start_time then -- server-starting |
| 35 if pposix.getuid() == 0 and not module:get_option_boolean("run_as_root") then | 35 if pposix.getuid() == 0 and not module:get_option_boolean("run_as_root") then |
| 36 module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); | 36 module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); |
| 37 module:log("error", "For more information on running Prosody as root, see https://prosody.im/doc/root"); | 37 module:log("error", "For more information on running Prosody as root, see https://prosody.im/doc/root"); |
| 38 prosody.shutdown("Refusing to run as root"); | 38 prosody.shutdown("Refusing to run as root", 1); |
| 39 end | 39 end |
| 40 end | 40 end |
| 41 | 41 |
| 42 local pidfile; | 42 local pidfile; |
| 43 local pidfile_handle; | 43 local pidfile_handle; |
| 59 local err; | 59 local err; |
| 60 local mode = stat(pidfile) and "r+" or "w+"; | 60 local mode = stat(pidfile) and "r+" or "w+"; |
| 61 pidfile_handle, err = io.open(pidfile, mode); | 61 pidfile_handle, err = io.open(pidfile, mode); |
| 62 if not pidfile_handle then | 62 if not pidfile_handle then |
| 63 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | 63 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); |
| 64 prosody.shutdown("Couldn't write pidfile"); | 64 prosody.shutdown("Couldn't write pidfile", 1); |
| 65 else | 65 else |
| 66 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock | 66 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock |
| 67 local other_pid = pidfile_handle:read("*a"); | 67 local other_pid = pidfile_handle:read("*a"); |
| 68 module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); | 68 module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); |
| 69 pidfile_handle = nil; | 69 pidfile_handle = nil; |
| 70 prosody.shutdown("Prosody already running"); | 70 prosody.shutdown("Prosody already running", 1); |
| 71 else | 71 else |
| 72 pidfile_handle:close(); | 72 pidfile_handle:close(); |
| 73 pidfile_handle, err = io.open(pidfile, "w+"); | 73 pidfile_handle, err = io.open(pidfile, "w+"); |
| 74 if not pidfile_handle then | 74 if not pidfile_handle then |
| 75 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | 75 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); |
| 76 prosody.shutdown("Couldn't write pidfile"); | 76 prosody.shutdown("Couldn't write pidfile", 1); |
| 77 else | 77 else |
| 78 if lfs.lock(pidfile_handle, "w") then | 78 if lfs.lock(pidfile_handle, "w") then |
| 79 pidfile_handle:write(tostring(pposix.getpid())); | 79 pidfile_handle:write(tostring(pposix.getpid())); |
| 80 pidfile_handle:flush(); | 80 pidfile_handle:flush(); |
| 81 end | 81 end |
