-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.py
More file actions
36 lines (28 loc) · 1.04 KB
/
watcher.py
File metadata and controls
36 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf -**-
# watcher.py
import subprocess
from os import path
from watchfiles import watch
# Path to the file for which we want to watch
WATCHED_FILE = "plugins/.plugins"
if not path.exists(WATCHED_FILE):
print(f"File {WATCHED_FILE} does not exist. Creating it...")
with open(WATCHED_FILE, "w") as f:
f.write("")
def rebuild_and_restart():
print("Change detected. Rebuilding and restarting Docker Compose services...")
try:
subprocess.run(["docker", "compose", "build"], check=True)
subprocess.run(["docker", "compose", "restart"], check=True)
print("Docker Compose services restarted successfully.")
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
print(f"Watching {WATCHED_FILE} for changes...")
try:
# Watch the file for changes
for changes in watch(WATCHED_FILE):
# Call the rebuild and restart function when a change is detected
rebuild_and_restart()
except KeyboardInterrupt:
print("Stopping watcher...")