From 09ed6cc8c4b800702273e20f571a33bebcc85bd3 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 27 Mar 2024 11:57:07 -0500 Subject: [PATCH] Add site.Stop method (fix #35) --- site.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/site.go b/site.go index 042afa1..db97987 100644 --- a/site.go +++ b/site.go @@ -134,6 +134,25 @@ func (site *Site) Start() DeployError { return DeployError{} } +// Stop attempts to stop a Lapis server in the given repository. +func (site *Site) Stop() DeployError { + log.Printf("Stopping Lapis server %s...", site.getName()) + + old_cwd, _ := os.Getwd() + defer syscall.Chdir(old_cwd) + syscall.Chdir(configuration.sites_dir + "/" + site.name) + + cmd := exec.Command("lapis", "term") + if err := cmd.Start(); err != nil { + return newDeployError(1, "stopSite", + fmt.Sprintf("Failed to stop Lapis server in '%s'", site.getName()), "") + } + go func() { + cmd.Wait() + }() + return DeployError{} +} + // Restart attempts to restart the Lapis server in the given repository. func (site *Site) Restart() DeployError { log.Printf("Restarting Lapis server in %s...", site.getName())