watcher
Watch and execute command
Installation
npm install no6-app-watcher -g
How to use
watcher ./watch.js
watch.js is configuration file
How to use in Docker
-
Docker
docker run -d --name watcher -v ./test/watch.js:/usr/src/app/watch.js -v ./test:/watcher:ro doanthuanthanh88/watcher
-
docker-compose.yaml
watcher: image: doanthuanthanh88/watcher container_name: watcher tty: true volumes: - ./test/watch.js:/usr/src/app/watch.js # Overide default configuration file - ./test:/watcher:ro # Overide default folder watcher
How to run
watcher ./watch.js
watch.js: This is configuration file and it's stored at $CWD
Configuration
The below configuration file is watch.js
. You can rename it to anything and pass it into execute command
module.exports = {
node_modules: ['axios'], # External libraries which will be installed to use in exec.handle
interval: 500, # Interval time to watch the changes
dir: [ # Directories to watch
'./test'
],
ext: [ # File extension to watch
/\.evt/,
/\.txt/
],
exec: [ # Map file to execute something
{
name: 'all-of-service', # Which is received when user post rest API to execute command remote
file: /nginx\.evt/, # When file match this then executing
cmd: "echo \'thanh\'", # Execute command here
delay: 1000, # Time to delay before executing. If in this period time, if user changes this file many time, it will only execute a last
onInput: [ # Auto update file at path to make executing
'path_file_change',
'file content'
]
onUpdate: { # Handke output
console: true, # Output to console screen
async http(msg) { # Output to rest API. We can use external libs in this. Input is message log
await require('axios')({
method: 'POST',
url: 'https://onapis.com/SEND TO SOMETHING/ID_HERE?group=Test',
headers: {
'content-type': 'text/plain'
},
data: msg
})
}
},
onRemove(){} # Handle when force close or the file is removed
},
{
file: /c\.txt/,
cmd: 'ping -n 5 127.0.0.1',
delay: 0,
handle: {
console: true
}
},
{
file: /d\.txt/,
cmd: 'ping -n 5 127.0.0.1',
delay: 0,
handle: {
console: true
}
}
]
}