2022-01-10 20:11:52 -05:00
from datetime import timedelta
2022-01-19 21:34:59 +01:00
from http import server
2020-08-11 20:36:09 -04:00
import os
import sys
import json
import time
import logging
import threading
2021-02-26 17:39:35 +02:00
import asyncio
2021-08-09 20:48:22 -04:00
import shutil
2022-01-14 14:59:06 -05:00
from tzlocal import get_localzone
2022-01-10 20:11:52 -05:00
from app . classes . controllers . users_controller import Users_Controller
2020-08-11 20:36:09 -04:00
from app . classes . shared . helpers import helper
from app . classes . shared . console import console
2021-03-21 23:02:18 -05:00
from app . classes . web . tornado import Webserver
2021-02-26 17:39:35 +02:00
from app . classes . web . websocket_helper import websocket_helper
2020-08-31 13:46:25 -04:00
2020-08-23 18:43:28 -04:00
from app . classes . minecraft . serverjars import server_jar_obj
2021-09-09 00:01:10 +02:00
from app . classes . models . servers import servers_helper
from app . classes . models . management import management_helper
2022-01-10 20:11:52 -05:00
from apscheduler . events import EVENT_JOB_ERROR , EVENT_JOB_EXECUTED , EVENT_ALL , EVENT_JOB_REMOVED
2020-08-11 20:36:09 -04:00
2022-01-12 17:29:45 -05:00
logger = logging . getLogger ( ' apscheduler ' )
2020-08-11 20:36:09 -04:00
2020-08-16 22:47:53 -04:00
try :
2022-01-12 16:09:38 -05:00
from apscheduler . schedulers . background import BackgroundScheduler
2022-01-19 14:43:34 -05:00
from apscheduler . triggers . cron import CronTrigger
2020-08-16 22:47:53 -04:00
except ModuleNotFoundError as e :
2021-04-03 13:29:10 -05:00
logger . critical ( " Import Error: Unable to load {} module " . format ( e . name ) , exc_info = True )
2021-04-17 23:34:13 +03:00
console . critical ( " Import Error: Unable to load {} module " . format ( e . name ) )
2020-08-16 22:47:53 -04:00
sys . exit ( 1 )
2020-08-11 20:36:09 -04:00
2021-03-21 23:02:18 -05:00
scheduler_intervals = { ' seconds ' ,
' minutes ' ,
' hours ' ,
' days ' ,
' weeks ' ,
' monday ' ,
' tuesday ' ,
' wednesday ' ,
' thursday ' ,
' friday ' ,
' saturday ' ,
' sunday '
}
2020-12-17 15:39:29 +02:00
2020-08-11 20:36:09 -04:00
class TasksManager :
2021-03-21 23:02:18 -05:00
def __init__ ( self , controller ) :
self . controller = controller
self . tornado = Webserver ( controller , self )
2022-01-19 14:43:34 -05:00
self . tz = get_localzone ( )
self . scheduler = BackgroundScheduler ( timezone = str ( self . tz ) )
2022-01-10 20:11:52 -05:00
self . users_controller = Users_Controller ( )
2020-08-11 20:36:09 -04:00
self . webserver_thread = threading . Thread ( target = self . tornado . run_tornado , daemon = True , name = ' tornado_thread ' )
self . main_thread_exiting = False
2020-08-16 22:47:53 -04:00
self . schedule_thread = threading . Thread ( target = self . scheduler_thread , daemon = True , name = " scheduler " )
2021-01-20 17:20:42 +02:00
self . log_watcher_thread = threading . Thread ( target = self . log_watcher , daemon = True , name = " log_watcher " )
2020-08-31 13:46:25 -04:00
self . command_thread = threading . Thread ( target = self . command_watcher , daemon = True , name = " command_watcher " )
2021-02-26 17:39:35 +02:00
self . realtime_thread = threading . Thread ( target = self . realtime , daemon = True , name = " realtime " )
2021-03-21 23:02:18 -05:00
self . reload_schedule_from_db ( )
2020-12-17 15:39:29 +02:00
2020-08-11 20:36:09 -04:00
def get_main_thread_run_status ( self ) :
return self . main_thread_exiting
2021-03-21 23:02:18 -05:00
def reload_schedule_from_db ( self ) :
2021-09-09 00:01:10 +02:00
jobs = management_helper . get_schedules_enabled ( )
2022-01-12 17:29:45 -05:00
logger . info ( " Reload from DB called. Current enabled schedules: " )
for item in jobs :
logger . info ( " JOB: {} " . format ( item ) )
2022-01-19 21:34:59 +01:00
2021-03-21 23:02:18 -05:00
def command_watcher ( self ) :
2020-08-31 13:46:25 -04:00
while True :
# select any commands waiting to be processed
2021-09-09 00:01:10 +02:00
commands = management_helper . get_unactioned_commands ( )
2020-08-31 16:16:45 -04:00
for c in commands :
2022-01-18 14:43:22 -05:00
try :
svr = self . controller . get_server_obj ( c . server_id )
except :
logger . error ( " Server value requested does note exist purging item from waiting commands. " )
management_helper . mark_command_complete ( c . command_id )
user_id = c . user_id
command = c . command
2020-08-31 16:16:45 -04:00
if command == ' start_server ' :
2021-11-27 17:10:43 -05:00
svr . run_threaded_server ( user_id )
2020-08-31 16:16:45 -04:00
elif command == ' stop_server ' :
svr . stop_threaded_server ( )
elif command == " restart_server " :
2021-11-27 17:10:43 -05:00
svr . restart_threaded_server ( user_id )
2020-08-31 16:16:45 -04:00
2021-03-21 23:02:18 -05:00
elif command == " backup_server " :
svr . backup_server ( )
2021-07-24 21:09:39 -04:00
elif command == " update_executable " :
2021-11-20 12:25:14 -05:00
svr . jar_update ( )
2022-01-11 00:26:33 -05:00
else :
svr . send_command ( command )
2022-01-18 14:43:22 -05:00
management_helper . mark_command_complete ( c . command_id )
2020-08-31 16:16:45 -04:00
2020-08-31 13:46:25 -04:00
time . sleep ( 1 )
2020-08-11 20:36:09 -04:00
def _main_graceful_exit ( self ) :
2020-08-16 22:47:53 -04:00
try :
os . remove ( helper . session_file )
os . remove ( os . path . join ( helper . root_dir , ' .header ' ) )
2021-03-21 23:02:18 -05:00
self . controller . stop_all_servers ( )
2020-08-16 22:47:53 -04:00
except :
2021-03-13 09:24:17 -06:00
logger . info ( " Caught error during shutdown " , exc_info = True )
2020-08-18 21:04:43 -04:00
logger . info ( " ***** Crafty Shutting Down ***** \n \n " )
console . info ( " ***** Crafty Shutting Down ***** \n \n " )
2020-08-11 20:36:09 -04:00
self . main_thread_exiting = True
def start_webserver ( self ) :
self . webserver_thread . start ( )
def reload_webserver ( self ) :
self . tornado . stop_web_server ( )
console . info ( " Waiting 3 seconds " )
time . sleep ( 3 )
self . webserver_thread = threading . Thread ( target = self . tornado . run_tornado , daemon = True , name = ' tornado_thread ' )
self . start_webserver ( )
def stop_webserver ( self ) :
self . tornado . stop_web_server ( )
2020-08-16 22:47:53 -04:00
def start_scheduler ( self ) :
logger . info ( " Launching Scheduler Thread... " )
console . info ( " Launching Scheduler Thread... " )
self . schedule_thread . start ( )
2021-03-21 23:02:18 -05:00
logger . info ( " Launching command thread... " )
console . info ( " Launching command thread... " )
self . command_thread . start ( )
logger . info ( " Launching log watcher... " )
console . info ( " Launching log watcher... " )
self . log_watcher_thread . start ( )
logger . info ( " Launching realtime thread... " )
console . info ( " Launching realtime thread... " )
self . realtime_thread . start ( )
2020-08-16 22:47:53 -04:00
2022-01-10 20:11:52 -05:00
def scheduler_thread ( self ) :
2022-01-11 00:26:33 -05:00
schedules = management_helper . get_schedules_enabled ( )
2022-01-11 01:29:27 -05:00
self . scheduler . add_listener ( self . schedule_watcher , mask = EVENT_JOB_EXECUTED )
#self.scheduler.add_job(self.scheduler.print_jobs, 'interval', seconds=10, id='-1')
2022-01-19 14:43:34 -05:00
2022-01-11 00:26:33 -05:00
#load schedules from DB
for schedule in schedules :
2022-01-11 12:17:57 -05:00
if schedule . cron_string != " " :
2022-01-19 13:07:26 -05:00
try :
2022-01-19 14:43:34 -05:00
self . scheduler . add_job ( management_helper . add_command , CronTrigger . from_crontab ( schedule . cron_string , timezone = str ( self . tz ) ) , id = str ( schedule . schedule_id ) , args = [ schedule . server_id , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , schedule . command ] )
2022-01-19 13:07:26 -05:00
except Exception as e :
console . error ( " Failed to schedule task with error: {} . " . format ( e ) )
console . warning ( " Removing failed task from DB. " )
2022-01-19 14:43:34 -05:00
logger . error ( " Failed to schedule task with error: {} . " . format ( e ) )
logger . warning ( " Removing failed task from DB. " )
#remove items from DB if task fails to add to apscheduler
2022-01-19 13:07:26 -05:00
management_helper . delete_scheduled_task ( schedule . schedule_id )
2022-01-11 12:17:57 -05:00
else :
if schedule . interval_type == ' hours ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = 0 , hour = ' */ ' + str ( schedule . interval ) , id = str ( schedule . schedule_id ) , args = [ schedule . server_id , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , schedule . command ] )
elif schedule . interval_type == ' minutes ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = ' */ ' + str ( schedule . interval ) , id = str ( schedule . schedule_id ) , args = [ schedule . server_id , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , schedule . command ] )
elif schedule . interval_type == ' days ' :
time = schedule . start_time . split ( ' : ' )
self . scheduler . add_job ( management_helper . add_command , ' cron ' , day = ' */ ' + str ( schedule . interval ) , hour = time [ 0 ] , minute = time [ 1 ] , id = str ( schedule . schedule_id ) , args = [ schedule . server_id , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , schedule . command ] )
2022-01-11 00:26:33 -05:00
2022-01-10 20:11:52 -05:00
self . scheduler . start ( )
2022-01-12 16:09:38 -05:00
jobs = self . scheduler . get_jobs ( )
2022-01-12 17:29:45 -05:00
logger . info ( " Loaded schedules. Current enabled schedules: " )
2022-01-12 16:09:38 -05:00
for item in jobs :
logger . info ( " JOB: {} " . format ( item ) )
2022-01-10 20:11:52 -05:00
def schedule_job ( self , job_data ) :
2022-01-11 18:51:07 -05:00
sch_id = management_helper . create_scheduled_task ( job_data [ ' server_id ' ] , job_data [ ' action ' ] , job_data [ ' interval ' ] , job_data [ ' interval_type ' ] , job_data [ ' start_time ' ] , job_data [ ' command ' ] , " None " , job_data [ ' enabled ' ] , job_data [ ' one_time ' ] , job_data [ ' cron_string ' ] )
2022-01-10 20:11:52 -05:00
if job_data [ ' enabled ' ] :
2022-01-11 12:17:57 -05:00
if job_data [ ' cron_string ' ] != " " :
2022-01-11 17:41:46 -05:00
try :
2022-01-19 14:43:34 -05:00
self . scheduler . add_job ( management_helper . add_command , CronTrigger . from_crontab ( job_data [ ' cron_string ' ] , timezone = str ( self . tz ) ) , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
2022-01-11 17:41:46 -05:00
except Exception as e :
console . error ( " Failed to schedule task with error: {} . " . format ( e ) )
2022-01-19 13:07:26 -05:00
console . warning ( " Removing failed task from DB. " )
2022-01-19 14:43:34 -05:00
logger . error ( " Failed to schedule task with error: {} . " . format ( e ) )
logger . warning ( " Removing failed task from DB. " )
#remove items from DB if task fails to add to apscheduler
2022-01-11 17:41:46 -05:00
management_helper . delete_scheduled_task ( sch_id )
2022-01-11 12:17:57 -05:00
else :
if job_data [ ' interval_type ' ] == ' hours ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = 0 , hour = ' */ ' + str ( job_data [ ' interval ' ] ) , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
elif job_data [ ' interval_type ' ] == ' minutes ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = ' */ ' + str ( job_data [ ' interval ' ] ) , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
elif job_data [ ' interval_type ' ] == ' days ' :
2022-01-11 17:24:05 -05:00
time = job_data [ ' start_time ' ] . split ( ' : ' )
2022-01-11 12:17:57 -05:00
self . scheduler . add_job ( management_helper . add_command , ' cron ' , day = ' */ ' + str ( job_data [ ' interval ' ] ) , hour = time [ 0 ] , minute = time [ 1 ] , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] , )
2022-01-12 17:29:45 -05:00
logger . info ( " Added job. Current enabled schedules: " )
jobs = self . scheduler . get_jobs ( )
for item in jobs :
logger . info ( " JOB: {} " . format ( item ) )
2022-01-10 20:11:52 -05:00
2022-01-14 23:53:44 -05:00
def remove_all_server_tasks ( self , server_id ) :
schedules = management_helper . get_schedules_by_server ( server_id )
for schedule in schedules :
self . remove_job ( schedule . schedule_id )
2022-01-10 20:11:52 -05:00
def remove_job ( self , sch_id ) :
2022-01-13 00:30:35 -05:00
job = management_helper . get_scheduled_task_model ( sch_id )
2022-01-10 20:11:52 -05:00
management_helper . delete_scheduled_task ( sch_id )
2022-01-13 00:30:35 -05:00
if job . enabled :
self . scheduler . remove_job ( str ( sch_id ) )
2022-01-14 23:53:44 -05:00
logger . info ( " Job with ID {} was deleted. " . format ( sch_id ) )
2022-01-13 00:30:35 -05:00
else :
2022-01-14 23:53:44 -05:00
logger . info ( " Job with ID {} was deleted from DB, but was not enabled. Not going to try removing something that doesn ' t exist from active schedules. " . format ( sch_id ) )
2022-01-10 20:11:52 -05:00
2022-01-11 17:24:05 -05:00
def update_job ( self , sch_id , job_data ) :
management_helper . update_scheduled_task ( sch_id , job_data )
2022-01-11 19:30:00 -05:00
try :
2022-01-11 17:24:05 -05:00
self . scheduler . remove_job ( str ( sch_id ) )
2022-01-11 19:30:00 -05:00
except :
logger . info ( " No job found in update job. Assuming it was previously disabled. Starting new job. " )
2022-01-11 17:24:05 -05:00
if job_data [ ' cron_string ' ] != " " :
cron = job_data [ ' cron_string ' ] . split ( ' ' )
2022-01-11 17:41:46 -05:00
try :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = cron [ 0 ] , hour = cron [ 1 ] , day = cron [ 2 ] , month = cron [ 3 ] , day_of_week = cron [ 4 ] , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
except Exception as e :
console . error ( " Failed to schedule task with error: {} . " . format ( e ) )
console . info ( " Removing failed task from DB. " )
management_helper . delete_scheduled_task ( sch_id )
2022-01-11 17:24:05 -05:00
else :
if job_data [ ' interval_type ' ] == ' hours ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = 0 , hour = ' */ ' + str ( job_data [ ' interval ' ] ) , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
elif job_data [ ' interval_type ' ] == ' minutes ' :
self . scheduler . add_job ( management_helper . add_command , ' cron ' , minute = ' */ ' + str ( job_data [ ' interval ' ] ) , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] )
elif job_data [ ' interval_type ' ] == ' days ' :
time = job_data [ ' start_time ' ] . split ( ' : ' )
self . scheduler . add_job ( management_helper . add_command , ' cron ' , day = ' */ ' + str ( job_data [ ' interval ' ] ) , hour = time [ 0 ] , minute = time [ 1 ] , id = str ( sch_id ) , args = [ job_data [ ' server_id ' ] , self . users_controller . get_id_by_name ( ' system ' ) , ' 127.0.0.1 ' , job_data [ ' command ' ] ] , )
else :
try :
self . scheduler . get_job ( str ( sch_id ) )
self . scheduler . remove_job ( str ( sch_id ) )
except :
logger . info ( " APScheduler found no scheduled job on schedule update for schedule with id: {} . Assuming it was already disabled. " . format ( sch_id ) )
2022-01-10 20:11:52 -05:00
def schedule_watcher ( self , event ) :
if not event . exception :
2022-01-12 17:29:45 -05:00
if str ( event . job_id ) . isnumeric ( ) :
task = management_helper . get_scheduled_task_model ( int ( event . job_id ) )
if task . one_time :
self . remove_job ( task . schedule_id )
logger . info ( " one time task detected. Deleting... " )
else :
logger . info ( " Event job ID is not numerical. Assuming it ' s stats - not stored in DB. Moving on. " )
2022-01-11 01:29:27 -05:00
else :
logger . error ( " Task failed with error: {} " . format ( event . exception ) )
2020-08-11 20:36:09 -04:00
2021-03-21 23:02:18 -05:00
def start_stats_recording ( self ) :
2020-08-27 18:30:56 -04:00
stats_update_frequency = helper . get_setting ( ' stats_update_frequency ' )
2020-08-18 21:04:43 -04:00
logger . info ( " Stats collection frequency set to {stats} seconds " . format ( stats = stats_update_frequency ) )
console . info ( " Stats collection frequency set to {stats} seconds " . format ( stats = stats_update_frequency ) )
2020-08-24 19:16:33 -04:00
2020-08-23 22:17:36 -04:00
# one for now,
2021-03-21 23:02:18 -05:00
self . controller . stats . record_stats ( )
2020-08-23 22:17:36 -04:00
# one for later
2022-01-11 21:56:37 -05:00
self . scheduler . add_job ( self . controller . stats . record_stats , ' interval ' , seconds = stats_update_frequency , id = " stats " )
2020-08-11 20:36:09 -04:00
2022-01-11 21:56:37 -05:00
def serverjar_cache_refresher ( self ) :
2020-08-23 18:43:28 -04:00
logger . info ( " Refreshing serverjars.com cache on start " )
server_jar_obj . refresh_cache ( )
logger . info ( " Scheduling Serverjars.com cache refresh service every 12 hours " )
2022-01-11 21:56:37 -05:00
self . scheduler . add_job ( server_jar_obj . refresh_cache , ' interval ' , hours = 12 , id = " serverjars " )
2020-08-23 18:43:28 -04:00
2022-01-19 21:34:59 +01:00
def realtime ( self ) :
2021-02-26 17:39:35 +02:00
loop = asyncio . new_event_loop ( )
asyncio . set_event_loop ( loop )
2021-03-01 02:54:20 +02:00
2021-09-09 00:01:10 +02:00
host_stats = management_helper . get_latest_hosts_stats ( )
2021-02-26 17:39:35 +02:00
while True :
if host_stats . get ( ' cpu_usage ' ) != \
2021-09-09 00:01:10 +02:00
management_helper . get_latest_hosts_stats ( ) . get ( ' cpu_usage ' ) or \
2021-02-26 17:39:35 +02:00
host_stats . get ( ' mem_percent ' ) != \
2021-09-09 00:01:10 +02:00
management_helper . get_latest_hosts_stats ( ) . get ( ' mem_percent ' ) :
2021-02-26 17:39:35 +02:00
# Stats are different
2021-09-09 00:01:10 +02:00
host_stats = management_helper . get_latest_hosts_stats ( )
2021-02-26 17:39:35 +02:00
if len ( websocket_helper . clients ) > 0 :
# There are clients
2021-08-10 23:17:56 +03:00
websocket_helper . broadcast_page ( ' /panel/dashboard ' , ' update_host_stats ' , {
2021-02-26 17:39:35 +02:00
' cpu_usage ' : host_stats . get ( ' cpu_usage ' ) ,
' cpu_cores ' : host_stats . get ( ' cpu_cores ' ) ,
' cpu_cur_freq ' : host_stats . get ( ' cpu_cur_freq ' ) ,
' cpu_max_freq ' : host_stats . get ( ' cpu_max_freq ' ) ,
' mem_percent ' : host_stats . get ( ' mem_percent ' ) ,
' mem_usage ' : host_stats . get ( ' mem_usage ' )
} )
2022-01-19 21:34:59 +01:00
servers = self . controller . servers_list
servers_ping = [ ]
for srv in servers :
server_data = srv . get ( ' server_data_obj ' , False )
if server_data :
server_id = server_data . get ( ' server_id ' , False )
srv [ ' raw_ping_result ' ] = self . controller . stats . get_raw_server_stats ( server_id )
if ( " {} " . format ( srv [ ' raw_ping_result ' ] . get ( ' icon ' ) ) == " b ' ' " ) :
srv [ ' raw_ping_result ' ] [ ' icon ' ] = False
2022-01-19 22:45:52 +01:00
2022-01-19 21:34:59 +01:00
servers_ping . append ( {
' id ' : srv [ ' raw_ping_result ' ] . get ( ' id ' ) ,
' started ' : srv [ ' raw_ping_result ' ] . get ( ' started ' ) ,
' running ' : srv [ ' raw_ping_result ' ] . get ( ' running ' ) ,
' cpu ' : srv [ ' raw_ping_result ' ] . get ( ' cpu ' ) ,
' mem ' : srv [ ' raw_ping_result ' ] . get ( ' mem ' ) ,
' mem_percent ' : srv [ ' raw_ping_result ' ] . get ( ' mem_percent ' ) ,
' world_name ' : srv [ ' raw_ping_result ' ] . get ( ' world_name ' ) ,
' world_size ' : srv [ ' raw_ping_result ' ] . get ( ' world_size ' ) ,
' server_port ' : srv [ ' raw_ping_result ' ] . get ( ' server_port ' ) ,
' int_ping_results ' : srv [ ' raw_ping_result ' ] . get ( ' int_ping_results ' ) ,
' online ' : srv [ ' raw_ping_result ' ] . get ( ' online ' ) ,
' max ' : srv [ ' raw_ping_result ' ] . get ( ' max ' ) ,
' players ' : srv [ ' raw_ping_result ' ] . get ( ' players ' ) ,
' desc ' : srv [ ' raw_ping_result ' ] . get ( ' desc ' ) ,
' version ' : srv [ ' raw_ping_result ' ] . get ( ' version ' ) ,
' icon ' : srv [ ' raw_ping_result ' ] . get ( ' icon ' )
} )
2022-01-21 23:50:04 +01:00
if ( len ( websocket_helper . clients ) > 0 ) :
websocket_helper . broadcast_page_params (
' /panel/server_detail ' ,
{
' id ' : str ( server_id )
} ,
' update_server_details ' ,
{
' id ' : srv [ ' raw_ping_result ' ] . get ( ' id ' ) ,
' started ' : srv [ ' raw_ping_result ' ] . get ( ' started ' ) ,
' running ' : srv [ ' raw_ping_result ' ] . get ( ' running ' ) ,
' cpu ' : srv [ ' raw_ping_result ' ] . get ( ' cpu ' ) ,
' mem ' : srv [ ' raw_ping_result ' ] . get ( ' mem ' ) ,
' mem_percent ' : srv [ ' raw_ping_result ' ] . get ( ' mem_percent ' ) ,
' world_name ' : srv [ ' raw_ping_result ' ] . get ( ' world_name ' ) ,
' world_size ' : srv [ ' raw_ping_result ' ] . get ( ' world_size ' ) ,
' server_port ' : srv [ ' raw_ping_result ' ] . get ( ' server_port ' ) ,
' int_ping_results ' : srv [ ' raw_ping_result ' ] . get ( ' int_ping_results ' ) ,
' online ' : srv [ ' raw_ping_result ' ] . get ( ' online ' ) ,
' max ' : srv [ ' raw_ping_result ' ] . get ( ' max ' ) ,
' players ' : srv [ ' raw_ping_result ' ] . get ( ' players ' ) ,
' desc ' : srv [ ' raw_ping_result ' ] . get ( ' desc ' ) ,
' version ' : srv [ ' raw_ping_result ' ] . get ( ' version ' ) ,
' icon ' : srv [ ' raw_ping_result ' ] . get ( ' icon ' )
}
)
2022-01-19 21:34:59 +01:00
if ( len ( servers_ping ) > 0 ) & ( len ( websocket_helper . clients ) > 0 ) :
try :
2022-01-19 22:45:52 +01:00
websocket_helper . broadcast_page ( ' /panel/dashboard ' , ' update_server_status ' , servers_ping )
2022-01-19 21:34:59 +01:00
websocket_helper . broadcast_page ( ' /status ' , ' update_server_status ' , servers_ping )
except :
console . warning ( " Can ' t broadcast server status to websocket " )
time . sleep ( 5 )
2021-03-05 11:35:05 +02:00
2021-03-05 11:30:18 +02:00
def log_watcher ( self ) :
2021-09-09 00:01:10 +02:00
self . controller . servers . check_for_old_logs ( )
2022-01-11 21:56:37 -05:00
self . scheduler . add_job ( self . controller . servers . check_for_old_logs , ' interval ' , hours = 6 , id = " log-mgmt " )
2021-03-21 23:32:48 -05:00