Skip to content

Commit 84a7894

Browse files
committed
add watch.py
1 parent b063315 commit 84a7894

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
build: .
1717
container_name: "sync"
1818
volumes:
19-
- /home/docker/bareos-sd/data/storage:/data
19+
- ./data/storage:/data
2020
- ./logs:/var/log/s3sync
2121
```
2222
the directory to watch must mounted in volume. In this exemple (for bareos : /home/docker/bareos-sd/data/storage)

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ services:
44
build: .
55
container_name: "sync"
66
volumes:
7-
- /home/docker/bareos-sd/data/storage:/data
7+
- ./data/storage:/data
88
- ./logs:/var/log/s3sync

rootfs/watch.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python3
2+
import os.path
3+
import argparse
4+
import pyinotify
5+
6+
class EventHandler(pyinotify.ProcessEvent):
7+
def process_IN_CLOSE_WRITE(self, event):
8+
print(f"IN_CLOSE_WRITE event detected on: {event.pathname}")
9+
def process_IN_DELETE(self,event):
10+
print(f"IN_DELETE event detected on: {event.pathname}")
11+
def main():
12+
global __SECTION__
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument('--path', help='configFile',default='/data')
15+
args = parser.parse_args()
16+
path = args.path
17+
wm = pyinotify.WatchManager()
18+
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE
19+
notifier = pyinotify.Notifier(wm, EventHandler())
20+
wm.add_watch(path, mask)
21+
try:
22+
notifier.loop()
23+
except KeyboardInterrupt:
24+
print("Stopped.")
25+
if __name__ == "__main__":
26+
main()

0 commit comments

Comments
 (0)