plugins/mod_posix.lua
changeset 3341 a8a3e662fea7
parent 3340 0769cc5f34b6
child 3471 482275e38224
equal deleted inserted replaced
3340:0769cc5f34b6 3341:a8a3e662fea7
    93 				local other_pid = pidfile_handle:read("*a");
    93 				local other_pid = pidfile_handle:read("*a");
    94 				module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid);
    94 				module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid);
    95 				pidfile_handle = nil;
    95 				pidfile_handle = nil;
    96 				prosody.shutdown("Prosody already running");
    96 				prosody.shutdown("Prosody already running");
    97 			else
    97 			else
       
    98 				pidfile_handle:close();
    98 				pidfile_handle, err = io.open(pidfile, "w+");
    99 				pidfile_handle, err = io.open(pidfile, "w+");
    99 				if not pidfile_handle then
   100 				if not pidfile_handle then
   100 					module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err);
   101 					module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err);
   101 					prosody.shutdown("Couldn't write pidfile");
   102 					prosody.shutdown("Couldn't write pidfile");
       
   103 				else
       
   104 					if lfs.lock(pidfile_handle, "w") then
       
   105 						pidfile_handle:write(tostring(pposix.getpid()));
       
   106 						pidfile_handle:flush();
       
   107 					end
   102 				end
   108 				end
   103 				pidfile_handle:write(tostring(pposix.getpid()));
       
   104 				pidfile_handle:flush();
       
   105 			end
   109 			end
   106 		end
   110 		end
   107 	end
   111 	end
   108 end
   112 end
   109 
   113