How can I constantly monitor (small) file for changes?
Eg. when file is updated (action from web application), a script is executed (if not already running).
Right now, I do it every minute using cron, but this has delay up to one minute. I'd like to take the action immediately after the file is changed.
Maybe I need to write some low level process running in the background, once the server is started?
The reason I want to do it is to separate web application from root actions (performed on demand, once when file is updated).
incrond (inotify cron daemon) behaves like cron but uses inotify as the triggering mechanism. This guide has some pretty comprehensive examples.
An example incron entry for the case you described might be:
incron is the software you're searching for.
If you are running Linux, as I assume you are, then you can rely on Linux
inotify
mechanism that notifies user-space processes when files change.LSyncd is one program built around that feature, which you can configure to execute arbitrary commands when files change.