factor out restart-logic

This commit is contained in:
Jonas Große Sundrup 2023-12-29 23:33:47 +01:00
parent ba1798ce46
commit 4a880b781d
No known key found for this signature in database
GPG key ID: 5B587ADC0531D442

28
main.go
View file

@ -88,19 +88,8 @@ func main() {
}
handleRequest(conn)
// Restart xochitl
if *restart {
services := []string{"xochitl", "remux", "tarnish", "draft"}
for _, service := range services {
_, exitcode := exec.Command("systemctl", "is-active", service).CombinedOutput()
if exitcode == nil {
debug("Restarting " + service)
stdout, err := exec.Command("systemctl", "restart", service).CombinedOutput()
if err != nil {
fmt.Println(service+" restart failed with message:", string(stdout))
}
}
}
restartUISoftware()
}
if isSocketActivated {
@ -198,3 +187,18 @@ func handleRequest(conn net.Conn) {
conn.Close()
}
// Restarts xochitl or other UI software
func restartUISoftware() {
services := []string{"xochitl", "remux", "tarnish", "draft"}
for _, service := range services {
_, exitcode := exec.Command("systemctl", "is-active", service).CombinedOutput()
if exitcode == nil {
debug("Restarting " + service)
stdout, err := exec.Command("systemctl", "restart", service).CombinedOutput()
if err != nil {
fmt.Println(service+" restart failed with message:", string(stdout))
}
}
}
}