diff options
| author | Jeff Carr <[email protected]> | 2024-11-18 07:49:34 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-18 07:49:34 -0600 | 
| commit | 82c559e6579f950b11e2fae1afc67660a14c0629 (patch) | |
| tree | 89e840591ed940de5226c15fc395e358f1c4ac26 | |
| parent | 0b78c1f2d15608a9f6ddfaa977ef0f44dab77073 (diff) | |
apt update triggersv0.0.4
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | http.go | 52 | ||||
| -rw-r--r-- | main.go | 2 | ||||
| -rw-r--r-- | structs.go | 16 | 
4 files changed, 74 insertions, 8 deletions
@@ -47,3 +47,15 @@ git-clone:  http-toogle-ZOOD:  	curl --silent http://localhost:8080/flag?flag=ZOOD + +http-list-machines: +	curl --silent http://localhost:8080/list + +http-set-zood-target: +	curl --silent "http://localhost:8080/target?package=zood&version=v0.0.8" + +http-upgrade-hpdev2.grid.wit.com: +	curl --silent "http://localhost:8080/upgrade?hostname=hpdev2.grid.wit.com" + +http-upgrade-mirrors.wit.com: +	curl --silent "http://localhost:8080/upgrade?hostname=mirrors.wit.com" @@ -22,6 +22,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  	hostname := r.URL.Query().Get("hostname")  	flag := r.URL.Query().Get("flag") +	packname := r.URL.Query().Get("package") +	version := r.URL.Query().Get("version")  	msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte  	if err != nil { @@ -42,9 +44,15 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  			return  		}  		log.Log(ZOOD, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname) +		b := me.upgrade[m.Hostname]  		switch updateMachine(m) {  		case "upgrade": -			fmt.Fprintln(w, "upgrade") +			if b { +				fmt.Fprintln(w, "apt update") +				me.upgrade[m.Hostname] = false +			} else { +				fmt.Fprintln(w, "upgrade") +			}  		default:  			fmt.Fprintln(w, "notsure")  		} @@ -70,6 +78,48 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  		return  	} +	// list out the machines and thier version of zood +	if route == "/list" { +		log.HttpMode(w) +		defer log.HttpMode(nil) +		loop := me.machines.SortByName() +		for loop.Scan() { +			m := loop.Machine() +			zood := m.FindPackageByName("zood") +			v := me.targets["zood"] // this is the target version +			if zood == nil { +				log.Info("machine", m.Hostname, "does not have zood installed") +			} else { +				log.Info("know about machine", m.Hostname, "zood version", zood.Version, "vs target version", v) +			} +		} +		return +	} + +	// save the config file +	if route == "/save" { +		// me.machines.SaveConfig() +		return +	} + +	// flag a package to attempt to upgrade +	if route == "/upgrade" { +		log.HttpMode(w) +		defer log.HttpMode(nil) +		me.upgrade[hostname] = true +		log.Log(NOW, "setting package ", packname, " to upgrade") +		return +	} + +	// set the target version for a package +	if route == "/target" { +		log.HttpMode(w) +		defer log.HttpMode(nil) +		me.targets[packname] = version +		log.Log(NOW, "setting package/version to ", packname, " ", version) +		return +	} +  	// toggle logging flags  	if route == "/flag" {  		log.HttpMode(w) @@ -48,6 +48,8 @@ func main() {  	me.hostname, _ = os.Hostname()  	me.pollDelay = 10 * time.Second  	me.machines = new(zoopb.Machines) +	me.targets =  make(map[string]string) // keep track of what versions the machines should be running +	me.upgrade =  make(map[string]bool) // used to trigger upgrade attempts  	go NewWatchdog() @@ -10,11 +10,13 @@ var me *stuff  // this app's variables  type stuff struct { -	hostname  string          // my fqdn dns zookeeper hostname -	pollDelay time.Duration   // how often to report our status -	dog       *time.Ticker    // the watchdog timer -	dogchan   chan bool       // can kill the watchdog -	distro    string          // debian,redhat,gentoo,macos,wincrap -	packages  *zoopb.Packages // installed packages and versions -	machines  *zoopb.Machines // every machine that has reported itself to the zookeeper +	hostname  string            // my fqdn dns zookeeper hostname +	pollDelay time.Duration     // how often to report our status +	dog       *time.Ticker      // the watchdog timer +	dogchan   chan bool         // can kill the watchdog +	distro    string            // debian,redhat,gentoo,macos,wincrap +	packages  *zoopb.Packages   // installed packages and versions +	machines  *zoopb.Machines   // every machine that has reported itself to the zookeeper +	targets   map[string]string // what versions the machines should be running +	upgrade   map[string]bool   // use this to trigger builds  }  | 
