Can now set custom config path flag when starting daemon

This commit is contained in:
2026-06-05 20:58:50 -05:00
parent 82029bf143
commit 17117e2376
4 changed files with 82 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
@@ -28,6 +29,10 @@ func PrepareInstanceConfig(templateVersion string, instanceConfigPath string, op
func SyncInstanceConfig(templateVersion string, instanceConfigPath string, options VsServerConfigOptions, cfg *AppConfig) error {
templatePath := filepath.Join(cfg.Storage.ConfigTemplatesDir, templateVersion, "serverconfig.json")
if err := ensureTemplateExists(templateVersion, templatePath, cfg); err != nil {
return fmt.Errorf("failed ensuring configuration template availability: %w", err)
}
if _, err := os.Stat(instanceConfigPath); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(instanceConfigPath), 0755); err != nil {
return fmt.Errorf("failed creating instance directory tree: %w", err)
@@ -91,3 +96,43 @@ func SyncInstanceConfig(templateVersion string, instanceConfigPath string, optio
return os.WriteFile(instanceConfigPath, updatedData, 0644)
}
func ensureTemplateExists(version string, targetPath string, cfg *AppConfig) error {
if _, err := os.Stat(targetPath); err == nil {
return nil
}
fmt.Printf("Template for version %s not found locally. Fetching remote layout from git server...\n", version)
if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
return fmt.Errorf("failed to create local template cache directory: %w", err)
}
remoteURL := fmt.Sprintf("https://git.bellsworne.tech/chrisbell/vssm_config_templates/raw/branch/main/%s/serverconfig.json", version)
resp, err := http.Get(remoteURL)
if err != nil {
return fmt.Errorf("network error attempting to pull config template: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("version template '%s' does not exist in the remote git repository asset tree", version)
} else if resp.StatusCode != http.StatusOK {
return fmt.Errorf("remote git mirror returned unexpected HTTP status: %s", resp.Status)
}
out, err := os.Create(targetPath)
if err != nil {
return fmt.Errorf("failed creating cache file hook on system storage: %w", err)
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
if err != nil {
return fmt.Errorf("failed stream-writing network payload cache frame to disk: %w", err)
}
fmt.Printf("Successfully cached configuration layout template for version %s\n", version)
return nil
}