.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HOOKABLE 1p" .TH HOOKABLE 1p "2021-03-07" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" inotify\-hookable \- blocking command\-line interface to inotify .SH "SYNOPSIS" .IX Header "SYNOPSIS" Watch a directory, tell us when things change in it: .PP .Vb 1 \& inotify\-hookable \-\-watch\-directories /tmp/watch\-this .Ve .PP Watch a git tree, some configs, and a repository of static assets, restart the webserver or compress those assets if anything changes: .PP .Vb 7 \& inotify\-hookable \e \& \-\-watch\-directories /etc/uwsgi \e \& \-\-watch\-directories /git_tree/central \e \& \-\-watch\-directories /etc/app\-config \e \& \-\-watch\-directories /git_tree/static_assets \e \& \-\-on\-modify\-path\-command "^(/etc/uwsgi|/git_tree/central|/etc/app\-config)=sudo /etc/init.d/uwsgi restart" \e \& \-\-on\-modify\-path\-command "^/git_tree/static_assets=(cd /git_tree/static_assets && compress_static_assets)" .Ve .PP Or watch specific files: .PP .Vb 3 \& inotify\-hookable \e \& \-\-watch\-files /var/www/cgi\-bin/mod_perl_handler \e \& \-\-on\-modify\-command "apachectl restart" .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This simple command-line program is my replacement for the functionality offered by Plack's Filesys::Notify::Simple. I found that on very large git trees Plack would spend an inordinate amount watching the filesystem for changes. .PP This program uses Linux::Inotify2, so the kernel will notify it \&\fBinstantly\fR when something changes (actually it's so fast that we have to work around how fast it sends us events). .PP The result is that you can run this e.g. in a screen session and have it watch your development environment, and your webserver will have begun restarting before your finger leaves the \fIsave\fR button. .PP vim and emacs temporary files are ignored by default (see \f(CW\*(C`\-\-ignore\-paths\*(C'\fR.) so you can edit your files without your server restarting unnecessarily. .PP Currently the command-line interface for this is the only one that really makes sense, this module is entirely blocking (although it could probably run in another process via \s-1POE\s0 or something). Patches welcome. .SH "OPTIONS" .IX Header "OPTIONS" Note that boolean options can be negated with \f(CW\*(C`\-\-no\-OPTION\*(C'\fR, e.g. \f(CW\*(C`\-\-no\-r\*(C'\fR or \f(CW\*(C`\-\-no\-recursive\*(C'\fR to turn off the \f(CW\*(C`\-\-recursive\*(C'\fR option which is on by default. .ie n .SS """\-w"" or ""\-\-watch\-directories""" .el .SS "\f(CW\-w\fP or \f(CW\-\-watch\-directories\fP" .IX Subsection "-w or --watch-directories" Specify this to watch a directory, you can give this however many times you like to watch lots of directories. .ie n .SS """\-f"" or ""\-\-watch\-files""" .el .SS "\f(CW\-f\fP or \f(CW\-\-watch\-files\fP" .IX Subsection "-f or --watch-files" Watch a file, specify multiple times for multiple files. You can watch files and directories in the same command. .ie n .SS """\-r"" or ""\-\-recursive""" .el .SS "\f(CW\-r\fP or \f(CW\-\-recursive\fP" .IX Subsection "-r or --recursive" If you supply this any directory you give will be recursively watched. This is on by default. .ie n .SS """\-c"" or ""\-\-on\-modify\-command""" .el .SS "\f(CW\-c\fP or \f(CW\-\-on\-modify\-command\fP" .IX Subsection "-c or --on-modify-command" A command that will be run when something is modified. .ie n .SS """\-C"" or ""\-\-on\-modify\-path\-command""" .el .SS "\f(CW\-C\fP or \f(CW\-\-on\-modify\-path\-command\fP" .IX Subsection "-C or --on-modify-path-command" A key-value pair where the key is a regex that'll be matched against a modified path, and the value is a command that'll be run. See the \&\*(L"\s-1SYNOPSIS\*(R"\s0 for an example. .PP Useful for e.g. restarting a webserver if you modify directory \fIA\fR but compressing some static assets if you modify directory \fIB\fR. .ie n .SS """\-t"" or ""\-\-buffer\-time""" .el .SS "\f(CW\-t\fP or \f(CW\-\-buffer\-time\fP" .IX Subsection "-t or --buffer-time" Linux will send you inotify events \fBreally\fR fast, so fast that if you run something like: .PP .Vb 1 \& touch foo bar .Ve .PP You might get an event for \fIfoo\fR in one batch, followed by an event for \fIbar\fR later on. .PP To deal with this we enter a loop when we start getting events and sleep for a default of 100 microseconds, as long as we keep getting events we keep sleeping for 100 microseconds, but as soon as we haven't received anything new we fire off our event handlers. .ie n .SS """\-i"" or ""\-\-ignore\-paths""" .el .SS "\f(CW\-i\fP or \f(CW\-\-ignore\-paths\fP" .IX Subsection "-i or --ignore-paths" Regexes for files/directories to ignore events for. By default this is set to regexes for vim and emacs temporary files, \f(CW\*(C`qr{\e..*sw.\ez}\*(C'\fR and \&\f(CW\*(C`qr{\e.\e#[^/]+\ez}\*(C'\fR respectively. .PP The regexes match after any \f(CW\*(C`/\*(C'\fR in the path or the beginning of the string. .ie n .SS """\-d"" or ""\-\-debug""" .el .SS "\f(CW\-d\fP or \f(CW\-\-debug\fP" .IX Subsection "-d or --debug" Spew out some verbose debug output while running. .ie n .SS """\-q"" or ""\-\-[no\-]quiet""" .el .SS "\f(CW\-q\fP or \f(CW\-\-[no\-]quiet\fP" .IX Subsection "-q or --[no-]quiet" Don't log noisy information .SH "ACKNOWLEDGMENT" .IX Header "ACKNOWLEDGMENT" This module was originally developed at and for Booking.com. With approval from Booking.com, this module was generalized and put on \&\s-1CPAN,\s0 for which the authors would like to express their gratitude. .SH "AUTHOR" .IX Header "AUTHOR" Ævar Arnfjörð Bjarmason