mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Added db setter for stats field (updating) so we can disable start button when server is updating.
This commit is contained in:
parent
aaf8438ddb
commit
979c67d064
@ -157,6 +157,7 @@ class Server_Stats(BaseModel):
|
|||||||
players = CharField(default="")
|
players = CharField(default="")
|
||||||
desc = CharField(default="Unable to Connect")
|
desc = CharField(default="Unable to Connect")
|
||||||
version = CharField(default="")
|
version = CharField(default="")
|
||||||
|
updating = BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -817,6 +818,15 @@ class db_shortcuts:
|
|||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_update(server_id, value):
|
||||||
|
try:
|
||||||
|
row = Server_Stats.select().where(Server_Stats.server_id == server_id)
|
||||||
|
except Exception as ex:
|
||||||
|
logger.error("Database entry not found. ".format(ex))
|
||||||
|
with database.atomic():
|
||||||
|
Server_Stats.update(updating=value).where(Server_Stats.server_id == server_id).execute()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None, auto_enabled: bool = True):
|
def set_backup_config(server_id: int, backup_path: str = None, max_backups: int = None, auto_enabled: bool = True):
|
||||||
logger.debug("Updating server {} backup config with {}".format(server_id, locals()))
|
logger.debug("Updating server {} backup config with {}".format(server_id, locals()))
|
||||||
|
@ -16,6 +16,7 @@ from threading import Thread
|
|||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.models import db_helper, Servers
|
from app.classes.shared.models import db_helper, Servers
|
||||||
|
from app.classes.web.websocket_helper import websocket_helper
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -122,6 +123,9 @@ class Server:
|
|||||||
logger.error("Server is already running - Cancelling Startup")
|
logger.error("Server is already running - Cancelling Startup")
|
||||||
console.error("Server is already running - Cancelling Startup")
|
console.error("Server is already running - Cancelling Startup")
|
||||||
return False
|
return False
|
||||||
|
if self.settings['updating']:
|
||||||
|
websocket_helper.broadcast('warn', "Server is updating. Not starting. Please wait for update to finish.")
|
||||||
|
return False
|
||||||
|
|
||||||
logger.info("Launching Server {} with command {}".format(self.name, self.server_command))
|
logger.info("Launching Server {} with command {}".format(self.name, self.server_command))
|
||||||
console.info("Launching Server {} with command {}".format(self.name, self.server_command))
|
console.info("Launching Server {} with command {}".format(self.name, self.server_command))
|
||||||
@ -379,6 +383,11 @@ class Server:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def jar_update(self):
|
def jar_update(self):
|
||||||
|
db_helper.set_update(self.server_id, True)
|
||||||
|
update_thread = threading.Thread(target=self.a_jar_update, daemon=True, name="exe_update")
|
||||||
|
update_thread.start()
|
||||||
|
|
||||||
|
def a_jar_update(self):
|
||||||
wasStarted = "-1"
|
wasStarted = "-1"
|
||||||
self.backup_server()
|
self.backup_server()
|
||||||
#checks if server is running. Calls shutdown if it is running.
|
#checks if server is running. Calls shutdown if it is running.
|
||||||
@ -394,7 +403,7 @@ class Server:
|
|||||||
if os.path.isdir(backup_dir):
|
if os.path.isdir(backup_dir):
|
||||||
backup_executable = os.path.join(backup_dir, 'old_server.jar')
|
backup_executable = os.path.join(backup_dir, 'old_server.jar')
|
||||||
else:
|
else:
|
||||||
logger.info("Executable backup directory not found for Server: {}}. Creating one.".format(self.name))
|
logger.info("Executable backup directory not found for Server: {}. Creating one.".format(self.name))
|
||||||
os.mkdir(backup_dir)
|
os.mkdir(backup_dir)
|
||||||
backup_executable = os.path.join(backup_dir, 'old_server.jar')
|
backup_executable = os.path.join(backup_dir, 'old_server.jar')
|
||||||
|
|
||||||
@ -415,10 +424,18 @@ class Server:
|
|||||||
downloaded = helper.download_file(self.settings['executable_update_url'], current_executable)
|
downloaded = helper.download_file(self.settings['executable_update_url'], current_executable)
|
||||||
|
|
||||||
if downloaded:
|
if downloaded:
|
||||||
logger.info("Executable updated successfully.")
|
while self.is_backingup:
|
||||||
|
db_helper.set_update(self.server_id, True)
|
||||||
|
pass
|
||||||
|
logger.info("Executable updated successfully. Starting Server")
|
||||||
|
time.sleep(5)
|
||||||
|
db_helper.set_update(self.server_id, False)
|
||||||
|
websocket_helper.broadcast('notification', "Executable update finished for "+self.name)
|
||||||
|
db_helper.add_to_audit_log_raw('Alert', '-1', self.server_id, "Executable update finished for "+self.name, self.settings['server_ip'])
|
||||||
if wasStarted:
|
if wasStarted:
|
||||||
while self.is_backingup:
|
|
||||||
pass
|
|
||||||
self.start_server()
|
self.start_server()
|
||||||
else:
|
else:
|
||||||
|
time.sleep(5)
|
||||||
|
db_helper.set_update(self.server_id, False)
|
||||||
|
websocket_helper.broadcast('notification', "Executable update failed for " + self.name+". Check log file for details.")
|
||||||
logger.error("Executable download failed.")
|
logger.error("Executable download failed.")
|
||||||
|
@ -124,13 +124,14 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="actions_serverlist">
|
<td class="actions_serverlist">
|
||||||
|
|
||||||
{% if server['stats']['running'] %}
|
{% if server['stats']['running'] %}
|
||||||
<a class="stop_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-stop"></i></a>
|
<a class="stop_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-stop"></i></a>
|
||||||
<a class="restart_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-sync"></i></a>
|
<a class="restart_button" data-id="{{server['server_data']['server_id']}}"> <i class="fas fa-sync"></i></a>
|
||||||
|
{% elif server['stats']['updating']%}
|
||||||
|
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> UPDATING...</i></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="play_button"><i class="fas fa-play"></i></a>
|
<a data-id="{{server['server_data']['server_id']}}" class="play_button"><i class="fas fa-play"></i></a>
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> <i class="fas fa-clone"></i></a>
|
<a data-id="{{server['server_data']['server_id']}}" class="clone_button"> <i class="fas fa-clone"></i></a>
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
@ -83,12 +83,19 @@
|
|||||||
<button id="submit" class="btn btn-sm btn-info" type="button">{{ translate('serverTerm', 'sendCommand') }}</button>
|
<button id="submit" class="btn btn-sm btn-info" type="button">{{ translate('serverTerm', 'sendCommand') }}</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{% if data['server_stats']['updating']%}
|
||||||
|
<div class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0">
|
||||||
|
<button onclick="send_command(server_id, 'start_server');" id="start-btn" style="max-width: 7rem;" class="btn btn-warning m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'updating') }}</button>
|
||||||
|
<button onclick="" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1 disabled">{% raw translate('serverTerm', 'restart') %}</button>
|
||||||
|
<button onclick="" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop') }}</button>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
<div class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0">
|
<div class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0">
|
||||||
<button onclick="send_command(server_id, 'start_server');" id="start-btn" style="max-width: 7rem;" class="btn btn-primary m-1 flex-grow-1">{{ translate('serverTerm', 'start') }}</button>
|
<button onclick="send_command(server_id, 'start_server');" id="start-btn" style="max-width: 7rem;" class="btn btn-primary m-1 flex-grow-1">{{ translate('serverTerm', 'start') }}</button>
|
||||||
<button onclick="send_command(server_id, 'restart_server');" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1">{% raw translate('serverTerm', 'restart') %}</button>
|
<button onclick="send_command(server_id, 'restart_server');" id="restart-btn" style="max-width: 7rem;" class="btn btn-outline-primary m-1 flex-grow-1">{% raw translate('serverTerm', 'restart') %}</button>
|
||||||
<button onclick="send_command(server_id, 'stop_server');" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1">{{ translate('serverTerm', 'stop') }}</button>
|
<button onclick="send_command(server_id, 'stop_server');" id="stop-btn" style="max-width: 7rem;" class="btn btn-danger m-1 flex-grow-1">{{ translate('serverTerm', 'stop') }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -125,7 +125,8 @@
|
|||||||
"sendCommand": "Send command",
|
"sendCommand": "Send command",
|
||||||
"start": "Start",
|
"start": "Start",
|
||||||
"restart": "Restart",
|
"restart": "Restart",
|
||||||
"stop": "Stop"
|
"stop": "Stop",
|
||||||
|
"updating": "Updating..."
|
||||||
},
|
},
|
||||||
"serverPlayerManagement": {
|
"serverPlayerManagement": {
|
||||||
"players": "Players",
|
"players": "Players",
|
||||||
|
Loading…
Reference in New Issue
Block a user