Add variable shutdown timeouts

This commit is contained in:
Andrew 2022-08-21 12:41:28 -04:00
parent f3590ded0f
commit 44afc72d3a
6 changed files with 40 additions and 4 deletions

View File

@ -38,6 +38,7 @@ class Servers(BaseModel):
logs_delete_after = IntegerField(default=0)
type = CharField(default="minecraft-java")
show_status = BooleanField(default=1)
shutdown_timeout = IntegerField(default=60)
class Meta:
table_name = "servers"

View File

@ -612,12 +612,15 @@ class ServerInstance:
# caching the name and pid number
server_name = self.name
server_pid = self.process.pid
self.shutdown_timeout = self.settings["shutdown_timeout"]
while running:
i += 1
ttk = int(self.shutdown_timeout - (i * 2))
logstr = (
f"Server {server_name} is still running "
f"- waiting 2s to see if it stops ({int(60-(i*2))} "
"- waiting 2s to see if it stops"
f"({ttk} "
f"seconds until force close)"
)
logger.info(logstr)
@ -626,7 +629,7 @@ class ServerInstance:
time.sleep(2)
# if we haven't closed in 60 seconds, let's just slam down on the PID
if i >= 30:
if i >= round(self.shutdown_timeout / 2, 0):
logger.info(
f"Server {server_name} is still running - Forcing the process down"
)

View File

@ -1418,6 +1418,7 @@ class PanelHandler(BaseHandler):
return
server_name = self.get_argument("server_name", None)
server_obj = self.controller.servers.get_server_obj(server_id)
shutdown_timeout = self.get_argument("shutdown_timeout", 60)
if superuser:
server_path = self.get_argument("server_path", None)
if Helpers.is_os_windows():
@ -1498,6 +1499,7 @@ class PanelHandler(BaseHandler):
)
server_obj.server_name = server_name
server_obj.shutdown_timeout = shutdown_timeout
if superuser:
if Helpers.validate_traversal(
self.helper.get_servers_root_dir(), server_path

View File

@ -163,6 +163,17 @@
value="{{ data['server_stats']['server_id']['server_port'] }}" step="1" max="65566" min="1"
required>
</div>
<div class="form-group">
<label for="shutdown_timeout">{{ translate('serverConfig', 'shutdownTimeout', data['lang']) }}
<small class="text-muted ml-1"> - {{ translate('serverConfig', 'timeoutExplain1', data['lang'])
}}&nbsp;
{{ data['server_stats']['server_id']['stop_command'] }}&nbsp;{{ translate('serverConfig',
'timeoutExplain2', data['lang']) }}
</small> </label>
<input type="number" class="form-control" name="shutdown_timeout" id="shutdown_timeout"
value="{{ data['server_stats']['server_id']['shutdown_timeout'] }}" step="2" max="300" min="60"
required>
</div>
{% end %}
<div class="form-group">

View File

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

View File

@ -324,7 +324,10 @@
"stopBeforeDeleting": "Please stop the server before deleting it",
"update": "Update Executable",
"yesDelete": "Yes, delete",
"yesDeleteFiles": "Yes, delete files"
"yesDeleteFiles": "Yes, delete files",
"shutdownTimeout": "Shutdown Timeout",
"timeoutExplain1": "How long Crafty will wait for your server to shutdown after executing the",
"timeoutExplain2": "command before it forces the process down."
},
"serverConfigHelp": {
"desc": "Here is where you can change the configuration of your server",
@ -558,4 +561,4 @@
"userSettings": "User Settings",
"uses": "Number of uses allowed (-1==No Limit)"
}
}
}