mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Merge branch 'remove-old-logs' into 'dev'
"remove old logs" feature See merge request crafty-controller/crafty-commander!21
This commit is contained in:
commit
abcb097cdb
@ -66,9 +66,28 @@ class Helpers:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
logger.error("{} does not exits".format(file))
|
||||
logger.error("{} does not exist".format(file))
|
||||
return True
|
||||
|
||||
def check_for_old_logs(self, db_helper):
|
||||
servers = db_helper.get_all_defined_servers()
|
||||
for server in servers:
|
||||
logs_path = os.path.split(server['log_path'])[0]
|
||||
latest_log_file = os.path.split(server['log_path'])[1]
|
||||
logs_delete_after = int(server['logs_delete_after'])
|
||||
if logs_delete_after == 0:
|
||||
continue
|
||||
|
||||
log_files = list(filter(
|
||||
lambda val: val != latest_log_file,
|
||||
os.listdir(logs_path)
|
||||
))
|
||||
for log_file in log_files:
|
||||
log_file_path = os.path.join(logs_path, log_file)
|
||||
if self.check_file_exists(log_file_path) and \
|
||||
self.is_file_older_than_x_days(log_file_path, logs_delete_after):
|
||||
os.remove(log_file_path)
|
||||
|
||||
def get_setting(self, key, default_return=False):
|
||||
|
||||
try:
|
||||
|
@ -105,6 +105,7 @@ class Servers(BaseModel):
|
||||
stop_command = CharField(default="stop")
|
||||
server_ip = CharField(default="127.0.0.1")
|
||||
server_port = IntegerField(default=25565)
|
||||
logs_delete_after = IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
table_name = "servers"
|
||||
|
@ -35,6 +35,9 @@ class TasksManager:
|
||||
|
||||
self.schedule_thread = threading.Thread(target=self.scheduler_thread, daemon=True, name="scheduler")
|
||||
|
||||
self.log_watcher_thread = threading.Thread(target=self.log_watcher, daemon=True, name="log_watcher")
|
||||
self.log_watcher_thread.start()
|
||||
|
||||
self.command_thread = threading.Thread(target=self.command_watcher, daemon=True, name="command_watcher")
|
||||
self.command_thread.start()
|
||||
|
||||
@ -133,5 +136,10 @@ class TasksManager:
|
||||
logger.info("Scheduling Serverjars.com cache refresh service every 12 hours")
|
||||
schedule.every(12).hours.do(server_jar_obj.refresh_cache)
|
||||
|
||||
def log_watcher(self):
|
||||
console.debug('in log_watcher')
|
||||
helper.check_for_old_logs(db_helper)
|
||||
schedule.every(6).hours.do(lambda: helper.check_for_old_logs(db_helper))
|
||||
|
||||
|
||||
tasks_manager = TasksManager()
|
||||
|
@ -297,6 +297,7 @@ class PanelHandler(BaseHandler):
|
||||
server_port = self.get_argument('server_port', None)
|
||||
auto_start = int(float(self.get_argument('auto_start', '0')))
|
||||
crash_detection = int(float(self.get_argument('crash_detection', '0')))
|
||||
logs_delete_after = int(float(self.get_argument('logs_delete_after', '0')))
|
||||
subpage = self.get_argument('subpage', None)
|
||||
|
||||
user_data = json.loads(self.get_secure_cookie("user_data"))
|
||||
@ -328,6 +329,7 @@ class PanelHandler(BaseHandler):
|
||||
Servers.server_port: server_port,
|
||||
Servers.auto_start: auto_start,
|
||||
Servers.crash_detection: crash_detection,
|
||||
Servers.logs_delete_after: logs_delete_after,
|
||||
}).where(Servers.server_id == server_id).execute()
|
||||
|
||||
controller.refresh_server_settings(server_id)
|
||||
|
@ -112,6 +112,11 @@
|
||||
<input type="number" class="form-control" name="server_port" id="server_port" value="{{ data['server_stats'][0]['server_id']['server_port'] }}" step="1" max="65566" min="1" >
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="logs_delete_after">Remove Old Logs After <small class="text-muted ml-1"> - How many days will a log file has to be old to get deleted (0 is off)</small> </label>
|
||||
<input type="number" class="form-control" name="logs_delete_after" id="logs_delete_after" value="{{ data['server_stats'][0]['server_id']['logs_delete_after'] }}" step="1" max="365" min="0" >
|
||||
</div>
|
||||
|
||||
<div class="form-check-flat">
|
||||
<label for="auto_start" class="form-check-label ml-4 mb-4">
|
||||
{% if data['server_stats'][0]['server_id']['auto_start'] %}
|
||||
|
Loading…
Reference in New Issue
Block a user