Compare commits

..

2 Commits

Author SHA1 Message Date
852874a12a Add site stop chat command (fix #22) 2024-03-27 11:57:26 -05:00
09ed6cc8c4 Add site.Stop method (fix #35) 2024-03-27 11:57:07 -05:00
2 changed files with 38 additions and 0 deletions

View File

@ -150,6 +150,25 @@ func initMatrix() {
return text + "\n🟢 Successfully restarted site." return text + "\n🟢 Successfully restarted site."
}) })
registerChatCommand("stop", "Stop a site.", func(ctx context.Context, evt *event.Event, args []string) string {
if len(args) < 2 {
return "🔴 Invalid site."
}
site, found, err := getSite(args[1])
if err != nil {
return "🔴 Failed to get site " + args[2] + "!"
} else if !found {
return "🔴 Invalid site."
}
text := "⚪️ Stopping server..."
if derr := site.Stop(); derr.code != 0 {
derr.SendOverMatrix()
return text + "\n🔴 Failed to stop site!"
}
return text + "\n🟢 Successfully stopped site."
})
go func() { go func() {
for range time.Tick(time.Second * 6) { for range time.Tick(time.Second * 6) {
log.Printf("Scanning for queued messages...") log.Printf("Scanning for queued messages...")

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())