From b920b82f4ee4d5112ceb82cd8986601dea1b6241 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sun, 7 Jan 2024 22:14:27 +0100 Subject: [PATCH 1/2] Add basic-space-cleanup command --- share/actionsmap.yml | 4 ++++ src/tools.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/share/actionsmap.yml b/share/actionsmap.yml index 9382c70f3..a98653551 100644 --- a/share/actionsmap.yml +++ b/share/actionsmap.yml @@ -1739,6 +1739,10 @@ tools: help: python command to execute full: --command + ### tools_basic_space_cleanup() + basic-space-cleanup: + action_help: Basic space cleanup (apt, journalctl, logs, ...) + ### tools_shutdown() shutdown: action_help: Shutdown the server diff --git a/src/tools.py b/src/tools.py index 088400067..a2fd9d82e 100644 --- a/src/tools.py +++ b/src/tools.py @@ -623,6 +623,36 @@ def tools_shell(command=None): shell = code.InteractiveConsole(vars) shell.interact() +def tools_basic_space_cleanup(): + """ + Basic space cleanup. + + apt autoremove + apt clean + archived logs removal + journalctl vacuum (leaves 50M of logs) + """ + subprocess.run( + [ + "/bin/bash", + "-c", + "apt autoremove && apt autoclean", + ] + ) + subprocess.run( + [ + "/bin/bash", + "-c", + "journalctl --vacuum-size=50M", + ] + ) + subprocess.run( + [ + "/bin/bash", + "-c", + "rm /var/log/*.gz && rm /var/log/*/*.gz && rm /var/log/*.? && rm /var/log/*/*.?", + ] + ) # ############################################ # # # From 8ca59703c5c6b5975a3a90387f939a80bbf2d736 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 13 Jan 2024 12:11:05 +0100 Subject: [PATCH 2/2] Improve basic-space-cleanup shell calls and documentation --- src/tools.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/tools.py b/src/tools.py index a2fd9d82e..cd415c5a3 100644 --- a/src/tools.py +++ b/src/tools.py @@ -628,31 +628,13 @@ def tools_basic_space_cleanup(): Basic space cleanup. apt autoremove - apt clean - archived logs removal + apt autoclean journalctl vacuum (leaves 50M of logs) + archived logs removal """ - subprocess.run( - [ - "/bin/bash", - "-c", - "apt autoremove && apt autoclean", - ] - ) - subprocess.run( - [ - "/bin/bash", - "-c", - "journalctl --vacuum-size=50M", - ] - ) - subprocess.run( - [ - "/bin/bash", - "-c", - "rm /var/log/*.gz && rm /var/log/*/*.gz && rm /var/log/*.? && rm /var/log/*/*.?", - ] - ) + subprocess.run("apt autoremove && apt autoclean", shell=True) + subprocess.run("journalctl --vacuum-size=50M", shell=True) + subprocess.run("rm /var/log/*.gz && rm /var/log/*/*.gz && rm /var/log/*.? && rm /var/log/*/*.?", shell=True) # ############################################ # # #