How to Check for Auto-Updates in ChocolateLMLite: Complete Configuration Guide
ChocolateLMLite automatically checks for updates every 24 hours by downloading version JSON from a remote endpoint and comparing it against the compiled CurrentVersion constant, displaying console notifications when newer releases are available.
ChocolateLMLite includes a built-in auto-update mechanism that helps server administrators stay current with the latest releases without manual intervention. This system runs silently in the background, respects configuration flags, and alerts users through the console interface when updates are detected. Understanding how to check for auto-updates in ChocolateLMLite ensures your deployment maintains optimal compatibility and security.
How the Auto-Update System Works
Configuration Flag
The auto-update behavior is controlled by the EnableAutoUpdateCheck boolean property defined in the YamlGeneral class within src/FileManager.cs. This setting defaults to true, meaning fresh installations automatically enable update checking unless explicitly disabled in the YAML configuration.
Scheduling Mechanism
In src/Program.cs, the method UpdateChecker.ScheduleRegularUpdates initiates immediately after the console monitor starts. This method launches a background Task that executes CheckForUpdates on startup, then enters a loop waiting TimeSpan.FromHours(24) between subsequent checks while monitoring a CancellationToken for graceful shutdown.
Version Fetching and Comparison
The CheckForUpdates method in src/UpdateChecker.cs performs the actual version validation:
- Creates a temporary
HttpClientto download JSON fromhttps://sabowl.sakura.ne.jp/api/chocolatelm/version.json(defined by theUpdateCheckUrlconstant) - Deserializes the payload using
System.Text.Jsonto extract theverfield - Compares the remote version against the compile-time constant
CurrentVersion(e.g.,"0.03")
User Notification
When the fetched version differs from CurrentVersion, the system invokes ConsoleMonitor.UpdateInfo to render a banner in the server console UI. Both update availability confirmations and "latest version" status messages are logged via MyLog for audit trails.
Configuring Auto-Update Checking
To enable or disable automatic update verification, modify your general.yaml configuration file:
# general.yaml
EnableAutoUpdateCheck: true # Set to false to disable auto-updates
The default value is true, so the check runs automatically on new installations unless explicitly disabled.
Manual Update Checking
For debugging or administrative purposes, you can trigger the update check manually from any part of the codebase:
// Trigger immediate update check
await UpdateChecker.CheckForUpdates(consoleMonitor);
This executes the same HTTP request and version comparison logic used by the scheduled background task.
Core Implementation Details
The scheduler implementation respects application lifecycle through a CancellationToken passed from the main program. When the server shuts down, the token triggers and the background task exits cleanly without hanging the process.
The core comparison logic validates the JSON structure before comparing versions:
public static async Task CheckForUpdates(ConsoleMonitor consoleMonitor)
{
const string CurrentVersion = "0.03";
const string UpdateCheckUrl = "https://sabowl.sakura.ne.jp/api/chocolatelm/version.json";
using var client = new HttpClient();
string json = await client.GetStringAsync(UpdateCheckUrl);
using var doc = JsonSerializer.Deserialize<JsonDocument>(json);
if (doc?.RootElement.TryGetProperty("ver", out var ver))
{
string latest = ver.GetString() ?? CurrentVersion;
if (latest != CurrentVersion)
{
consoleMonitor.UpdateInfo(
"Update Available",
$"New version {latest} (current: {CurrentVersion})"
);
}
}
}
Summary
- EnableAutoUpdateCheck in
YamlGeneral(src/FileManager.cs) controls whether the system checks for updates (defaults totrue) - UpdateChecker.ScheduleRegularUpdates in
src/Program.csinitiates a background task running every 24 hours viaTimeSpan.FromHours(24) - CheckForUpdates downloads version JSON from
https://sabowl.sakura.ne.jp/api/chocolatelm/version.jsonand compares against theCurrentVersionconstant - ConsoleMonitor.UpdateInfo displays update notifications in the server console UI when versions differ
- The mechanism uses
System.Text.Jsonfor deserialization and respectsCancellationTokenfor graceful shutdown
Frequently Asked Questions
How do I disable auto-updates in ChocolateLMLite?
Set EnableAutoUpdateCheck: false in your general.yaml configuration file. This prevents Program.cs from calling UpdateChecker.ScheduleRegularUpdates during server startup, effectively disabling all automatic version checking.
How often does ChocolateLMLite check for updates?
The system checks immediately on startup, then waits 24 hours between subsequent checks using Task.Delay(TimeSpan.FromHours(24)). This interval is hardcoded in the ScheduleRegularUpdates method and runs continuously until the application receives a shutdown signal through the CancellationToken.
Where does the version information come from?
The application fetches a JSON payload from https://sabowl.sakura.ne.jp/api/chocolatelm/version.json, which returns an object structured as { "ver": "0.xx" }. This remote endpoint is defined as the UpdateCheckUrl constant in src/UpdateChecker.cs and is queried using a temporary HttpClient instance.
What happens when ChocolateLMLite finds an available update?
When the fetched version string differs from the compiled CurrentVersion constant, the system invokes ConsoleMonitor.UpdateInfo to display a banner in the console interface and writes a notification entry via MyLog. The server continues running normally; the notification is informational only and does not trigger automatic downloads or service restarts.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →