|
| 1 | +# watcherd |
| 2 | + |
| 3 | +watcherd will look for directory changes (added and deleted directories) under the specified path (`-p`) and will execute specified commands or shell scripts (`-a`, `-d`) depending on the event. |
| 4 | +Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`). |
| 5 | +Note, the trigger command will only be execute when at least one add or delete command has succeeded with exit code 0. |
| 6 | + |
| 7 | +### Modes |
| 8 | + |
| 9 | +watcherd can either use the native [inotifywait](https://linux.die.net/man/1/inotifywait) implementation or if this is not available on your system use a custom bash implementation. The default is to use bash. |
| 10 | + |
| 11 | +### Examples |
| 12 | + |
| 13 | +Assuming `vhost-add.sh` will add nginx vhost config files and `vhost-del.sh` will remove nginx vhost config files, the following will then be able to create new nginx vhosts on-the-fly, simply by adding or deleting folders in your main www directory. The trigger command will simply force nginx to reload its configuration after directory changes occured. |
| 14 | + |
| 15 | +```shell |
| 16 | +watcherd -p /var/www -a vhost-add.sh -d vhost-del.sh -t "nginx -s stop" |
| 17 | +``` |
| 18 | + |
| 19 | +### Usage |
| 20 | + |
| 21 | +```shell |
| 22 | +Usage: watcherd -p <path> -a <cmd> -d <cmd> [-t <cmd> -w <str> -i <int> -v] |
| 23 | + watcherd --help |
| 24 | + watcherd --version |
| 25 | + |
| 26 | +watcherd will look for directory changes (added and deleted directories) under |
| 27 | +the specified path (-p) and will execute specified commands or shell scripts |
| 28 | +(-a, -d) depending on the event. Once all events have happened during one round |
| 29 | +(-i), a trigger command can be executed (-t). Note, the trigger command will |
| 30 | +only be execute when at least one add or delete command has succeeded with exit |
| 31 | +code 0. |
| 32 | + |
| 33 | +Required arguments: |
| 34 | + -p <path> Path to directoy to watch for changes. |
| 35 | + -a <cmd> Command to execute when a directory was added. |
| 36 | + The full path of the new dir will be appended as an argument to |
| 37 | + this command. |
| 38 | + -d <cmd> Command to execute when a directory was deletd. |
| 39 | + The full path of the new dir will be appended as an argument to |
| 40 | + this command. |
| 41 | + |
| 42 | +Optional arguments: |
| 43 | + -t <cmd> Command to execute after all directories have been added or |
| 44 | + deleted during one round. |
| 45 | + No argument will be appended. |
| 46 | + -w <str> The directory watcher to use. Valid values are: |
| 47 | + 'inotify': Uses inotifywait to watch for directory changes. |
| 48 | + 'bash': Uses a bash loop to watch for directory changes. |
| 49 | + The default is to use 'bash' as the watcher. |
| 50 | + -i <int> When using the bash watcher, specify the interval in seconds |
| 51 | + for how often to look for directory changes. |
| 52 | + -v Verbose output. |
| 53 | + |
| 54 | +Misc arguments: |
| 55 | + --help Show this help screen. |
| 56 | + --version Show version information. |
| 57 | +``` |
0 commit comments