Skip to content

Commit d2afc2d

Browse files
authored
Merge pull request #208 from mendix/DEP-846_FixLogfilterCrashes
DEP-846 Relaunch logfilter after dying, and log return code.
2 parents 368e9a1 + 22d0e8f commit d2afc2d

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

start.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
)
5454

5555
logger.setLevel(buildpackutil.get_buildpack_loglevel())
56-
logger.info("Started Mendix Cloud Foundry Buildpack v2.2.2")
56+
logger.info("Started Mendix Cloud Foundry Buildpack v2.2.3")
5757
logging.getLogger("m2ee").propagate = False
5858

5959

@@ -802,6 +802,38 @@ def set_up_m2ee_client(vcap_data):
802802
return m2ee
803803

804804

805+
class LogFilterThread(threading.Thread):
806+
def __init__(self, log_ratelimit):
807+
super().__init__()
808+
self.log_ratelimit = log_ratelimit
809+
810+
def run(self):
811+
try:
812+
while True:
813+
proc = subprocess.Popen(
814+
[
815+
"./bin/mendix-logfilter",
816+
"-r",
817+
self.log_ratelimit,
818+
"-f",
819+
"log/out.log",
820+
]
821+
)
822+
proc.wait()
823+
logger.warning(
824+
"MENDIX LOGGING: Mendix logfilter crashed with return code "
825+
"%s. This is nothing to worry about, we are restarting the "
826+
"logfilter now.",
827+
proc.returncode,
828+
)
829+
except Exception:
830+
logger.warning(
831+
"MENDIX LOGGING: Logging pipeline failed completely. To "
832+
"restore log availibility, restart your application.",
833+
exc_info=True,
834+
)
835+
836+
805837
def set_up_logging_file():
806838
buildpackutil.lazy_remove_file("log/out.log")
807839
os.mkfifo("log/out.log")
@@ -816,15 +848,9 @@ def set_up_logging_file():
816848
]
817849
)
818850
else:
819-
subprocess.Popen(
820-
[
821-
"./bin/mendix-logfilter",
822-
"-r",
823-
log_ratelimit,
824-
"-f",
825-
"log/out.log",
826-
]
827-
)
851+
log_filter_thread = LogFilterThread(log_ratelimit)
852+
log_filter_thread.daemon = True
853+
log_filter_thread.start()
828854

829855

830856
def service_backups():

0 commit comments

Comments
 (0)