prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Certwatcher does not work with symlinks (on Kubernetes)
  I need to recheck this, but I just had this issue... Will report in 3 Months
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `core/nginx/certwatcher.py`
  Content:
  ```
  1 #!/usr/bin/python3
  2 """
  3 Certificate watcher which reloads nginx or reconfigures it, depending on what
  4 happens to externally supplied certificates. Only executed by start.py in case
  5 of TLS_FLAVOR=[mail, cert]
  6 """
  7 
  8 from os.path import exists, split as path_split
  9 from os import system
  10 import time
  11 from watchdog.observers import Observer
  12 from watchdog.events import FileSystemEventHandler, FileDeletedEvent, \
  13     FileCreatedEvent, FileModifiedEvent, FileMovedEvent
  14 
  15 class ChangeHandler(FileSystemEventHandler):
  16     "watchdog-handler listening on any event, executing the correct configuration/reload steps"
  17     @staticmethod
  18     def reload_nginx():
  19         "merely reload nginx without re-configuring everything"
  20         if exists("/var/run/nginx.pid"):
  21             print("Reloading a running nginx")
  22             system("nginx -s reload")
  23 
  24     @staticmethod
  25     def reexec_config():
  26         "execute a reconfiguration of the system, which also reloads"
  27         print("Reconfiguring system")
  28         system("/config.py")
  29 
  30     def on_any_event(self, event):
  31         "event-listener checking if the affected files are the cert-files we're interested in"
  32         if event.is_directory:
  33             return
  34 
  35         filename = path_split(event.src_path)[-1]
  36         if isinstance(event, FileMovedEvent):
  37             filename = path_split(event.dest_path)[-1]
  38 
  39         if filename in ['cert.pem', 'key.pem']:
  40             # all cases except for FileModified need re-configure
  41             if isinstance(event, (FileCreatedEvent, FileMovedEvent, FileDeletedEvent)):
  42                 ChangeHandler.reexec_config()
  43             # file modification needs only a nginx reload without config.py
  44             elif isinstance(event, FileModifiedEvent):
  45                 ChangeHandler.reload_nginx()
  46         # cert files have been moved away, re-configure
  47         elif isinstance(event, FileMovedEvent) and path_split(event.src_path)[-1] in ['cert.pem', 'key.pem']:
  48             ChangeHandler.reexec_config()
  49 
  50 
  51 if __name__ == '__main__':
  52     observer = Observer()
  53     handler = ChangeHandler()
  54     observer.schedule(handler, "/certs", recursive=False)
  55     observer.start()
  56 
  57     try:
  58         while True:
  59             time.sleep(1)
  60     except KeyboardInterrupt:
  61         observer.stop()
  62 
  63     observer.join()
  64
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/core/nginx/certwatcher.py b/core/nginx/certwatcher.py
  --- a/core/nginx/certwatcher.py
  +++ b/core/nginx/certwatcher.py
  @@ -8,7 +8,7 @@
   from os.path import exists, split as path_split
   from os import system
   import time
  -from watchdog.observers import Observer
  +from watchdog.observers.polling import PollingObserver
   from watchdog.events import FileSystemEventHandler, FileDeletedEvent, \
       FileCreatedEvent, FileModifiedEvent, FileMovedEvent
   
  @@ -49,7 +49,7 @@
   
   
   if __name__ == '__main__':
  -    observer = Observer()
  +    observer = PollingObserver()
       handler = ChangeHandler()
       observer.schedule(handler, "/certs", recursive=False)
       observer.start()
  
verification_info: {"golden_diff": "diff --git a/core/nginx/certwatcher.py b/core/nginx/certwatcher.py\n--- a/core/nginx/certwatcher.py\n+++ b/core/nginx/certwatcher.py\n@@ -8,7 +8,7 @@\n from os.path import exists, split as path_split\n from os import system\n import time\n-from watchdog.observers import Observer\n+from watchdog.observers.polling import PollingObserver\n from watchdog.events import FileSystemEventHandler, FileDeletedEvent, \\\n     FileCreatedEvent, FileModifiedEvent, FileMovedEvent\n \n@@ -49,7 +49,7 @@\n \n \n if __name__ == '__main__':\n-    observer = Observer()\n+    observer = PollingObserver()\n     handler = ChangeHandler()\n     observer.schedule(handler, \"/certs\", recursive=False)\n     observer.start()\n", "issue": "Certwatcher does not work with symlinks (on Kubernetes)\nI need to recheck this, but I just had this issue... Will report in 3 Months\n", "before_files": [{"content": "#!/usr/bin/python3\n\"\"\"\nCertificate watcher which reloads nginx or reconfigures it, depending on what\nhappens to externally supplied certificates. Only executed by start.py in case\nof TLS_FLAVOR=[mail, cert]\n\"\"\"\n\nfrom os.path import exists, split as path_split\nfrom os import system\nimport time\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileSystemEventHandler, FileDeletedEvent, \\\n    FileCreatedEvent, FileModifiedEvent, FileMovedEvent\n\nclass ChangeHandler(FileSystemEventHandler):\n    \"watchdog-handler listening on any event, executing the correct configuration/reload steps\"\n    @staticmethod\n    def reload_nginx():\n        \"merely reload nginx without re-configuring everything\"\n        if exists(\"/var/run/nginx.pid\"):\n            print(\"Reloading a running nginx\")\n            system(\"nginx -s reload\")\n\n    @staticmethod\n    def reexec_config():\n        \"execute a reconfiguration of the system, which also reloads\"\n        print(\"Reconfiguring system\")\n        system(\"/config.py\")\n\n    def on_any_event(self, event):\n        \"event-listener checking if the affected files are the cert-files we're interested in\"\n        if event.is_directory:\n            return\n\n        filename = path_split(event.src_path)[-1]\n        if isinstance(event, FileMovedEvent):\n            filename = path_split(event.dest_path)[-1]\n\n        if filename in ['cert.pem', 'key.pem']:\n            # all cases except for FileModified need re-configure\n            if isinstance(event, (FileCreatedEvent, FileMovedEvent, FileDeletedEvent)):\n                ChangeHandler.reexec_config()\n            # file modification needs only a nginx reload without config.py\n            elif isinstance(event, FileModifiedEvent):\n                ChangeHandler.reload_nginx()\n        # cert files have been moved away, re-configure\n        elif isinstance(event, FileMovedEvent) and path_split(event.src_path)[-1] in ['cert.pem', 'key.pem']:\n            ChangeHandler.reexec_config()\n\n\nif __name__ == '__main__':\n    observer = Observer()\n    handler = ChangeHandler()\n    observer.schedule(handler, \"/certs\", recursive=False)\n    observer.start()\n\n    try:\n        while True:\n            time.sleep(1)\n    except KeyboardInterrupt:\n        observer.stop()\n\n    observer.join()\n", "path": "core/nginx/certwatcher.py"}], "after_files": [{"content": "#!/usr/bin/python3\n\"\"\"\nCertificate watcher which reloads nginx or reconfigures it, depending on what\nhappens to externally supplied certificates. Only executed by start.py in case\nof TLS_FLAVOR=[mail, cert]\n\"\"\"\n\nfrom os.path import exists, split as path_split\nfrom os import system\nimport time\nfrom watchdog.observers.polling import PollingObserver\nfrom watchdog.events import FileSystemEventHandler, FileDeletedEvent, \\\n    FileCreatedEvent, FileModifiedEvent, FileMovedEvent\n\nclass ChangeHandler(FileSystemEventHandler):\n    \"watchdog-handler listening on any event, executing the correct configuration/reload steps\"\n    @staticmethod\n    def reload_nginx():\n        \"merely reload nginx without re-configuring everything\"\n        if exists(\"/var/run/nginx.pid\"):\n            print(\"Reloading a running nginx\")\n            system(\"nginx -s reload\")\n\n    @staticmethod\n    def reexec_config():\n        \"execute a reconfiguration of the system, which also reloads\"\n        print(\"Reconfiguring system\")\n        system(\"/config.py\")\n\n    def on_any_event(self, event):\n        \"event-listener checking if the affected files are the cert-files we're interested in\"\n        if event.is_directory:\n            return\n\n        filename = path_split(event.src_path)[-1]\n        if isinstance(event, FileMovedEvent):\n            filename = path_split(event.dest_path)[-1]\n\n        if filename in ['cert.pem', 'key.pem']:\n            # all cases except for FileModified need re-configure\n            if isinstance(event, (FileCreatedEvent, FileMovedEvent, FileDeletedEvent)):\n                ChangeHandler.reexec_config()\n            # file modification needs only a nginx reload without config.py\n            elif isinstance(event, FileModifiedEvent):\n                ChangeHandler.reload_nginx()\n        # cert files have been moved away, re-configure\n        elif isinstance(event, FileMovedEvent) and path_split(event.src_path)[-1] in ['cert.pem', 'key.pem']:\n            ChangeHandler.reexec_config()\n\n\nif __name__ == '__main__':\n    observer = PollingObserver()\n    handler = ChangeHandler()\n    observer.schedule(handler, \"/certs\", recursive=False)\n    observer.start()\n\n    try:\n        while True:\n            time.sleep(1)\n    except KeyboardInterrupt:\n        observer.stop()\n\n    observer.join()\n", "path": "core/nginx/certwatcher.py"}]}