Add site.Stop method (fix #35)

This commit is contained in:
Noah 2024-03-27 11:57:07 -05:00
parent ba71b42369
commit 09ed6cc8c4

19
site.go
View File

@ -134,6 +134,25 @@ func (site *Site) Start() DeployError {
return 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. // Restart attempts to restart the Lapis server in the given repository.
func (site *Site) Restart() DeployError { func (site *Site) Restart() DeployError {
log.Printf("Restarting Lapis server in %s...", site.getName()) log.Printf("Restarting Lapis server in %s...", site.getName())