From 4effc84ff7c3111626c90d1e71df0ce6eeb74b86 Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Mon, 23 Jan 2023 16:06:42 -0500 Subject: [PATCH 1/2] make log compression optional with `JULIA_PKG_SERVER_COMPRESS_LOGS` For some debugging and use cases this may be optional. For example, a user may prefer to use logrotate provided by the system. --- bin/run_server.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/run_server.jl b/bin/run_server.jl index 358934e..208e292 100755 --- a/bin/run_server.jl +++ b/bin/run_server.jl @@ -27,6 +27,8 @@ timestamp_logger(logger) = TransformerLogger(logger) do log merge(log, (; message = "[$(Dates.format(now(), date_format))] $(log.message)")) end +compress_logs = get(ENV, "JULIA_PKG_SERVER_COMPRESS_LOGS", "true") in ("True", "TRUE", "true") + # Keep 10 days of logs let fc = NFileCache(log_dir, 10*24, DiscardLRU(); predicate = x -> endswith(x, r"pkgserver\.log(\.gz)?")) global function postrotate(file) @@ -44,7 +46,7 @@ global_logger(TeeLogger( DatetimeRotatingFileLogger( log_dir, string(raw"yyyy-mm-dd-HH-\p\k\g\s\e\r\v\e\r.\l\o\g"); - rotation_callback = postrotate, + rotation_callback = compress_logs ? postrotate : identity, ), Logging.Info, ), From 8928155408ecf2a0e0ef86270beff393ff57227e Mon Sep 17 00:00:00 2001 From: Steve Kelly Date: Fri, 27 Jan 2023 17:51:08 -0500 Subject: [PATCH 2/2] make several settings in run_server.jl `const` --- bin/run_server.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/run_server.jl b/bin/run_server.jl index 208e292..eb975be 100755 --- a/bin/run_server.jl +++ b/bin/run_server.jl @@ -3,7 +3,7 @@ using PkgServer, Sockets, Logging, LoggingExtras, Dates, FilesystemDatastructure # Accept optional environment-based arguments # Eventually, do this via Pkg preferences -pkgserver = get(ENV, "JULIA_PKG_SERVER", "http://0.0.0.0:8000") +const pkgserver = get(ENV, "JULIA_PKG_SERVER", "http://0.0.0.0:8000") try m = match(r"(https?://)?(.+):(\d+)", pkgserver) global host = m.captures[2] @@ -14,9 +14,9 @@ catch global port = 8000 end -storage_root = get(ENV, "JULIA_PKG_SERVER_STORAGE_ROOT", "/tmp/pkgserver") -storage_servers = strip.(split(get(ENV, "JULIA_PKG_SERVER_STORAGE_SERVERS", "https://us-east.storage.juliahub.com,https://kr.storage.juliahub.com"), ",")) -log_dir = get(ENV, "JULIA_PKG_SERVER_LOGS_DIR", joinpath(storage_root, "logs")) +const storage_root = get(ENV, "JULIA_PKG_SERVER_STORAGE_ROOT", "/tmp/pkgserver") +const storage_servers = strip.(split(get(ENV, "JULIA_PKG_SERVER_STORAGE_SERVERS", "https://us-east.storage.juliahub.com,https://kr.storage.juliahub.com"), ",")) +const log_dir = get(ENV, "JULIA_PKG_SERVER_LOGS_DIR", joinpath(storage_root, "logs")) mkpath(storage_root) mkpath(log_dir) @@ -27,7 +27,7 @@ timestamp_logger(logger) = TransformerLogger(logger) do log merge(log, (; message = "[$(Dates.format(now(), date_format))] $(log.message)")) end -compress_logs = get(ENV, "JULIA_PKG_SERVER_COMPRESS_LOGS", "true") in ("True", "TRUE", "true") +const compress_logs = get(ENV, "JULIA_PKG_SERVER_COMPRESS_LOGS", "true") in ("True", "TRUE", "true") # Keep 10 days of logs let fc = NFileCache(log_dir, 10*24, DiscardLRU(); predicate = x -> endswith(x, r"pkgserver\.log(\.gz)?"))