2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-20 18:52:44 +08:00

FEATURE: Allow plugins to register demon processes (#11493)

This allows plugins to call `register_demon_process` with a Class inheriting from Demon::Base. The unicorn master process will take care of spawning, monitoring and restarting the process. This API should be used with extreme caution, but it is significantly cleaner than spawning processes/threads in an `after_initialize` block.

This commit also cleans up the demon spawning logging so that it uses the same format as unicorn worker logging. It also switches to the block form of `fork` to ensure that Demons exit after running, rather than returning execution to where the fork took place.
This commit is contained in:
David Taylor 2020-12-16 09:43:39 +00:00 committed by GitHub
parent 38b6b098bc
commit 1d024f77a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View file

@ -141,15 +141,13 @@ class Demon::Base
end
def run
if @pid = fork
write_pid_file
return
@pid = fork do
Process.setproctitle("discourse #{self.class.prefix}")
monitor_parent
establish_app
after_fork
end
Process.setproctitle("discourse #{self.class.prefix}")
monitor_parent
establish_app
after_fork
write_pid_file
end
def already_running?