namespace Chronos.Server.Hosting;
/// What Chronos.Server was asked to do.
public enum ServerCommand
{
/// Run in the console (Docker, Linux, development).
Run,
/// Run under the Windows Service Control Manager (the command line the installed service uses).
Service,
InstallService,
UninstallService,
/// Probe /health of the local server and exit 0/1 (container health check).
HealthCheck,
Help,
}
/// Command-line switches of the server; anything else is passed on to the web host.
public sealed record ServerCommandLine(ServerCommand Command, IReadOnlyList HostArguments, string? Error)
{
public const string Usage = """
Chronos Server — time-lapse archive, uploads, jobs and rendering.
Usage: Chronos.Server [--service | --install-service | --uninstall-service | --healthcheck | --help]
(no switch) run in the console until Ctrl+C
--service run under the Windows Service Control Manager
--install-service register the "ChronosServer" Windows service (automatic start, LocalSystem)
--uninstall-service stop and remove the Windows service
--healthcheck exit 0 when the local server answers /health, 1 otherwise
Configuration: /data/server.json (CHRONOS_DATA_PATH) overridden by environment variables:
CHRONOS_ARCHIVE_PATH CHRONOS_DATA_PATH CHRONOS_SERVER_NAME CHRONOS_ADMIN_USER CHRONOS_ADMIN_PASSWORD
CHRONOS_DB (postgres | sqlite | connection string) CHRONOS_DB_HOST CHRONOS_DB_PORT CHRONOS_DB_NAME CHRONOS_DB_USER
CHRONOS_DB_PASSWORD CHRONOS_DB_SSLMODE CHRONOS_HTTP_PORT CHRONOS_HTTPS_PORT CHRONOS_TLS_MODE (auto | pem | proxy)
CHRONOS_TLS_CERT CHRONOS_TLS_KEY CHRONOS_LANG
CHRONOS_SPACE_PATH folder whose volume's free space the admin panel shows (default: the archive's); on
Unraid the share's array view (/mnt/user0/) mapped read-only to /space
CHRONOS_PARALLELISM photos the running job processes at once (jobs run one at a time; default: half the
cores); CHRONOS_WORKERS, its former name, still sets it
CHRONOS_PRIORITY_QUEUE a job of a higher level pauses the running one, which resumes afterwards (true | false)
CHRONOS_LOG_LEVEL least severe level of the log files and the console (Trace | Debug | Information |
Warning | Error | Critical | None; default Information)
CHRONOS_LOG_CONSOLE_LEVEL the console's own level (default: CHRONOS_LOG_LEVEL's)
CHRONOS_LOG_RETENTION_DAYS days log files are kept (default 14)
CHRONOS_LOG_MAX_FILE_MB size at which a log file continues in a numbered one (default 50; 0: no limit)
CHRONOS_LOG_MAX_TOTAL_MB size of all log files; beyond it the oldest are deleted (default 1024; 0: no limit)
CHRONOS_LOG_ROTATION a new log file every day or every hour, UTC (daily | hourly; default daily)
CHRONOS_AUDIT_RETENTION_DAYS days of audit log the audit-cleanup schedule keeps (default 0: forever)
CHRONOS_DIAGNOSTICS_LOG_MB MB from the end of each log file in the diagnostics zip (default 4)
CHRONOS_DISCOVERY LAN beacon (true | false); in a container it needs host networking
CHRONOS_PUBLIC_HTTP_PORT, CHRONOS_PUBLIC_HTTPS_PORT
ports clients reach when the container's ports are published as other host ports
(admin redirect to HTTPS, LAN beacon)
CHRONOS_TRUSTED_PROXIES proxy mode: addresses or networks (CIDR) whose X-Forwarded-* headers count
(default: loopback only; list a proxy in another container or on another machine)
Container image only: PUID, PGID (user and group the server runs as, owners of /data), TZ (time zone of the schedules)
""";
public static ServerCommandLine Parse(IReadOnlyList args)
{
var command = ServerCommand.Run;
var rest = new List();
string? error = null;
foreach (var arg in args)
{
ServerCommand? parsed = arg switch
{
"--service" => ServerCommand.Service,
"--install-service" => ServerCommand.InstallService,
"--uninstall-service" => ServerCommand.UninstallService,
"--healthcheck" => ServerCommand.HealthCheck,
"--help" or "-h" or "-?" or "/?" => ServerCommand.Help,
_ => null,
};
if (parsed is not { } switchCommand)
{
rest.Add(arg);
continue;
}
if (command != ServerCommand.Run && command != switchCommand) error = $"{arg} cannot be combined with another command switch.";
command = switchCommand;
}
return new ServerCommandLine(command, rest, error);
}
}