https://github.com/sagikazarmark/fsig
Send signals to a subprocess when files change
https://github.com/sagikazarmark/fsig
signal subprocess
Last synced: 6 months ago
JSON representation
Send signals to a subprocess when files change
- Host: GitHub
- URL: https://github.com/sagikazarmark/fsig
- Owner: sagikazarmark
- License: mit
- Created: 2018-03-12T00:43:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-25T11:40:24.000Z (about 7 years ago)
- Last Synced: 2025-04-09T23:12:41.983Z (6 months ago)
- Topics: signal, subprocess
- Language: Go
- Size: 53.7 KB
- Stars: 16
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# File Signal (fsig)
[](https://travis-ci.org/sagikazarmark/fsig)
[](https://goreportcard.com/report/github.com/sagikazarmark/fsig)
[](https://godoc.org/github.com/sagikazarmark/fsig)**Send signals to a child process upon file changes**
This project was born because of the need to reload applications upon Kubernetes ConfigMap changes,
but it can be used without the containerization stuff as well.Fsig is heavily inspired by [configmap-reload](https://github.com/jimmidyson/configmap-reload)
which provides a similar use case for modern application (like Prometheus) run on Kubernetes.## Usage
```
usage: fsig --watch=WATCH [] [...]Send signals to a child process upon file changes
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-w, --watch=WATCH ... Watched directory (at least one)
--version Show application version.Args:
Signal to be sent to the child process
Child process command
[] Child process arguments
```### Example
```bash
$ fsig -w watched/dir HUP -- ./my_program --arg
```## Installation
Download a precompiled binary for the [latest](https://github.com/sagikazarmark/fsig/releases/latest) version.
### Ubuntu images
```dockerfile
RUN apt-get update && apt-get install -y wgetENV FSIG_VERSION 0.4.0
RUN wget https://github.com/sagikazarmark/fsig/releases/download/v${FSIG_VERSION}/fsig_${FSIG_VERSION}_linux_amd64.tar.gz \
&& tar -C /usr/local/bin -xzvf fsig_${FSIG_VERSION}_linux_amd64.tar.gz fsig \
&& rm fsig_linux_amd64.tar.gz
```### Alpine images
```dockerfile
RUN apk add --no-cache opensslENV FSIG_VERSION 0.4.0
RUN wget https://github.com/sagikazarmark/fsig/releases/download/v${FSIG_VERSION}/fsig_${FSIG_VERSION}_linux_amd64.tar.gz \
&& tar -C /usr/local/bin -xzvf fsig_${FSIG_VERSION}_linux_amd64.tar.gz fsig \
&& rm fsig_linux_amd64.tar.gz
```## Alternatives
fsig might not always fit your use case.
The following alternatives provide similar solutions to the problem fsig tries to solve.### Shell script
**Pros:**
- very simple
- has only two dependencies (`bash`, `inotifywait`)**Cons:**
- works by putting processes in the background
```bash
#!/bin/bash{
echo "Starting [APPLICATION]"
start_application "$@"
} &pid=$!
watches=${WATCH_PATHS:-"/path/to/watched/file"}echo "Setting up watches for ${watches[@]}"
{
inotifywait -e modify,move,create,delete --timefmt '%d/%m/%y %H:%M' -m --format '%T' ${watches[@]} | while read date time; do
echo "File change detected at ${time} on ${date}"
kill -s HUP $pid
done
echo "Watching file changes failed, killing application"
kill -TERM $pid
} &wait $pid || exit 1
```#### Install on Alpine
```bash
$ apk add bash inotify-tools
```#### Install on Debian
```bash
$ apt-get install bash inotify-tools
```### Entr
[entr](http://entrproject.org/) is a tool similar to `inotifywait` with the purpose of providing better user
experience when used in scripts.**Pros:**
- tiny dependency
- very simple usage (compared to the script above)**Cons:**
- cannot watch directories without exiting first which makes it impossible to use in a Docker container
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.