Add feature - ignore exit codes on crash detection

This commit is contained in:
amcmanu3 2023-02-10 14:02:26 -05:00
parent 3eeb00e524
commit 87fdb1627c
6 changed files with 50 additions and 17 deletions

View File

@ -40,6 +40,7 @@ class Servers(BaseModel):
show_status = BooleanField(default=1) show_status = BooleanField(default=1)
created_by = IntegerField(default=-100) created_by = IntegerField(default=-100)
shutdown_timeout = IntegerField(default=60) shutdown_timeout = IntegerField(default=60)
ignored_exits = CharField(default="0")
class Meta: class Meta:
table_name = "servers" table_name = "servers"

View File

@ -730,26 +730,26 @@ class ServerInstance:
self.server_thread.join() self.server_thread.join()
def stop_server(self): def stop_server(self):
if self.settings["stop_command"]:
self.send_command(self.settings["stop_command"])
if self.settings["crash_detection"]:
# remove crash detection watcher
logger.info(f"Removing crash watcher for server {self.name}")
try:
self.server_scheduler.remove_job("c_" + str(self.server_id))
except:
logger.error(
f"Removing crash watcher for server {self.name} failed. "
f"Assuming it was never started."
)
else:
# windows will need to be handled separately for Ctrl+C
self.process.terminate()
running = self.check_running() running = self.check_running()
if not running: if not running:
logger.info(f"Can't stop server {self.name} if it's not running") logger.info(f"Can't stop server {self.name} if it's not running")
Console.info(f"Can't stop server {self.name} if it's not running") Console.info(f"Can't stop server {self.name} if it's not running")
return return
if self.settings["crash_detection"]:
# remove crash detection watcher
logger.info(f"Removing crash watcher for server {self.name}")
try:
self.server_scheduler.remove_job("c_" + str(self.server_id))
except:
logger.error(
f"Removing crash watcher for server {self.name} failed. "
f"Assuming it was never started."
)
if self.settings["stop_command"]:
self.send_command(self.settings["stop_command"])
else:
# windows will need to be handled separately for Ctrl+C
self.process.terminate()
i = 0 i = 0
# caching the name and pid number # caching the name and pid number
@ -919,7 +919,7 @@ class ServerInstance:
if running: if running:
return return
# check the exit code -- This could be a fix for /stop # check the exit code -- This could be a fix for /stop
if self.process.returncode == 0: if str(self.process.returncode) in self.settings["ignored_exits"].split(","):
logger.warning( logger.warning(
f"Process {self.process.pid} exited with code " f"Process {self.process.pid} exited with code "
f"{self.process.returncode}. This is considered a clean exit" f"{self.process.returncode}. This is considered a clean exit"

View File

@ -1585,6 +1585,8 @@ class PanelHandler(BaseHandler):
crash_detection = int(float(self.get_argument("crash_detection", "0"))) crash_detection = int(float(self.get_argument("crash_detection", "0")))
logs_delete_after = int(float(self.get_argument("logs_delete_after", "0"))) logs_delete_after = int(float(self.get_argument("logs_delete_after", "0")))
java_selection = self.get_argument("java_selection", None) java_selection = self.get_argument("java_selection", None)
# make sure there is no whitespace
ignored_exits = " ".join(self.get_argument("ignored_exits", "").split())
# subpage = self.get_argument('subpage', None) # subpage = self.get_argument('subpage', None)
server_id = self.check_server_id() server_id = self.check_server_id()
@ -1669,6 +1671,7 @@ class PanelHandler(BaseHandler):
server_obj.auto_start = auto_start server_obj.auto_start = auto_start
server_obj.crash_detection = crash_detection server_obj.crash_detection = crash_detection
server_obj.logs_delete_after = logs_delete_after server_obj.logs_delete_after = logs_delete_after
server_obj.ignored_exits = ignored_exits
failed = False failed = False
for servers in self.controller.servers.failed_servers: for servers in self.controller.servers.failed_servers:
if servers["server_id"] == int(server_id): if servers["server_id"] == int(server_id):

View File

@ -184,6 +184,17 @@
value="{{ data['server_stats']['server_id']['shutdown_timeout'] }}" step="2" max="300" min="60" value="{{ data['server_stats']['server_id']['shutdown_timeout'] }}" step="2" max="300" min="60"
required> required>
</div> </div>
<div class="form-group">
<label for="ignored_exits">{{ translate('serverConfig', 'ignoredExits', data['lang']) }}
<small class="text-muted ml-1"> - {{ translate('serverConfig', 'ignoredExitsExplain',
data['lang'])
}}&nbsp;
{{ data['server_stats']['server_id']['ignored_exits'] }}&nbsp;{{ translate('serverConfig',
'timeoutExplain2', data['lang']) }}
</small> </label>
<input type="text" class="form-control" name="ignored_exits" id="ignored_exits"
value="{{ data['server_stats']['server_id']['ignored_exits'] }}">
</div>
<div class="form-group"> <div class="form-group">
<label for="logs_delete_after">{{ translate('serverConfig', 'removeOldLogsAfter', data['lang']) }} <label for="logs_delete_after">{{ translate('serverConfig', 'removeOldLogsAfter', data['lang']) }}

View File

@ -0,0 +1,16 @@
# Generated by database migrator
import peewee
def migrate(migrator, database, **kwargs):
migrator.add_columns("servers", ignored_exits=peewee.CharField(default="0"))
"""
Write your migrations here.
"""
def rollback(migrator, database, **kwargs):
migrator.drop_columns("servers", ["ignored_exits"])
"""
Write your rollback migrations here.
"""

View File

@ -352,7 +352,9 @@
"timeoutExplain1": "How long Crafty will wait for your server to shutdown after executing the", "timeoutExplain1": "How long Crafty will wait for your server to shutdown after executing the",
"timeoutExplain2": "command before it forces the process down.", "timeoutExplain2": "command before it forces the process down.",
"statsHint1": "The port your server is running on should go here. This is just how Crafty opens a connection to your server for stats.", "statsHint1": "The port your server is running on should go here. This is just how Crafty opens a connection to your server for stats.",
"statsHint2": "This does not change the port of your server. You must still change the port in your server config file." "statsHint2": "This does not change the port of your server. You must still change the port in your server config file.",
"ignoredExits": "Ignored Crash Exit Codes",
"ignoredExitsExplain": "Exit codes Crafty's Crash detection should ignore as a normal 'stop' (separated by commas)"
}, },
"serverConfigHelp": { "serverConfigHelp": {
"desc": "Here is where you can change the configuration of your server", "desc": "Here is where you can change the configuration of your server",