Rename servers -> sites (startAllServers -> startAllSites)

This commit is contained in:
Noah 2024-03-10 22:10:00 -05:00
parent a20a44dd17
commit 8c52e842b0
2 changed files with 15 additions and 14 deletions

View File

@ -32,7 +32,7 @@ func handler(data map[string]interface{}) {
deploy_error.SendOverMatrix() deploy_error.SendOverMatrix()
return return
} }
deploy_error = restartServer(repository["name"].(string)) deploy_error = restartSite(repository["name"].(string))
if deploy_error.code != 0 { if deploy_error.code != 0 {
deploy_error.SendOverMatrix() deploy_error.SendOverMatrix()
return return
@ -65,7 +65,7 @@ func main() {
}) })
log.Printf("Starting Lapis Deploy on port %d...", configuration.port) 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 go initMatrix() // Start Matrix stuff in a goroutine
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", configuration.port), nil)) // Start HTTP server log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", configuration.port), nil)) // Start HTTP server
} }

25
site.go
View File

@ -12,18 +12,19 @@ import (
"github.com/gogs/git-module" "github.com/gogs/git-module"
) )
// startAllServers attempts to start every server in 'sites_dir' // startAllSites attempts to start every server in 'sites_dir'
func startAllServers(sites_dir string) DeployError { func startAllSites() DeployError {
sites_dir := configuration.sites_dir
files, err := os.ReadDir(sites_dir) files, err := os.ReadDir(sites_dir)
if err != nil { if err != nil {
return newDeployError(1, "startAllServers", return newDeployError(1, "startAllSites",
fmt.Sprintf("Failed to read sites from '%s'", sites_dir), fmt.Sprint(err)) fmt.Sprintf("Failed to read sites from '%s'", sites_dir), fmt.Sprint(err))
} }
for _, file := range files { for _, file := range files {
if !file.IsDir() { if !file.IsDir() {
continue continue
} }
err := startServer(file.Name()) err := startSite(file.Name())
if err.code != 0 { if err.code != 0 {
return err return err
} }
@ -32,8 +33,8 @@ func startAllServers(sites_dir string) DeployError {
return DeployError{} return DeployError{}
} }
// startServer attempts to start a Lapis server in the given repository. // startSite attempts to start a Lapis server in the given repository.
func startServer(name string) DeployError { func startSite(name string) DeployError {
log.Printf("Starting Lapis server in repository %s...", name) log.Printf("Starting Lapis server in repository %s...", name)
old_cwd, _ := os.Getwd() old_cwd, _ := os.Getwd()
@ -42,7 +43,7 @@ func startServer(name string) DeployError {
cmd := exec.Command("lapis", "serve") cmd := exec.Command("lapis", "serve")
if err := cmd.Start(); err != nil { 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() { go func() {
cmd.Wait() cmd.Wait()
@ -51,8 +52,8 @@ func startServer(name string) DeployError {
return DeployError{} return DeployError{}
} }
// restartServer attempts to restart the Lapis server in the given repository. // restartSite attempts to restart the Lapis server in the given repository.
func restartServer(name string) DeployError { func restartSite(name string) DeployError {
log.Printf("Restarting Lapis server on repository %s...", name) log.Printf("Restarting Lapis server on repository %s...", name)
old_cwd, _ := os.Getwd() old_cwd, _ := os.Getwd()
@ -61,11 +62,11 @@ func restartServer(name string) DeployError {
out, err := exec.Command("lapis", "build").CombinedOutput() out, err := exec.Command("lapis", "build").CombinedOutput()
if err != nil { 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) log.Printf("[lapis build] %s", out)
if !strings.Contains(string(out), "HUP") { 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{} return DeployError{}
} }
@ -82,7 +83,7 @@ func pullRepo(url string, name string) DeployError {
if err = git.Clone(url, configuration.sites_dir+"/"+name); err != nil { if err = git.Clone(url, configuration.sites_dir+"/"+name); err != nil {
return newDeployError(1, "pullRepo", fmt.Sprintf("Failed to pull down repository '%s'", name), "") 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 return err
} }
} else { } else {