Fixed bugs with --config flag

This commit is contained in:
2026-06-05 21:48:25 -05:00
parent 17117e2376
commit 53b9f30d50
4 changed files with 37 additions and 18 deletions

View File

@@ -30,18 +30,18 @@ Alongside this project, I am developing a seperate web-based dashboard that can
## Roadmap ## Roadmap
- [ ] Configuration - [ ] Configuration
- [ ] Custom configuration path (passed to the daemon with a flag `--config-path`) - [x] Custom configuration path (passed to the daemon with a flag `--config`)
- [ ] Custom application data path (*for templates, etc, and to be used as a base for the other config directories*) <!-- - [ ] Custom application data path (*for templates, etc, and to be used as a base for the other config directories*) -->
- [ ] Daemon listen port (kind of implemented, could be cleaner) - [ ] Daemon listen port (kind of implemented, could be cleaner)
- [x] Declarative Server configuration (Create servers in config) - [x] Declarative Server configuration (Create servers in config)
- [ ] Server management - [ ] Server management
- [x] Create servers - [x] Create servers
- [x] Automatic server binary downloading by version (*Caveat: This works BUT the configuration template downloader needs to be figured out, otherwise you have to manually add a template for each version before it can actually be ran*) - [x] Automatic server binary downloading by version
- [ ] Delete servers - [ ] Delete servers
- [x] Start/Stop servers - [x] Start/Stop servers
- [ ] Server configuration - [ ] Server configuration
- [ ] Download correct configuration template for version - [x] Download correct configuration template for version (see availible templates [here](https://git.bellsworne.tech/chrisbell/vssm_config_templates))
- [x] Version - [x] Version
- [x] Server Name - [x] Server Name
- [x] Port - [x] Port

View File

@@ -18,7 +18,7 @@ type AppConfig struct {
Daemon struct { Daemon struct {
ListenAddress string `json:"listen_address"` ListenAddress string `json:"listen_address"`
} } `json:"daemon"`
Instances map[string]VsServerConfigOptions `json:"instances"` Instances map[string]VsServerConfigOptions `json:"instances"`
} }

View File

@@ -6,7 +6,6 @@ import (
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"path/filepath"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@@ -25,12 +24,14 @@ type InstanceStatusResponse struct {
type DaemonServer struct { type DaemonServer struct {
cfg *AppConfig cfg *AppConfig
configPath string
procManager *ProcessManager procManager *ProcessManager
} }
func StartDaemon(cfg *AppConfig) error { func StartDaemon(cfg *AppConfig, configPath string) error {
ds := &DaemonServer{ ds := &DaemonServer{
cfg: cfg, cfg: cfg,
configPath: configPath,
procManager: NewProcessManager(), procManager: NewProcessManager(),
} }
@@ -173,10 +174,16 @@ func (ds *DaemonServer) handleCreate(w http.ResponseWriter, r *http.Request) {
ds.cfg.Instances[name] = options ds.cfg.Instances[name] = options
home, _ := os.UserHomeDir() data, err := json.MarshalIndent(ds.cfg, "", " ")
configPath := filepath.Join(home, ".config", "vs-manager", "config.json") if err != nil {
data, _ := json.MarshalIndent(ds.cfg, "", " ") http.Error(w, fmt.Sprintf("Failed processing profile adjustments: %v", err), http.StatusInternalServerError)
_ = os.WriteFile(configPath, data, 0644) return
}
if err := os.WriteFile(ds.configPath, data, 0644); err != nil {
http.Error(w, fmt.Sprintf("Failed saving configuration adjustments to disk: %v", err), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "Successfully created and stored profile for instance %s", name) fmt.Fprintf(w, "Successfully created and stored profile for instance %s", name)
@@ -200,7 +207,7 @@ func (ds *DaemonServer) handleStart(w http.ResponseWriter, r *http.Request) {
return return
} }
instanceConfigPath := filepath.Join(ds.cfg.Storage.InstancesDir, name, "serverconfig.json") instanceConfigPath := ds.configPath
err := SyncInstanceConfig(options.Version, instanceConfigPath, options, ds.cfg) err := SyncInstanceConfig(options.Version, instanceConfigPath, options, ds.cfg)
if err != nil { if err != nil {
http.Error(w, "Failed to sync config: "+err.Error(), http.StatusInternalServerError) http.Error(w, "Failed to sync config: "+err.Error(), http.StatusInternalServerError)

24
main.go
View File

@@ -33,7 +33,12 @@ func main() {
return return
} }
cfg, err := LoadOrCreateConfig(*configFlag) absConfigPath, err := filepath.Abs(*configFlag)
if err != nil {
log.Fatalf("Failed to resolve absolute configuration path target: %v", err)
}
cfg, err := LoadOrCreateConfig(absConfigPath)
if err != nil { if err != nil {
log.Fatalf("Initialization failed: %v", err) log.Fatalf("Initialization failed: %v", err)
} }
@@ -43,8 +48,8 @@ func main() {
switch subCommand { switch subCommand {
case "daemon": case "daemon":
fmt.Println("Initializing VS server manager background supervisor...") fmt.Printf("Initializing VS server manager background supervisor [Config: %s]...\n", absConfigPath)
if err := StartDaemon(cfg); err != nil { if err := StartDaemon(cfg, absConfigPath); err != nil {
log.Fatalf("Daemon runtime fatal error: %v", err) log.Fatalf("Daemon runtime fatal error: %v", err)
} }
@@ -71,7 +76,7 @@ func main() {
sendIPCRequest(cfg, "POST", fmt.Sprintf("/instances/stop?name=%s", url.QueryEscape(name)), nil) sendIPCRequest(cfg, "POST", fmt.Sprintf("/instances/stop?name=%s", url.QueryEscape(name)), nil)
case "cmd": case "cmd":
if len(args) < 4 { if len(args) < 3 {
log.Fatalf("Usage: vssm cmd <instance_name> \"<server command>\"") log.Fatalf("Usage: vssm cmd <instance_name> \"<server command>\"")
} }
name := args[1] name := args[1]
@@ -84,6 +89,9 @@ func main() {
case "list", "status": case "list", "status":
fetchAndPrintStatus(cfg) fetchAndPrintStatus(cfg)
case "show-config":
fmt.Printf("%v", cfg.Storage.AppDataDir)
default: default:
printUsage() printUsage()
} }
@@ -107,7 +115,8 @@ func sendIPCRequest(cfg *AppConfig, method string, path string, body io.Reader)
defer resp.Body.Close() defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body) respBody, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
log.Fatalf("Error from daemon: %s", string(respBody)) log.Fatalf("Error from daemon: %s", string(respBody))
} }
@@ -149,10 +158,13 @@ func fetchAndPrintStatus(cfg *AppConfig) {
func printUsage() { func printUsage() {
fmt.Println("VintageStory Server Manager") fmt.Println("VintageStory Server Manager")
fmt.Println("\nUsage:") fmt.Println("\nGlobal Options:")
fmt.Println(" --config <path> Explicitly target a non-default config structure file location")
fmt.Println("\nUsage Commands:")
fmt.Println(" vssm daemon Starts the background process supervisor") fmt.Println(" vssm daemon Starts the background process supervisor")
fmt.Println(" vssm create <name> <version> Provisions baseline configuration and stores instance profile") fmt.Println(" vssm create <name> <version> Provisions baseline configuration and stores instance profile")
fmt.Println(" vssm start <name> Launches an existing server instance using stored profile") fmt.Println(" vssm start <name> Launches an existing server instance using stored profile")
fmt.Println(" vssm stop <name> Gracefully shuts down a server instance") fmt.Println(" vssm stop <name> Gracefully shuts down a server instance")
fmt.Println(" vssm cmd <name> \"<command>\" Dispatches a terminal console command down the pipe") fmt.Println(" vssm cmd <name> \"<command>\" Dispatches a terminal console command down the pipe")
fmt.Println(" vssm list Displays the operational matrix of all instances")
} }