Exemplo n.º 1
0
func main() {
	caretakerd.Version = version
	caretakerd.PackageName = packageName

	defer panics.DefaultPanicHandler()
	app := app.NewAppFor(getExecutableType())

	err := app.Run(os.Args)
	if err != nil {
		os.Exit(1)
	}
}
Exemplo n.º 2
0
func (instance *Caretakerd) terminationNotificationHandler() {
	defer panics.DefaultPanicHandler()
	for {
		osSignal, channelReady := <-instance.signalChannel
		if channelReady {
			signal := values.Signal(osSignal.(syscall.Signal))
			instance.Logger().Log(logger.Debug, "Received shutdown signal: %v", signal)
			instance.Stop()
		} else {
			break
		}
	}
}
Exemplo n.º 3
0
// Run starts the RPC instance in the foreground.
// This means: This method is a blocking method.
func (instance *RPC) Run() {
	defer panics.DefaultPanicHandler()
	container := restful.NewContainer()

	ws := new(restful.WebService)
	ws.Produces(restful.MIME_JSON)

	ws.Route(ws.GET("/config").To(instance.config))

	ws.Route(ws.GET("/control/config").To(instance.controlConfig))

	ws.Route(ws.GET("/services").To(instance.services))

	ws.Route(ws.GET("/service/{serviceName}").To(instance.service))
	ws.Route(ws.GET("/service/{serviceName}/config").To(instance.serviceConfig))
	ws.Route(ws.GET("/service/{serviceName}/state").To(instance.serviceStatus))
	ws.Route(ws.GET("/service/{serviceName}/pid").To(instance.servicePid))

	ws.Route(ws.POST("/service/{serviceName}/start").To(instance.serviceStart))
	ws.Route(ws.POST("/service/{serviceName}/restart").To(instance.serviceRestart))
	ws.Route(ws.POST("/service/{serviceName}/status").To(instance.serviceStart))
	ws.Route(ws.POST("/service/{serviceName}/stop").To(instance.serviceStop))
	ws.Route(ws.POST("/service/{serviceName}/kill").To(instance.serviceKill))
	ws.Route(ws.POST("/service/{serviceName}/signal").To(instance.serviceSignal))

	container.Add(ws)

	server := &http.Server{
		Handler:  container,
		ErrorLog: log.New(instance.logger.NewOutputStreamWrapperFor(logger.Debug), "", 0),
	}
	instance.logger.Log(logger.Debug, "Rpc will bind to %v...", instance.conf.Listen)
	listener, err := net.Listen(instance.conf.Listen.AsScheme(), instance.conf.Listen.AsAddress())
	if err != nil {
		log.Fatal(err)
	}
	sl, err2 := NewStoppableListener(listener)
	if err2 != nil {
		panics.New("Could not create listener.").CausedBy(err2).Throw()
	}
	defer func() {
		(*instance).listener = nil
	}()
	(*instance).listener = sl
	if err := server.Serve(instance.secure(sl)); err != nil {
		if _, ok := err.(ListenerStoppedError); !ok {
			panics.New("Could not listen.").CausedBy(err2).Throw()
		}
	}
}