Skip to content

Instantly share code, notes, and snippets.

@wwj718

wwj718/mycertsdog.py

Last active Nov 14, 2019
Embed
What would you like to do?
# 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
You can’t perform that action at this time.