From 8c52e842b0bba66b280703daf7cf2d7dbb879301 Mon Sep 17 00:00:00 2001 From: Noah Date: Sun, 10 Mar 2024 22:10:00 -0500 Subject: [PATCH] Rename servers -> sites (startAllServers -> startAllSites) --- main.go | 4 ++-- site.go | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 73f82c9..e6e48dc 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ func handler(data map[string]interface{}) { deploy_error.SendOverMatrix() return } - deploy_error = restartServer(repository["name"].(string)) + deploy_error = restartSite(repository["name"].(string)) if deploy_error.code != 0 { deploy_error.SendOverMatrix() return @@ -65,7 +65,7 @@ func main() { }) log.Printf("Starting Lapis Deploy on port %d...", configuration.port) - startAllServers(configuration.sites_dir) // Start all the servers + startAllSites() // Start all the servers go initMatrix() // Start Matrix stuff in a goroutine log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", configuration.port), nil)) // Start HTTP server } diff --git a/site.go b/site.go index e451213..8df88b5 100644 --- a/site.go +++ b/site.go @@ -12,18 +12,19 @@ import ( "github.com/gogs/git-module" ) -// startAllServers attempts to start every server in 'sites_dir' -func startAllServers(sites_dir string) DeployError { +// startAllSites attempts to start every server in 'sites_dir' +func startAllSites() DeployError { + sites_dir := configuration.sites_dir files, err := os.ReadDir(sites_dir) if err != nil { - return newDeployError(1, "startAllServers", + return newDeployError(1, "startAllSites", fmt.Sprintf("Failed to read sites from '%s'", sites_dir), fmt.Sprint(err)) } for _, file := range files { if !file.IsDir() { continue } - err := startServer(file.Name()) + err := startSite(file.Name()) if err.code != 0 { return err } @@ -32,8 +33,8 @@ func startAllServers(sites_dir string) DeployError { return DeployError{} } -// startServer attempts to start a Lapis server in the given repository. -func startServer(name string) DeployError { +// startSite attempts to start a Lapis server in the given repository. +func startSite(name string) DeployError { log.Printf("Starting Lapis server in repository %s...", name) old_cwd, _ := os.Getwd() @@ -42,7 +43,7 @@ func startServer(name string) DeployError { cmd := exec.Command("lapis", "serve") if err := cmd.Start(); err != nil { - return newDeployError(1, "startServer", fmt.Sprintf("Failed to start Lapis server in repository '%s'", name), "") + return newDeployError(1, "startSite", fmt.Sprintf("Failed to start Lapis server in repository '%s'", name), "") } go func() { cmd.Wait() @@ -51,8 +52,8 @@ func startServer(name string) DeployError { return DeployError{} } -// restartServer attempts to restart the Lapis server in the given repository. -func restartServer(name string) DeployError { +// restartSite attempts to restart the Lapis server in the given repository. +func restartSite(name string) DeployError { log.Printf("Restarting Lapis server on repository %s...", name) old_cwd, _ := os.Getwd() @@ -61,11 +62,11 @@ func restartServer(name string) DeployError { out, err := exec.Command("lapis", "build").CombinedOutput() if err != nil { - return newDeployError(1, "restartServer", fmt.Sprintf("Failed to run 'lapis build' in repository '%s'", name), string(out)) + return newDeployError(1, "restartSite", fmt.Sprintf("Failed to run 'lapis build' in repository '%s'", name), string(out)) } log.Printf("[lapis build] %s", out) if !strings.Contains(string(out), "HUP") { - return newDeployError(1, "restartServer", "'lapis build' command returned unexpected value! (Lapis server not running?)", string(out)) + return newDeployError(1, "restartSite", "'lapis build' command returned unexpected value! (Lapis server not running?)", string(out)) } return DeployError{} } @@ -82,7 +83,7 @@ func pullRepo(url string, name string) DeployError { if err = git.Clone(url, configuration.sites_dir+"/"+name); err != nil { return newDeployError(1, "pullRepo", fmt.Sprintf("Failed to pull down repository '%s'", name), "") } - if err := startServer(name); err.code != 0 { + if err := startSite(name); err.code != 0 { return err } } else {