mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'feature/forge-install' into 'dev'
Automated forge install See merge request crafty-controller/crafty-4!495
This commit is contained in:
commit
a7fa91b225
@ -1,7 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
## --- [4.0.17] - 2022/TBD
|
## --- [4.0.17] - 2022/TBD
|
||||||
### New features
|
### New features
|
||||||
TBD
|
- Automate forge install process through Crafty server creation for Forge server version 1.16 and greater. ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/495))
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Fix no port on bedrock server creation ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/493))
|
- Fix no port on bedrock server creation ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/493))
|
||||||
### Tweaks
|
### Tweaks
|
||||||
|
@ -119,9 +119,15 @@ class ServersController(metaclass=Singleton):
|
|||||||
return srv.stats_helper.set_import()
|
return srv.stats_helper.set_import()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def finish_import(server_id):
|
def finish_import(server_id, forge=False):
|
||||||
srv = ServersController().get_server_instance_by_id(server_id)
|
srv = ServersController().get_server_instance_by_id(server_id)
|
||||||
return srv.stats_helper.finish_import()
|
# This is where we start the forge installerr
|
||||||
|
if forge:
|
||||||
|
srv.run_threaded_server(
|
||||||
|
HelperUsers.get_user_id_by_name("system"), forge_install=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
srv.stats_helper.finish_import()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_import_status(server_id):
|
def get_import_status(server_id):
|
||||||
|
@ -187,24 +187,22 @@ class ServerJars:
|
|||||||
|
|
||||||
# open a file stream
|
# open a file stream
|
||||||
with requests.get(fetch_url, timeout=2, stream=True) as r:
|
with requests.get(fetch_url, timeout=2, stream=True) as r:
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
with open(path, "wb") as output:
|
with open(path, "wb") as output:
|
||||||
shutil.copyfileobj(r.raw, output)
|
shutil.copyfileobj(r.raw, output)
|
||||||
|
# If this is the newer forge version we will run the installer
|
||||||
|
if server == "forge" and int(version.split(".")[1]) > 15:
|
||||||
|
ServersController.finish_import(server_id, True)
|
||||||
|
else:
|
||||||
ServersController.finish_import(server_id)
|
ServersController.finish_import(server_id)
|
||||||
|
|
||||||
for user in server_users:
|
success = True
|
||||||
self.helper.websocket_helper.broadcast_user(
|
|
||||||
user, "notification", "Executable download finished"
|
|
||||||
)
|
|
||||||
time.sleep(3)
|
|
||||||
self.helper.websocket_helper.broadcast_user(
|
|
||||||
user, "send_start_reload", {}
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Unable to save jar to {path} due to error:{e}")
|
logger.error(f"Unable to save jar to {path} due to error:{e}")
|
||||||
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)
|
||||||
|
|
||||||
for user in server_users:
|
for user in server_users:
|
||||||
self.helper.websocket_helper.broadcast_user(
|
self.helper.websocket_helper.broadcast_user(
|
||||||
user, "notification", "Executable download finished"
|
user, "notification", "Executable download finished"
|
||||||
@ -213,5 +211,4 @@ class ServerJars:
|
|||||||
self.helper.websocket_helper.broadcast_user(
|
self.helper.websocket_helper.broadcast_user(
|
||||||
user, "send_start_reload", {}
|
user, "send_start_reload", {}
|
||||||
)
|
)
|
||||||
|
return success
|
||||||
return False
|
|
||||||
|
@ -484,11 +484,26 @@ class Controller:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if Helpers.is_os_windows():
|
if Helpers.is_os_windows():
|
||||||
|
# Let's check for and setup for install server commands
|
||||||
|
if server == "forge":
|
||||||
|
server_command = (
|
||||||
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||||
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||||
|
f'-jar "{server_file}" --installServer'
|
||||||
|
)
|
||||||
|
else:
|
||||||
server_command = (
|
server_command = (
|
||||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||||
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||||
f'-jar "{server_file}" nogui'
|
f'-jar "{server_file}" nogui'
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
if server == "forge":
|
||||||
|
server_command = (
|
||||||
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||||
|
f"-Xmx{Helpers.float_to_string(max_mem)}M "
|
||||||
|
f"-jar {server_file} --installServer"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
server_command = (
|
server_command = (
|
||||||
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
f"java -Xms{Helpers.float_to_string(min_mem)}M "
|
||||||
|
@ -202,12 +202,15 @@ class ServerInstance:
|
|||||||
# remove the scheduled job since it's ran
|
# remove the scheduled job since it's ran
|
||||||
return self.server_scheduler.remove_job(str(self.server_id))
|
return self.server_scheduler.remove_job(str(self.server_id))
|
||||||
|
|
||||||
def run_threaded_server(self, user_id):
|
def run_threaded_server(self, user_id, forge_install=False):
|
||||||
# start the server
|
# start the server
|
||||||
self.server_thread = threading.Thread(
|
self.server_thread = threading.Thread(
|
||||||
target=self.start_server,
|
target=self.start_server,
|
||||||
daemon=True,
|
daemon=True,
|
||||||
args=(user_id,),
|
args=(
|
||||||
|
user_id,
|
||||||
|
forge_install,
|
||||||
|
),
|
||||||
name=f"{self.server_id}_server_thread",
|
name=f"{self.server_id}_server_thread",
|
||||||
)
|
)
|
||||||
self.server_thread.start()
|
self.server_thread.start()
|
||||||
@ -292,13 +295,13 @@ class ServerInstance:
|
|||||||
logger.critical(f"Unable to write/access {self.server_path}")
|
logger.critical(f"Unable to write/access {self.server_path}")
|
||||||
Console.critical(f"Unable to write/access {self.server_path}")
|
Console.critical(f"Unable to write/access {self.server_path}")
|
||||||
|
|
||||||
def start_server(self, user_id):
|
def start_server(self, user_id, forge_install=False):
|
||||||
if not user_id:
|
if not user_id:
|
||||||
user_lang = self.helper.get_setting("language")
|
user_lang = self.helper.get_setting("language")
|
||||||
else:
|
else:
|
||||||
user_lang = HelperUsers.get_user_lang_by_id(user_id)
|
user_lang = HelperUsers.get_user_lang_by_id(user_id)
|
||||||
|
|
||||||
if self.stats_helper.get_import_status():
|
if self.stats_helper.get_import_status() and not forge_install:
|
||||||
if user_id:
|
if user_id:
|
||||||
self.helper.websocket_helper.broadcast_user(
|
self.helper.websocket_helper.broadcast_user(
|
||||||
user_id,
|
user_id,
|
||||||
@ -341,7 +344,9 @@ class ServerInstance:
|
|||||||
"eula= true",
|
"eula= true",
|
||||||
"eula =true",
|
"eula =true",
|
||||||
]
|
]
|
||||||
|
# If this is a forge installer we're running we can bypass the eula checks.
|
||||||
|
if forge_install is True:
|
||||||
|
e_flag = True
|
||||||
if not e_flag and self.settings["type"] == "minecraft-java":
|
if not e_flag and self.settings["type"] == "minecraft-java":
|
||||||
if user_id:
|
if user_id:
|
||||||
self.helper.websocket_helper.broadcast_user(
|
self.helper.websocket_helper.broadcast_user(
|
||||||
@ -422,6 +427,9 @@ class ServerInstance:
|
|||||||
).format(self.name, ex)
|
).format(self.name, ex)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if forge_install:
|
||||||
|
# Reset import status if failed while forge installing
|
||||||
|
self.stats_helper.finish_import()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -460,6 +468,9 @@ class ServerInstance:
|
|||||||
).format(self.name, ex)
|
).format(self.name, ex)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
if forge_install:
|
||||||
|
# Reset import status if failed while forge installing
|
||||||
|
self.stats_helper.finish_import()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
out_buf = ServerOutBuf(self.helper, self.process, self.server_id)
|
out_buf = ServerOutBuf(self.helper, self.process, self.server_id)
|
||||||
@ -540,6 +551,10 @@ class ServerInstance:
|
|||||||
self.detect_crash, "interval", seconds=30, id=f"c_{self.server_id}"
|
self.detect_crash, "interval", seconds=30, id=f"c_{self.server_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# If this is a forge install we'll call the watcher to do the things
|
||||||
|
if forge_install:
|
||||||
|
self.forge_install_watcher()
|
||||||
|
|
||||||
def check_internet_thread(self, user_id, user_lang):
|
def check_internet_thread(self, user_id, user_lang):
|
||||||
if user_id:
|
if user_id:
|
||||||
if not Helpers.check_internet():
|
if not Helpers.check_internet():
|
||||||
@ -553,6 +568,78 @@ class ServerInstance:
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def forge_install_watcher(self):
|
||||||
|
# Enter for install if that parameter is true
|
||||||
|
while True:
|
||||||
|
# We'll watch the process
|
||||||
|
if self.process.poll() is None:
|
||||||
|
# IF process still has not exited we'll keep looping
|
||||||
|
time.sleep(5)
|
||||||
|
Console.debug("Installing Forge...")
|
||||||
|
else:
|
||||||
|
# Process has exited. Lets do some work to setup the new
|
||||||
|
# run command.
|
||||||
|
# Let's grab the server object we're going to update.
|
||||||
|
server_obj = HelperServers.get_server_obj(self.server_id)
|
||||||
|
|
||||||
|
# The forge install is done so we can delete that install file.
|
||||||
|
os.remove(os.path.join(server_obj.path, server_obj.executable))
|
||||||
|
|
||||||
|
# We need to grab the exact forge version number.
|
||||||
|
# We know we can find it here in the run.sh/bat script.
|
||||||
|
run_file_path = ""
|
||||||
|
if self.helper.is_os_windows():
|
||||||
|
run_file_path = os.path.join(server_obj.path, "run.bat")
|
||||||
|
else:
|
||||||
|
run_file_path = os.path.join(server_obj.path, "run.sh")
|
||||||
|
|
||||||
|
if Helpers.check_file_perms(run_file_path) and os.path.isfile(
|
||||||
|
run_file_path
|
||||||
|
):
|
||||||
|
run_file = open(run_file_path, "r", encoding="utf-8")
|
||||||
|
run_file_text = run_file.read()
|
||||||
|
else:
|
||||||
|
Console.error(
|
||||||
|
"ERROR ! Forge install can't read the scripts files."
|
||||||
|
" Aborting ..."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# We get the server command parameters from forge script
|
||||||
|
server_command = re.findall(
|
||||||
|
r"java @([a-zA-Z0-9_\.]+)"
|
||||||
|
r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?",
|
||||||
|
run_file_text,
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
version = server_command[2]
|
||||||
|
executable_path = f"{server_command[1]}{server_command[2]}/"
|
||||||
|
|
||||||
|
# Let's set the proper server executable
|
||||||
|
server_obj.executable = os.path.join(
|
||||||
|
f"{executable_path}forge-{version}-server.jar"
|
||||||
|
)
|
||||||
|
# Now lets set up the new run command.
|
||||||
|
# This is based off the run.sh/bat that
|
||||||
|
# Forge uses in 1.16 and <
|
||||||
|
execution_command = (
|
||||||
|
f"java @{server_command[0]}"
|
||||||
|
f" @{executable_path}{server_command[3]} nogui {server_command[4]}"
|
||||||
|
)
|
||||||
|
server_obj.execution_command = execution_command
|
||||||
|
Console.debug("SUCCESS! Forge install completed")
|
||||||
|
|
||||||
|
# We'll update the server with the new information now.
|
||||||
|
HelperServers.update_server(server_obj)
|
||||||
|
self.stats_helper.finish_import()
|
||||||
|
server_users = PermissionsServers.get_server_user_list(self.server_id)
|
||||||
|
|
||||||
|
for user in server_users:
|
||||||
|
self.helper.websocket_helper.broadcast_user(
|
||||||
|
user, "send_start_reload", {}
|
||||||
|
)
|
||||||
|
break
|
||||||
|
|
||||||
def stop_crash_detection(self):
|
def stop_crash_detection(self):
|
||||||
# This is only used if the crash detection settings change
|
# This is only used if the crash detection settings change
|
||||||
# while the server is running.
|
# while the server is running.
|
||||||
|
@ -168,22 +168,11 @@
|
|||||||
|
|
||||||
<td draggable="false" id="controls{{server['server_data']['server_id']}}" class="actions_serverlist">
|
<td draggable="false" id="controls{{server['server_data']['server_id']}}" class="actions_serverlist">
|
||||||
{% if server['user_command_permission'] %}
|
{% if server['user_command_permission'] %}
|
||||||
{% if server['stats']['running'] %}
|
{% if server['stats']['importing'] and server['stats']['running'] %}
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="stop_button" data-toggle="tooltip"
|
<!-- WHAT HAPPENED HERE -->
|
||||||
title="{{ translate('dashboard', 'stop' , data['lang']) }}">
|
<a data-id="{{server['server_data']['server_id']}}" class=""><i
|
||||||
<i class="fas fa-stop"></i>
|
class="fa fa-spinner fa-spin"></i> {{ translate('serverTerm', 'installing',
|
||||||
</a>
|
data['lang']) }}</i></a>
|
||||||
|
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="restart_button" data-toggle="tooltip"
|
|
||||||
title="{{ translate('dashboard', 'restart' , data['lang']) }}">
|
|
||||||
<i class="fas fa-sync"></i>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="kill_button" data-toggle="tooltip"
|
|
||||||
title="{{ translate('dashboard', 'kill' , data['lang']) }}">
|
|
||||||
<i class="fas fa-skull"></i>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{% elif server['stats']['updating']%}
|
{% elif server['stats']['updating']%}
|
||||||
<!-- WHAT HAPPENED HERE -->
|
<!-- WHAT HAPPENED HERE -->
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class=""><i
|
<a data-id="{{server['server_data']['server_id']}}" class=""><i
|
||||||
@ -198,6 +187,21 @@
|
|||||||
<a data-id="{{server['server_data']['server_id']}}" class=""><i class="fa fa-spinner fa-spin"></i>
|
<a data-id="{{server['server_data']['server_id']}}" class=""><i class="fa fa-spinner fa-spin"></i>
|
||||||
{{ translate('serverTerm', 'importing',
|
{{ translate('serverTerm', 'importing',
|
||||||
data['lang']) }}</a>
|
data['lang']) }}</a>
|
||||||
|
{% elif server['stats']['running'] %}
|
||||||
|
<a data-id="{{server['server_data']['server_id']}}" class="stop_button" data-toggle="tooltip"
|
||||||
|
title="{{ translate('dashboard', 'stop' , data['lang']) }}">
|
||||||
|
<i class="fas fa-stop"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a data-id="{{server['server_data']['server_id']}}" class="restart_button" data-toggle="tooltip"
|
||||||
|
title="{{ translate('dashboard', 'restart' , data['lang']) }}">
|
||||||
|
<i class="fas fa-sync"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a data-id="{{server['server_data']['server_id']}}" class="kill_button" data-toggle="tooltip"
|
||||||
|
title="{{ translate('dashboard', 'kill' , data['lang']) }}">
|
||||||
|
<i class="fas fa-skull"></i>
|
||||||
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a data-id="{{server['server_data']['server_id']}}" class="play_button" data-toggle="tooltip"
|
<a data-id="{{server['server_data']['server_id']}}" class="play_button" data-toggle="tooltip"
|
||||||
title="{{ translate('dashboard', 'start' , data['lang']) }}">
|
title="{{ translate('dashboard', 'start' , data['lang']) }}">
|
||||||
|
@ -62,7 +62,21 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
{% if data['permissions']['Commands'] in data['user_permissions'] %}
|
||||||
{% if data['server_stats']['updating']%}
|
{% if data['importing'] and data['server_stats']['running']%}
|
||||||
|
<div id="update_control_buttons"
|
||||||
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
||||||
|
style="visibility: visible">
|
||||||
|
<button onclick="" id="start-btn" style="max-width: 7rem;"
|
||||||
|
class="btn btn-warning m-1 flex-grow-1 disabled"><i
|
||||||
|
class="fa fa-spinner fa-spin"></i> {{translate('serverTerm', 'installing', data['lang']) }}</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',
|
||||||
|
data['lang']) %}</button>
|
||||||
|
<button onclick="" id="stop-btn" style="max-width: 7rem;"
|
||||||
|
class="btn btn-danger m-1 flex-grow-1 disabled">{{ translate('serverTerm', 'stop', data['lang'])
|
||||||
|
}}</button>
|
||||||
|
</div>
|
||||||
|
{% elif data['server_stats']['updating']%}
|
||||||
<div id="update_control_buttons"
|
<div id="update_control_buttons"
|
||||||
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
class="mt-4 flex-wrap d-flex justify-content-between justify-content-md-center align-items-center px-5 px-md-0"
|
||||||
style="visibility: visible">
|
style="visibility: visible">
|
||||||
|
@ -97,7 +97,8 @@
|
|||||||
"status": "Status",
|
"status": "Status",
|
||||||
"stop": "Stop",
|
"stop": "Stop",
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"welcome": "Welcome to Crafty Controller"
|
"welcome": "Welcome to Crafty Controller",
|
||||||
|
"installing": "Installing..."
|
||||||
},
|
},
|
||||||
"datatables": {
|
"datatables": {
|
||||||
"i18n": {
|
"i18n": {
|
||||||
@ -481,7 +482,8 @@
|
|||||||
"starting": "Delayed-Start",
|
"starting": "Delayed-Start",
|
||||||
"stop": "Stop",
|
"stop": "Stop",
|
||||||
"stopScroll": "Stop Auto Scrolling",
|
"stopScroll": "Stop Auto Scrolling",
|
||||||
"updating": "Updating..."
|
"updating": "Updating...",
|
||||||
|
"installing": "Installing..."
|
||||||
},
|
},
|
||||||
"serverMetrics": {
|
"serverMetrics": {
|
||||||
"resetZoom": "Reset Zoom",
|
"resetZoom": "Reset Zoom",
|
||||||
|
@ -97,7 +97,8 @@
|
|||||||
"status": "Statut",
|
"status": "Statut",
|
||||||
"stop": "Arrêter",
|
"stop": "Arrêter",
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"welcome": "Bienvenue sur Crafty Controller"
|
"welcome": "Bienvenue sur Crafty Controller",
|
||||||
|
"installing": "Installation ..."
|
||||||
},
|
},
|
||||||
"datatables": {
|
"datatables": {
|
||||||
"i18n": {
|
"i18n": {
|
||||||
@ -450,7 +451,13 @@
|
|||||||
"starting": "Démarrage retardé",
|
"starting": "Démarrage retardé",
|
||||||
"stop": "Arrêter",
|
"stop": "Arrêter",
|
||||||
"stopScroll": "Stopper l'Auto Défilement",
|
"stopScroll": "Stopper l'Auto Défilement",
|
||||||
"updating": "Mise à Jour ..."
|
"updating": "Mise à Jour ...",
|
||||||
|
"installing": "Installation ..."
|
||||||
|
},
|
||||||
|
"serverMetrics": {
|
||||||
|
"resetZoom": "Reset Zoom",
|
||||||
|
"zoomHint1": "Pour zoomer le graphique, maintenir la touche SHIFT et utiliser la molette de la souris.",
|
||||||
|
"zoomHint2": "Il est aussi possible de maintenir la touche SHIFT puis de clicker et déplacer la zone sur laquelle zoomer."
|
||||||
},
|
},
|
||||||
"serverWizard": {
|
"serverWizard": {
|
||||||
"absoluteServerPath": "Chemin absolu de Votre Serveur",
|
"absoluteServerPath": "Chemin absolu de Votre Serveur",
|
||||||
|
Loading…
Reference in New Issue
Block a user