mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add steamcmd upgrade
Also refactor class function names to reflect application neutrality
This commit is contained in:
parent
93adb65b77
commit
6a318f7379
@ -24,7 +24,6 @@ class ImportHelpers:
|
|||||||
self.file_helper: FileHelpers = file_helper
|
self.file_helper: FileHelpers = file_helper
|
||||||
self.helper: Helpers = helper
|
self.helper: Helpers = helper
|
||||||
self.steam_apps: SteamApps = SteamApps(helper)
|
self.steam_apps: SteamApps = SteamApps(helper)
|
||||||
self.steam: SteamCMD()
|
|
||||||
|
|
||||||
def import_jar_server(self, server_path, new_server_dir, port, new_id):
|
def import_jar_server(self, server_path, new_server_dir, port, new_id):
|
||||||
import_thread = threading.Thread(
|
import_thread = threading.Thread(
|
||||||
@ -248,12 +247,15 @@ class ImportHelpers:
|
|||||||
self.helper.ensure_dir_exists(steamcmd_path)
|
self.helper.ensure_dir_exists(steamcmd_path)
|
||||||
self.helper.ensure_dir_exists(gamefiles_path)
|
self.helper.ensure_dir_exists(gamefiles_path)
|
||||||
|
|
||||||
# Set the SteamCMD install directory for next install.
|
# Initialize SteamCMD
|
||||||
self.steam = SteamCMD(steamcmd_path)
|
self.steam = SteamCMD(steamcmd_path)
|
||||||
|
|
||||||
# Install SteamCMD for managing game server files.
|
# Install SteamCMD for managing game server files.
|
||||||
self.steam.install()
|
self.steam.install()
|
||||||
|
|
||||||
|
# Install the game server files.
|
||||||
|
self.steam.app_update(app_id, gamefiles_path)
|
||||||
|
|
||||||
# Set the server execuion command. TODO brainstorm how to approach.
|
# Set the server execuion command. TODO brainstorm how to approach.
|
||||||
full_jar_path = os.path.join(steamcmd_path, server_exe)
|
full_jar_path = os.path.join(steamcmd_path, server_exe)
|
||||||
if Helpers.is_os_windows():
|
if Helpers.is_os_windows():
|
||||||
@ -262,9 +264,6 @@ class ImportHelpers:
|
|||||||
server_command = f"./{server_exe}"
|
server_command = f"./{server_exe}"
|
||||||
logger.debug("command: " + server_command)
|
logger.debug("command: " + server_command)
|
||||||
|
|
||||||
# Install the game server files.
|
|
||||||
self.steam.app_update(app_id, gamefiles_path)
|
|
||||||
|
|
||||||
# Finalise SteamCMD & game installing status.
|
# Finalise SteamCMD & game installing status.
|
||||||
ServersController.finish_import(server_id)
|
ServersController.finish_import(server_id)
|
||||||
server_users = PermissionsServers.get_server_user_list(server_id)
|
server_users = PermissionsServers.get_server_user_list(server_id)
|
||||||
|
@ -37,8 +37,10 @@ from app.classes.shared.helpers import Helpers
|
|||||||
from app.classes.shared.file_helpers import FileHelpers
|
from app.classes.shared.file_helpers import FileHelpers
|
||||||
from app.classes.shared.null_writer import NullWriter
|
from app.classes.shared.null_writer import NullWriter
|
||||||
from app.classes.shared.websocket_manager import WebSocketManager
|
from app.classes.shared.websocket_manager import WebSocketManager
|
||||||
|
from app.classes.steamcmd.steamcmd import SteamCMD
|
||||||
from app.classes.web.webhooks.webhook_factory import WebhookFactory
|
from app.classes.web.webhooks.webhook_factory import WebhookFactory
|
||||||
|
|
||||||
|
|
||||||
with redirect_stderr(NullWriter()):
|
with redirect_stderr(NullWriter()):
|
||||||
import psutil
|
import psutil
|
||||||
from psutil import NoSuchProcess
|
from psutil import NoSuchProcess
|
||||||
@ -1396,10 +1398,10 @@ class ServerInstance:
|
|||||||
]
|
]
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def jar_update(self):
|
def server_upgrade(self):
|
||||||
self.stats_helper.set_update(True)
|
self.stats_helper.set_update(True)
|
||||||
update_thread = threading.Thread(
|
update_thread = threading.Thread(
|
||||||
target=self.a_jar_update, daemon=True, name=f"exe_update_{self.name}"
|
target=self.a_server_upgrade, daemon=True, name=f"exe_update_{self.name}"
|
||||||
)
|
)
|
||||||
update_thread.start()
|
update_thread.start()
|
||||||
|
|
||||||
@ -1440,9 +1442,13 @@ class ServerInstance:
|
|||||||
def check_update(self):
|
def check_update(self):
|
||||||
return self.stats_helper.get_server_stats()["updating"]
|
return self.stats_helper.get_server_stats()["updating"]
|
||||||
|
|
||||||
def a_jar_update(self):
|
def a_server_upgrade(self):
|
||||||
server_users = PermissionsServers.get_server_user_list(self.server_id)
|
server_users = PermissionsServers.get_server_user_list(self.server_id)
|
||||||
was_started = "-1"
|
was_started = "-1"
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# Backup Server ###############
|
||||||
|
###############################
|
||||||
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.
|
||||||
if self.check_running():
|
if self.check_running():
|
||||||
@ -1521,14 +1527,19 @@ class ServerInstance:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# lets download the files
|
################################
|
||||||
|
# Executable Download ##########
|
||||||
|
################################
|
||||||
|
|
||||||
if HelperServers.get_server_type_by_id(self.server_id) != "minecraft-bedrock":
|
# Minecraft Java ###############
|
||||||
|
if HelperServers.get_server_type_by_id(self.server_id) == "minecraft-java":
|
||||||
# boolean returns true for false for success
|
# boolean returns true for false for success
|
||||||
downloaded = Helpers.download_file(
|
downloaded = Helpers.download_file(
|
||||||
self.settings["executable_update_url"], current_executable
|
self.settings["executable_update_url"], current_executable
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
|
# Minecraft Bedrock ############
|
||||||
|
if HelperServers.get_server_type_by_id(self.server_id) == "raknet":
|
||||||
# downloads zip from remote url
|
# downloads zip from remote url
|
||||||
try:
|
try:
|
||||||
bedrock_url = Helpers.get_latest_bedrock_url()
|
bedrock_url = Helpers.get_latest_bedrock_url()
|
||||||
@ -1557,6 +1568,37 @@ class ServerInstance:
|
|||||||
)
|
)
|
||||||
downloaded = False
|
downloaded = False
|
||||||
|
|
||||||
|
# SteamCMD #####################
|
||||||
|
if HelperServers.get_server_type_by_id(self.server_id) == "steam_cmd":
|
||||||
|
try:
|
||||||
|
# Set our storage locations
|
||||||
|
steamcmd_path = os.path.join(self.settings["path"], "steamcmd_files")
|
||||||
|
gamefiles_path = os.path.join(self.settings["path"], "gameserver_files")
|
||||||
|
app_id = SteamCMD.find_app_id(gamefiles_path)
|
||||||
|
|
||||||
|
# Ensure game and steam directories exist in server directory.
|
||||||
|
self.helper.ensure_dir_exists(steamcmd_path)
|
||||||
|
self.helper.ensure_dir_exists(gamefiles_path)
|
||||||
|
|
||||||
|
# Set the SteamCMD install directory for next install.
|
||||||
|
self.steam = SteamCMD(steamcmd_path)
|
||||||
|
|
||||||
|
# Install the game server files.
|
||||||
|
self.steam.app_update(app_id, gamefiles_path, validate=True)
|
||||||
|
downloaded = True
|
||||||
|
except ValueError as e:
|
||||||
|
logger.critical(
|
||||||
|
f"Failed to update SteamCMD Server \n App ID find failed: \n{e}"
|
||||||
|
)
|
||||||
|
downloaded = False
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(f"Failed to update SteamCMD Server \n{e}")
|
||||||
|
downloaded = False
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Start Upgraded Server ########
|
||||||
|
################################
|
||||||
|
|
||||||
if downloaded:
|
if downloaded:
|
||||||
logger.info("Executable updated successfully. Starting Server")
|
logger.info("Executable updated successfully. Starting Server")
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class TasksManager:
|
|||||||
svr.backup_server()
|
svr.backup_server()
|
||||||
|
|
||||||
elif command == "update_executable":
|
elif command == "update_executable":
|
||||||
svr.jar_update()
|
svr.server_upgrade()
|
||||||
else:
|
else:
|
||||||
svr.send_command(command)
|
svr.send_command(command)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user