namespace Titano.Server.Hosting;
/// What Titano.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 = """
Titano Server — time-lapse archive, uploads, jobs and rendering.
Usage: Titano.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 "TitanoServer" 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 (TITANO_DATA_PATH) overridden by environment variables:
TITANO_ARCHIVE_PATH TITANO_DATA_PATH TITANO_SERVER_NAME TITANO_ADMIN_USER TITANO_ADMIN_PASSWORD
TITANO_DB (postgres | sqlite | connection string) TITANO_DB_HOST TITANO_DB_PORT TITANO_DB_NAME TITANO_DB_USER
TITANO_DB_PASSWORD TITANO_DB_SSLMODE TITANO_HTTP_PORT TITANO_HTTPS_PORT TITANO_TLS_MODE (auto | pem | proxy)
TITANO_TLS_CERT TITANO_TLS_KEY TITANO_LANG TITANO_WORKERS
TITANO_LOG_LEVEL (Trace | Debug | Information | Warning | Error)
TITANO_DISCOVERY LAN beacon (true | false); in a container it needs host networking
TITANO_PUBLIC_HTTP_PORT, TITANO_PUBLIC_HTTPS_PORT
ports clients reach when the container's ports are published as other host ports
(admin redirect to HTTPS, LAN beacon)
TITANO_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 (local time zone)
""";
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);
}
}