Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cron.d] Add cron job to periodically clean-up core files #3449

Merged
merged 4 commits into from
Sep 13, 2019

Conversation

daall
Copy link
Contributor

@daall daall commented Sep 12, 2019

[cron.d] Add cron job to periodically clean-up core files

  • Create script to scan /var/core and clean-up older core files
  • Create cron job to run clean-up script

Signed-off-by: Danny Allen (daall@microsoft.com)

- What I did
I added a script to periodically clean-up old core files from the /var/core directory and installed it as a cron job in the image. The script is currently configured to keep the 4 newest core files per process in /var/core.

- How to verify it

  1. Build image with script and associated cron job
  2. Verify that after running the script only the 4 newest core files per process are still present in /var/core.
  3. Verify that there are syslog messages indicating the cron job is running on a 15 minute interval.

- Description for the changelog

Add cron job to periodically clean-up core files

- A picture of a cute animal (not mandatory but encouraged)
cute animal

* Create script to scan /var/core and clean-up older core files
* Create cron job to run clean-up script

Signed-off-by: Danny Allen <daall@microsoft.com>
core_files = [f for f in os.listdir(CORE_FILE_DIR) if os.path.isfile(os.path.join(CORE_FILE_DIR, f))]

core_files_by_process = defaultdict(list)
for f in core_files:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, should we have this as a generic infra so this can be used for cleanup other files also (old syslogs, swss.recs etc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! I'll take a look at it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea. Can we come back with another PR for that?

There are some specialty with core file handling, there are some persisted knowledge of core file name structure here. It is a bit hard to directly apply to log files.

But in general, I think we should have a more generic tool for other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think we should put some more thought into a more generic way of doing this. One possible idea is to provide different functions to process different types of files, but let's come back it later.

files/scripts/core_cleanup.py Outdated Show resolved Hide resolved
@daall daall requested a review from jleveque September 13, 2019 03:58
@yxieca yxieca merged commit 97c675c into sonic-net:master Sep 13, 2019
yxieca pushed a commit that referenced this pull request Sep 13, 2019
* [cron.d] Create cron job to periodically clean-up core files
* Create script to scan /var/core and clean-up older core files
* Create cron job to run clean-up script

Signed-off-by: Danny Allen <daall@microsoft.com>

* Update interval for running cron job

* Respond to feedback

* Change syslog id
@daall daall deleted the core_cleanup branch October 18, 2019 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants