Files
ubicloud/rhizome/host/bin/delete-old-serial-logs
Jeremy Evans e59d71e2f6 Restore Ruby 3.2 syntax to rhizome
Ubuntu 22.04 VmHosts use Ruby 3.0, and Ubunutu 24.04 use Ruby 3.2,
so 3.4 syntax would break either.  This was theoretically an issue
before, but I'm guessing there were no significant syntax changes
between 3.0 and 3.2 that Rubocop's rewriting would break.

This commits a rhizome/.rubocop.yml file that inherits the default
configuration, and overrides TargetRubyVersion.
2025-04-26 08:34:47 +09:00

25 lines
740 B
Ruby
Executable File

#!/bin/env ruby
# frozen_string_literal: true
require "fileutils"
directory_path = "/var/log/ubicloud/serials"
# Delete files older than 1 day
Dir.glob(File.join(directory_path, "*")).each do |file|
next unless File.file?(file) # Skip directories
file_age_in_hours = (Time.now - File.mtime(file)) / 3600
FileUtils.rm(file) if file_age_in_hours > 24
end
# Reduce the directory size to less than 1GB
files_with_sizes = Dir.glob(File.join(directory_path, "*"))
.select { File.file?(_1) }
.map { {file: _1, size: File.size(_1)} }
.sort_by { _1[:size] }
while files_with_sizes.sum { _1[:size] } > 1 * 1024 * 1024 * 1024 # 1GB in bytes
break unless (largest_file = files_with_sizes.pop)
FileUtils.rm(largest_file[:file])
end