monitor file

胡聪 (hucc) hucong.c at foxmail.com
Fri Oct 27 04:12:51 UTC 2017


Hi,

On Friday, Oct 27, 2017 5:04 AM, Dk Jack wrote:

>In my module I'd like to monitor the creation of a file (at a specific) using
>inotify or something similar and load some data from the file. How would I go
>about hooking up the inotifyFd with the nginx event system so that I get a
>callback when the file is created on the disk?

First of all, please make sure that this module is behind ngx_event_core_module.
Here, we asume the module type is NGX_HTTP_MODULE.

Secondly, get some configuration information.

Thirdly, module.init_process needs to be implemented.
And here are the outline of init_process:
if (ngx_worker == 0) {
    fd = inotify_init1(flags);
    wd = inotify_add_watch(fd, pathname, mask);
    c = ngx_get_connection(fd, log);
    rev = c->read;
    ...;
    rev->handler = your_main_callback_handler; /* What you want to do */
    ngx_add_event(rev, NGX_READ_EVENT, 0);
}

Hope this helps!


More information about the nginx-devel mailing list