Fixed IPC calls in main to use new ip and port seperation in the config
This commit is contained in:
@@ -18,23 +18,23 @@ type AppConfig struct {
|
|||||||
|
|
||||||
Daemon struct {
|
Daemon struct {
|
||||||
ListenAddress string `json:"listen_address"`
|
ListenAddress string `json:"listen_address"`
|
||||||
|
Port int `json:"port"`
|
||||||
} `json:"daemon"`
|
} `json:"daemon"`
|
||||||
|
|
||||||
Instances map[string]InstanceMetadata `json:"instances"`
|
Instances map[string]InstanceMetadata `json:"instances"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateConfigWithDefaults(configPath string) *AppConfig {
|
func CreateConfigWithDefaults(configPath string) *AppConfig {
|
||||||
home, _ := os.UserHomeDir()
|
basePath := filepath.Join(filepath.Dir(configPath), "vssm_data")
|
||||||
basePath := filepath.Join(home, ".local", "share", "vssm")
|
|
||||||
|
|
||||||
cfg := &AppConfig{}
|
cfg := &AppConfig{}
|
||||||
cfg.Storage.AppDataDir = basePath
|
|
||||||
cfg.Storage.InstallDir = filepath.Join(basePath, "installs")
|
cfg.Storage.InstallDir = filepath.Join(basePath, "installs")
|
||||||
cfg.Storage.InstancesDir = filepath.Join(basePath, "instances")
|
cfg.Storage.InstancesDir = filepath.Join(basePath, "instances")
|
||||||
cfg.Storage.BackupDir = filepath.Join(basePath, "backups")
|
cfg.Storage.BackupDir = filepath.Join(basePath, "backups")
|
||||||
cfg.Storage.ConfigTemplatesDir = filepath.Join(basePath, "config_templates")
|
cfg.Storage.ConfigTemplatesDir = filepath.Join(basePath, "config_templates")
|
||||||
|
|
||||||
cfg.Daemon.ListenAddress = "127.0.0.1:12345"
|
cfg.Daemon.ListenAddress = "127.0.0.1"
|
||||||
|
cfg.Daemon.Port = 65000
|
||||||
|
|
||||||
cfg.Instances = make(map[string]InstanceMetadata)
|
cfg.Instances = make(map[string]InstanceMetadata)
|
||||||
|
|
||||||
@@ -70,7 +70,6 @@ func LoadOrCreateConfig(configPath string) (*AppConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirs := []string{
|
dirs := []string{
|
||||||
cfg.Storage.AppDataDir,
|
|
||||||
cfg.Storage.InstallDir,
|
cfg.Storage.InstallDir,
|
||||||
cfg.Storage.InstancesDir,
|
cfg.Storage.InstancesDir,
|
||||||
cfg.Storage.BackupDir,
|
cfg.Storage.BackupDir,
|
||||||
|
|||||||
@@ -60,8 +60,10 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
|||||||
mux.ServeHTTP(w, r)
|
mux.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
listenAddress := cfg.Daemon.ListenAddress + ":" + strconv.Itoa(cfg.Daemon.Port)
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: cfg.Daemon.ListenAddress,
|
Addr: listenAddress,
|
||||||
Handler: corsWrappedHandler,
|
Handler: corsWrappedHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ func StartDaemon(cfg *AppConfig, configPath string) error {
|
|||||||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Printf("Engine daemon actively listening on http://%s\n", cfg.Daemon.ListenAddress)
|
fmt.Printf("Engine daemon actively listening on http://%s\n", listenAddress)
|
||||||
if err := server.ListenAndServe(); err != http.ErrServerClosed {
|
if err := server.ListenAndServe(); err != http.ErrServerClosed {
|
||||||
fmt.Printf("Daemon runtime failure: %v\n", err)
|
fmt.Printf("Daemon runtime failure: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -63,6 +63,9 @@ func main() {
|
|||||||
log.Fatalf("Initialization failed: %v", err)
|
log.Fatalf("Initialization failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listenAddress := cfg.Daemon.ListenAddress + ":" + strconv.Itoa(cfg.Daemon.Port)
|
||||||
|
fmt.Printf("Got listen address from config: %s\n", listenAddress)
|
||||||
|
|
||||||
subCommand := args[0]
|
subCommand := args[0]
|
||||||
|
|
||||||
switch subCommand {
|
switch subCommand {
|
||||||
@@ -132,7 +135,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendIPCRequest(cfg *AppConfig, method string, path string, body io.Reader) {
|
func sendIPCRequest(cfg *AppConfig, method string, path string, body io.Reader) {
|
||||||
targetUrl := fmt.Sprintf("http://%s%s", cfg.Daemon.ListenAddress, path)
|
listenAddress := cfg.Daemon.ListenAddress + ":" + strconv.Itoa(cfg.Daemon.Port)
|
||||||
|
targetUrl := fmt.Sprintf("http://%s%s", listenAddress, path)
|
||||||
|
fmt.Printf("Listen Addr: %s; Target URL: %s\n", listenAddress, targetUrl)
|
||||||
req, err := http.NewRequest(method, targetUrl, body)
|
req, err := http.NewRequest(method, targetUrl, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to construct IPC frame: %v", err)
|
log.Fatalf("Failed to construct IPC frame: %v", err)
|
||||||
@@ -158,7 +163,8 @@ func sendIPCRequest(cfg *AppConfig, method string, path string, body io.Reader)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchAndPrintStatus(cfg *AppConfig) {
|
func fetchAndPrintStatus(cfg *AppConfig) {
|
||||||
targetUrl := fmt.Sprintf("http://%s/instances/list", cfg.Daemon.ListenAddress)
|
listenAddress := cfg.Daemon.ListenAddress + ":" + strconv.Itoa(cfg.Daemon.Port)
|
||||||
|
targetUrl := fmt.Sprintf("http://%s/instances/list", listenAddress)
|
||||||
resp, err := http.Get(targetUrl)
|
resp, err := http.Get(targetUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("IPC connection failed. Is the vs-manager daemon running? Error: %v", err)
|
log.Fatalf("IPC connection failed. Is the vs-manager daemon running? Error: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user