Sign inSign up

livingdocs/file-change-hook

By livingdocs

Updated almost 6 years ago

Trigger a script when file changes happen

Image
0

5.8K

livingdocs/file-change-hook repository overview

livingdocs/file-change-hook

https://github.com/livingdocsIO/docker/tree/master/file-change-hook

A service that watches files for changes and triggers a command on change. e.g. This can be used in kubernetes to trigger config reloads using kill signals.

In the example below the process sleep would receive the SIGHUP signal.

      shareProcessNamespace: true
      volumes:
        - name: postgres-data
          emptyDir: {}
        - name: postgres-config
          configMap: {name: postgres-config}

      containers:
      # just a simple example
      - name: postgres
        image: postgres
        args: ['-c', '/config/postgesql.conf']
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
        - name: postgres-config
          mountPath: /config

      - name: file-change-hook
        image: livingdocs/file-change-hook:1.0
        args: ['killall -SIGHUP postgres && echo SIGHUP triggered', '/config']
        volumeMounts:
        - name: postgres-config
          mountPath: /config
        securityContext:
          capabilities:
            add: [SYS_PTRACE]

Output:

2020-10-21T18:10:22Z [watch]: Watcher started, watching 2 files
2020-10-21T18:11:31Z [watch]: 
2020-10-21T18:11:31Z [watch]: Files changed:
2020-10-21T18:11:31Z [watch]: ----------------
2020-10-21T18:11:31Z [watch]: 
2020-10-21T18:11:32Z [watch]:   > --- /dev/fd/63
2020-10-21T18:11:32Z [watch]:   > +++ /dev/fd/62
2020-10-21T18:11:32Z [watch]:   > @@ -1,2 +1,2 @@
2020-10-21T18:11:32Z [watch]:   > -d903df1d8288fe8d156bdaf2cbd3585a  /config/..2020_10_21_18_09_12.764308948/odyssey.conf
2020-10-21T18:11:32Z [watch]:   > -b86029d189c15545c294e0f4000ef64d  /config/..2020_10_21_18_09_12.764308948/postgresql.conf
2020-10-21T18:11:32Z [watch]:   > +d903df1d8288fe8d156bdaf2cbd3585a  /config/..2020_10_21_18_11_31.022177318/odyssey.conf
2020-10-21T18:11:32Z [watch]:   > +abdcc598b4c0e83dc7c897387f89521c  /config/..2020_10_21_18_11_31.022177318/postgresql.conf
2020-10-21T18:11:32Z [watch]: 
2020-10-21T18:11:32Z [watch]: Execute command:
2020-10-21T18:11:32Z [watch]: ----------------
2020-10-21T18:11:32Z [watch]: 
2020-10-21T18:11:32Z [watch]:   > SIGHUP triggered
2020-10-21T18:11:32Z [watch]: 
2020-10-21T18:11:32Z [watch]: ----------------
2020-10-21T18:11:32Z [watch]: Command suceeded.

Tag summary

Content type

Image

Digest

Size

11.1 MB

Last updated

almost 6 years ago

docker pull livingdocs/file-change-hook:1.0