func (s *Service) newExec(lastStart time.Time) *execution.Execution {
	for {
		delta := time.Until(lastStart.Add(RespawnDelay))
		if delta > 0 {
			t := time.NewTimer(delta)
			select {
			case <-s.stop:
				t.Stop()
				return nil
			case <-t.C:
			}
		}
		exec, err := execution.New(s.name, s.cfg, s.sc)
		if err == nil {
			return exec
		}
		lastStart = time.Now()
		log.Errorf("Execution of service [%s] failed, retrying: %v", s.name, err)
	}
}
newExec creates a new execution. It retries on failure, giving up only
if stop is closed, in which case it returns nil.
package daemonservice
import (
	"context"
	"fmt"
	"sync"
	"time"
	log "github.com/golang/glog"
	"github.com/golang/protobuf/ptypes"
	"github.com/google/fleetspeak/fleetspeak/src/client/daemonservice/execution"
	"github.com/google/fleetspeak/fleetspeak/src/client/service"
	dspb "github.com/google/fleetspeak/fleetspeak/src/client/daemonservice/proto/fleetspeak_daemonservice"
	fspb "github.com/google/fleetspeak/fleetspeak/src/common/proto/fleetspeak"
)
var RespawnDelay = time.Minute
func Factory(conf *fspb.ClientServiceConfig) (service.Service, error) {
	dsConf := &dspb.Config{}
	if err := ptypes.UnmarshalAny(conf.Config, dsConf); err != nil {
		return nil, fmt.Errorf(
			"can't unmarshal the given ClientServiceConfig.config (%q): %v",
			conf.Config, err)
	}
	var timeout time.Duration
	if dsConf.InactivityTimeout != nil {
		var err error
		timeout, err = ptypes.Duration(dsConf.InactivityTimeout)
		if err != nil {
			return nil, fmt.Errorf(
				"can't convert the given DaemonServiceConfig.inactivity_timeout (%q) to time.Duration: %v",
				dsConf.InactivityTimeout, err)
		}
		dsConf.LazyStart = true
	}
	ret := Service{
		name:              conf.Name,
		cfg:               dsConf,
		inactivityTimeout: timeout,
		stop: make(chan struct{}),
		msgs: make(chan *fspb.Message),
	}
	return &ret, nil
}
type Service struct {
	name              string
	cfg               *dspb.Config
	sc                service.Context
	inactivityTimeout time.Duration
	stop chan struct{}       
	msgs chan *fspb.Message  
	routines sync.WaitGroup  
}
func (s *Service) Start(sc service.Context) error {
	s.sc = sc
	s.routines.Add(1)
	go s.executionManagerLoop()
	return nil
}
func (s *Service) Stop() error {
	close(s.stop)
	s.routines.Wait()
	return nil
}