Last active
November 14, 2019 06:01
-
-
Save wwj718/71db083a88f937b438f0683b6ede1f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python3 mycertsdog.py . | |
import logging | |
import sys | |
import time | |
import subprocess | |
from watchdog.events import FileSystemEventHandler | |
from watchdog.observers import Observer | |
logging.basicConfig(level=logging.DEBUG) | |
class MyEventHandler(FileSystemEventHandler): | |
def my_task(self): | |
subprocess.call("cp /home/wwj/.acme.sh/codelab.club/codelab.club.key /home/wwj/mqtt/emqx/etc/certs/key.pem",shell=True) | |
subprocess.call("cp /home/wwj/.acme.sh/codelab.club/fullchain.cer /home/wwj/mqtt/emqx/etc/certs/cert.pem",shell=True) | |
subprocess.call("/home/wwj/mqtt/emqx/bin/emqx restart",shell=True) | |
def on_modified(self, event): | |
# test: cp ~/privkey.pem privkey.pem | |
# import IPython;IPython.embed() | |
if "codelab.club.key" in event.src_path: | |
logging.info(event) | |
time.sleep(1) | |
self.my_task() | |
path = sys.argv[1] | |
event_handler = MyEventHandler() | |
observer = Observer() | |
observer.schedule(event_handler, path, recursive=True) | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment