never open a socket with zood
This commit is contained in:
parent
022e411f48
commit
1d7b1efa27
88
http.go
88
http.go
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||
// Use of this source code is governed by the GPL 3.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/lib/protobuf/httppb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// remove '?' part and trailing '/'
|
||||
func cleanURL(url string) string {
|
||||
url = "/" + strings.Trim(url, "/")
|
||||
return url
|
||||
}
|
||||
|
||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Info("Got URL Path: ", r.URL.Path)
|
||||
route := cleanURL(r.URL.Path)
|
||||
|
||||
domname := r.URL.Query().Get("domain")
|
||||
flag := r.URL.Query().Get("flag")
|
||||
|
||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||
if err != nil {
|
||||
fmt.Fprintln(w, "ReadAll() error =", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("Got URL msg:", string(msg))
|
||||
if route == "/" {
|
||||
fmt.Fprintln(w, "OK")
|
||||
return
|
||||
}
|
||||
|
||||
// exit the virtigo daemon & have systemd restart it
|
||||
// this can happen & when it does, access to
|
||||
// to libvirtd will hang (aka: virsh list will hang)
|
||||
// One way to trigger this is to not properly close
|
||||
// domain sockets opened from go-qemu/hypervisor
|
||||
// it's a good idea in any case so leave it here
|
||||
if route == "/kill" {
|
||||
log.Warn("KILLED")
|
||||
fmt.Fprintln(w, "KILLED")
|
||||
os.Exit(-1)
|
||||
return
|
||||
}
|
||||
|
||||
// curl http://localhost:2520/import?domain=foo.bar.com
|
||||
if route == "/import" {
|
||||
fmt.Fprint(w, "import domain:", domname)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// toggle logging flags
|
||||
if route == "/flag" {
|
||||
log.HttpMode(w)
|
||||
defer log.HttpMode(nil)
|
||||
log.Info("going to toggle flag:", flag)
|
||||
switch flag {
|
||||
case "PING":
|
||||
if PING.Enabled() {
|
||||
log.Log(NOW, "toogle PING false")
|
||||
PING.SetBool(false)
|
||||
} else {
|
||||
log.Log(NOW, "toogle PING true")
|
||||
PING.SetBool(true)
|
||||
}
|
||||
default:
|
||||
log.Info("unknown looging flag:", flag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if route == "/favicon.ico" {
|
||||
httppb.WriteFile(w, resources, "ipv6.png")
|
||||
return
|
||||
}
|
||||
|
||||
log.Warn("BAD URL =", route)
|
||||
}
|
8
main.go
8
main.go
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/lib/protobuf/httppb"
|
||||
"go.wit.com/lib/protobuf/zoopb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
@ -48,10 +47,5 @@ func main() {
|
|||
me.forge = forgepb.InitPB()
|
||||
me.machine = zoopb.InitMachine()
|
||||
|
||||
go NewWatchdog()
|
||||
|
||||
err := httppb.StartHTTP(okHandler, argv.Port)
|
||||
if err != nil {
|
||||
log.Info("StartHTTP() err =", err)
|
||||
}
|
||||
zood() // talks to zookeeper
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func TimeFunction(f func()) time.Duration {
|
|||
return time.Since(startTime) // Calculate the elapsed time
|
||||
}
|
||||
|
||||
func NewWatchdog() {
|
||||
func zood() {
|
||||
me.dog = time.NewTicker(me.pollDelay)
|
||||
defer me.dog.Stop()
|
||||
done := make(chan bool)
|
||||
|
|
Loading…
Reference in New Issue