mark2devel / mark2

Minecraft Multi Server Wrapper Written in Python with Twisted; Pull Requests HIGHLY Encouraged, Collaborators Needed Discord: https://discord.gg/zymJygHNpv
Other
208 stars 44 forks source link

Run script on crash #157

Closed TomLewis closed 2 years ago

TomLewis commented 2 years ago

Let us run a local script when mark2 detects a crash. Then we can tell our script to do whatever we want.

I'm thinking, send me a pushbullet Pop a message into staff Google chat Post a small message to discord staff Email me the crash log, this would also require a placeholder to easily get the crash log filename.

Column01 commented 2 years ago

You can already do this with the scripting events, in fact I use it on my servers to report crashes to a discord webhook. I can think of a few ways to do this, and adding something explicitly for this isn't really worth the development time in my opinion.

Easy method (method I use)

  1. Catch ServerStopped event and run your script of choice
  2. Scan the crash reports folder for the server and compare it to a list of known crash reports
  3. If there's a report, do something with it. If not, do nothing

In my code, I move reports to another folder inside the crash reports folder called reported and also keep a list of files stored with my script that is checked to ensure reported crashes are not re-reported.

Adept method

  1. Catch ServerStopping event and use the event arg formatting to pass the reason to your script
  2. Parse the reasons for crashed and if it has crashed, scan crash reports folder like before

Expert Method

  1. Catch ServerOutput event and use the event arg formatting to pass the outputted line to your script
  2. Parse the outputted line for a message about a crash report
  3. Gather the path from the message and upload the file/alert places.

Not sure if this will work since server output events require a regex, but it could potentially work. Although this will slow mark2 down in all likelyhood since for every outputted line, mark2 would need to spawn a process to run your script.

Column01 commented 2 years ago

I'll try and make my crash reporter script public, it's in a private gitlab ATM and I don't have admin rights to change it's visibility settings 🙁

Column01 commented 2 years ago

Here you can find the code my network uses to report crashes to a discord webhook, should have all the instructions for setting it up if you want to use it and modify it for your purposes.

TomLewis commented 2 years ago

This is utterly amazing, what a great idea! When I get some spare time I will be looking into implementing your crash_reporter.py! So simple, such a great idea. It is weird that there is no crash event, seeing that mark knows when theres a crash, as it changes the filename for mark2 logs specifically to tell me its a crash log file.