Software /
code /
prosody
Comparison
util/startup.lua @ 13467:c2a476f4712a
util.startup: Fix exiting on pidfile trouble
prosody.shutdown() relies on prosody.main_thread, which has not been set
yet at this point.
Doing a clean shutdown might actually be harmful in case it tears down
things set up by the conflicting Prosody, such as the very pidfile we
were looking at.
Thanks again SigmaTel71 for noticing
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 27 Mar 2024 19:33:11 +0100 |
parent | 13464:2dbc169aae6a |
child | 13471:afad3b2725bf |
comparison
equal
deleted
inserted
replaced
13466:5d9ec2e55d74 | 13467:c2a476f4712a |
---|---|
717 pidfile = config.resolve_relative_path(prosody.paths.data, pidfile); | 717 pidfile = config.resolve_relative_path(prosody.paths.data, pidfile); |
718 local mode = stat(pidfile) and "r+" or "w+"; | 718 local mode = stat(pidfile) and "r+" or "w+"; |
719 local pidfile_handle, err = io.open(pidfile, mode); | 719 local pidfile_handle, err = io.open(pidfile, mode); |
720 if not pidfile_handle then | 720 if not pidfile_handle then |
721 log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | 721 log("error", "Couldn't write pidfile at %s; %s", pidfile, err); |
722 prosody.shutdown("Couldn't write pidfile", 1); | 722 os.exit(1); |
723 else | 723 else |
724 prosody.pidfile = pidfile; | 724 prosody.pidfile = pidfile; |
725 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock | 725 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock |
726 local other_pid = pidfile_handle:read("*a"); | 726 local other_pid = pidfile_handle:read("*a"); |
727 log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); | 727 log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); |
728 prosody.pidfile_handle = nil; | 728 prosody.pidfile_handle = nil; |
729 prosody.shutdown("Prosody already running", 1); | 729 os.exit(1); |
730 else | 730 else |
731 pidfile_handle:close(); | 731 pidfile_handle:close(); |
732 pidfile_handle, err = io.open(pidfile, "w+"); | 732 pidfile_handle, err = io.open(pidfile, "w+"); |
733 if not pidfile_handle then | 733 if not pidfile_handle then |
734 log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | 734 log("error", "Couldn't write pidfile at %s; %s", pidfile, err); |
735 prosody.shutdown("Couldn't write pidfile", 1); | 735 os.exit(1); |
736 else | 736 else |
737 if lfs.lock(pidfile_handle, "w") then | 737 if lfs.lock(pidfile_handle, "w") then |
738 pidfile_handle:write(tostring(pposix.getpid())); | 738 pidfile_handle:write(tostring(pposix.getpid())); |
739 pidfile_handle:flush(); | 739 pidfile_handle:flush(); |
740 prosody.pidfile_handle = pidfile_handle; | 740 prosody.pidfile_handle = pidfile_handle; |