Skip to content

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

Merged
yxieca merged 4 commits intosonic-net:masterfrom
daall:core_cleanup
Sep 13, 2019
Merged

[cron.d] Add cron job to periodically clean-up core files#3449
yxieca merged 4 commits intosonic-net:masterfrom
daall:core_cleanup

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 ([email protected])

- 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 <[email protected]>
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.

@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 <[email protected]>

* 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