From 655e321075c0beebe14eba83deeac1ba4c9e0b29 Mon Sep 17 00:00:00 2001 From: Oisin Canty Date: Fri, 2 Jul 2021 12:57:55 +0000 Subject: Ruby: process and thread lifecycle hooks. 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. --- src/nxt_main_process.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nxt_main_process.c') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 00f336f6..10bd2518 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -271,6 +271,11 @@ static nxt_conf_map_t nxt_ruby_app_conf[] = { NXT_CONF_MAP_INT32, offsetof(nxt_common_app_conf_t, u.ruby.threads), }, + { + nxt_string("hooks"), + NXT_CONF_MAP_STR, + offsetof(nxt_common_app_conf_t, u.ruby.hooks), + } }; -- cgit From db03dfad6745a7d87d784ac51ed2d52e1c50a557 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 3 Aug 2021 13:59:27 +0300 Subject: Fixed dead assignments. Found by Clang Static Analyzer. --- src/nxt_main_process.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nxt_main_process.c') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 10bd2518..16c6a297 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -347,8 +347,6 @@ nxt_port_main_start_process_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) nxt_process_init_t *init; nxt_common_app_conf_t *app_conf; - ret = NXT_ERROR; - rt = task->thread->runtime; process = nxt_main_process_new(task, rt); -- cgit