-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: add a "on process start" hook? #535
Comments
Note that Unit supports multithreading as well. Do you need a hook to be called on each thread or just per process? |
Ideally, both. Here's the hooks Puma supports. Not all of these are going to be applicable to Unit, but you can see the bigger picture:
Thanks Valentin. |
Hi @travisbell, We're currently working on this feature, if you would like to evaluate a patch that is currently being worked on and see if it meets your needs: https://gist.github.com/ocanty/66a820989d98568b73201a2fc4565b76 An example of configuration with the new "hooks" attribute:
An example of a valid "hooks.rb" file follows:
|
This is fantastic! I'll try to find some time to apply the patch and experiment. |
This feature allows one to specify blocks of code that are called when certain lifecycle events occur. A user configures a "hooks" property on the app configuration that points to a script. This script will be evaluated on boot and should contain blocks of code that will be called on specific events. An example of configuration: { "type": "ruby", "processes": 2, "threads": 2, "user": "vagrant", "group": "vagrant", "script": "config.ru", "hooks": "hooks.rb", "working_directory": "/home/vagrant/unit/rbhooks", "environment": { "GEM_HOME": "/home/vagrant/.ruby" } } An example of a valid "hooks.rb" file follows: File.write("./hooks.#{Process.pid}", "hooks evaluated") on_worker_boot do File.write("./worker_boot.#{Process.pid}", "worker booted") end on_thread_boot do File.write("./thread_boot.#{Process.pid}.#{Thread.current.object_id}", "thread booted") end on_thread_shutdown do File.write("./thread_shutdown.#{Process.pid}.#{Thread.current.object_id}", "thread shutdown") end on_worker_shutdown do File.write("./worker_shutdown.#{Process.pid}", "worker shutdown") end This closes issue #535 on GitHub.
I see this was included in 1.25.0, and it's working great. Thanks for the addition! |
This is very close to what I was looking for in #581, is there any chance of implementing such a thing for python? |
@krburkhart but it's already implemented as |
My issue with that is lifespan.shutdown doesn't fire until after web socket connections have closed. But they won't ever close because they are long-running connections. If unit lifespan worked like uvicorn and closed web socket connections when the listener is removed it would make things easier for me. I realize that this is inconsistent with http connections; I want the process to stay alive until those are closed. I have a workaround (utilizing the restart control function), but it involves a fair amount of code on my side that I worry is a bit fragile. Sorry to re-hash this here, I did not realize this is the same as lifespan. |
Hey guys,
I've been working through getting a few Ruby apps of mine battle tested with NGINX Unit and was wondering if there's a chance you would consider adding some hooks around starting up new processes.
The background here is that (in the Ruby world at least), most app servers have some hooks like this. Puma, Unicorn and Iodine for example, provide some ways to execute code on each worker after they've been started. This can be useful to handle things like warming the workers up by connecting to the database and/or caches.
The most popular app server in Ruby, Puma, has a
on_worker_boot
hook. It would be really nice to see something like this for Unit, and I hope you'll consider it.The text was updated successfully, but these errors were encountered: