Giter Club home page Giter Club logo

go-supervisor's Introduction

Go Supervisor API Toolkit

API toolkit for Supervisor written in Go!

Event Listener

Listener implements a Supervisor event listener. The following code illustrates basic usage of the listener:

func main() {
	done := make(chan bool)
	events := make(chan supervisor.Event)
	evl := supervisor.NewListener(os.Stdin, os.Stdout)

	go func() {
		for event := range events {
			fmt.Fprintf(os.Stderr, "Got event: %s\n", event)
		}
		done <- true
	}()

	evl.Run(events)
	close(events)
	<-done
}

RPC Client

Client implements an HTML RPC client to communicate with Supervisor. The following code demonstrates using the client to start a service:

func main() {
	client, err := supervisor.NewClient("http://localhost:9001/RPC2")
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	}

	if result, err = client.StartProcess("nginx", true); err != nil {
		fmt.Printf("Error: %s\n", err)
		os.Exit(1)
	} else if !result {
		fmt.Printf("Failed to start process.\n")
	}

	fmt.Printf("Process started.\n")
}

Stateful Monitor

Monitor implements a stateful monitoring system. It maintains the current state of all processes and emits events when processes are added, removed, or change state. It will also emit events when the Supervisor instance changes state. It will also do a full state refresh on any TICK event it receives. For full functionality it requires the PROCESS_STATE, SUPERVISOR_STATE_CHANGE, and a TICK event. If the TICK event is removed then no events will be emitted for process removal.

As an example:

func main() {
	url := "http://localhost:9001/RPC2"
	events := make(chan interface{})
	mon, err := supervisor.NewMonitor(url, os.Stdin, os.Stdout, events)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		os.Exit(1)
	}

	done := make(chan bool)
	go func() {
		for event := range events {
			switch event.(type) {
			case supervisor.ProcessAddEvent:
				process := (event.(supervisor.ProcessAddEvent)).Process
				fmt.Fprintf(os.Stderr, "Process %s added\n", process.Name)
			case supervisor.ProcessRemoveEvent:
				process := (event.(supervisor.ProcessRemoveEvent)).Process
				fmt.Fprintf(os.Stderr, "Process %s added\n", process.Name)
			case supervisor.ProcessStateEvent:
				process := (event.(supervisor.ProcessStateEvent)).Process
				from := (event.(supervisor.ProcessStateEvent)).FromState
				fmt.Fprintf(os.Stderr, "Process %s state change %s => %s\n", process.Name, from, process.State)
			case supervisor.SupervisorStateEvent:
				supervisor := (event.(supervisor.SupervisorStateEvent)).Supervisor
				from := (event.(supervisor.SupervisorStateEvent)).FromState
				fmt.Fprintf(os.Stderr, "Supervisor \"%s\" state change %s => %s\n", supervisor.Name, from, supervisor.State)
			default:
				fmt.Fprintf(os.Stderr, "Unchecked Event: %+v\n", event)
			}
		}
		done <- true
	}()

	mon.Refresh()
	mon.Run()

	close(events)
	mon.Close()
	<- done
}

License

This software project is licensed under the BSD-derived license and is copyright (c) 2013 Ryan Bourgeois. A copy of the license is included in the LICENSE file. If it is missing a copy can be found on the project page.

go-supervisor's People

Contributors

rynbrd avatar

Stargazers

jamesge avatar Juca Da avatar  avatar  avatar  avatar Antoine Bluchet avatar Sergey Fedotov avatar 龙天 avatar Ilia Choly avatar 朱求志 avatar Abdul Latif Syafii avatar  avatar ddppqq avatar Daniel Filipe Bruehmueller Morinigo avatar Bill LeiHao avatar chennqqi avatar netxfly avatar Song Liu avatar Timothy avatar Z.X.PING avatar Changchun Chen avatar Mark Wu avatar Lucho Mayta avatar Pavel Odintsov avatar Wsk avatar  avatar 张诚@视频结构化 avatar Adrian Huang avatar Pete Morgan avatar Chaiwat S avatar  avatar Dmitri Muntean avatar Alex Padgett avatar Aaron Chen avatar Patrick McCarren avatar  avatar Ian Alexander Wood avatar Petr Stepchenko avatar Jian Wen avatar Gleicon Moraes avatar  avatar Samuel Stauffer avatar Silas Sewell avatar

Watchers

 avatar James Cloos avatar Zhou Yuanzhen avatar

go-supervisor's Issues

type not define in rpc.go

I have already update github.com/kolo/xmlrpc, but xmlrpc.Struct and xmlrpc.Params are still undefine in rpc.go, how can I fix this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.