当前位置: 首页>>代码示例>>Golang>>正文


Golang daemon.SdNotify函数代码示例

本文整理汇总了Golang中github.com/coreos/go-systemd/daemon.SdNotify函数的典型用法代码示例。如果您正苦于以下问题:Golang SdNotify函数的具体用法?Golang SdNotify怎么用?Golang SdNotify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SdNotify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: serve

func serve(listeners []net.Listener, servers []*http.Server) error {
	hdServers := make([]httpdown.Server, len(listeners))
	for i, l := range listeners {
		if servers[i].TLSConfig != nil {
			l = tls.NewListener(l, servers[i].TLSConfig)
		}
		hdServers[i] = httpdown.HTTP{}.Serve(servers[i], l)
	}
	_ = daemon.SdNotify(sdReady) // ignore error

	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGTERM)
	<-ch
	signal.Stop(ch)

	errs := make([]error, len(listeners))
	wg := sync.WaitGroup{}
	for i := range hdServers {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			errs[i] = hdServers[i].Stop()
		}(i)
	}
	wg.Wait()

	for _, err := range errs {
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:orivej,项目名称:grace,代码行数:33,代码来源:http.go

示例2: StartAllInOne

// StartAllInOne:
// 1.  Creates the signer certificate if needed
// 2.  Calls RunMaster
// 3.  Calls RunNode
// 4.  If only writing configs, it exits
// 5.  Waits forever
func (o AllInOneOptions) StartAllInOne() error {
	if o.PrintIP {
		host, _, err := net.SplitHostPort(o.NodeArgs.DefaultKubernetesURL.Host)
		if err != nil {
			return err
		}
		fmt.Fprintf(o.Output, "%s\n", host)
		return nil
	}
	masterOptions := *o.MasterOptions
	if err := masterOptions.RunMaster(); err != nil {
		return err
	}

	nodeOptions := NodeOptions{o.NodeArgs, o.NodeConfigFile, o.MasterOptions.Output}
	if err := nodeOptions.RunNode(); err != nil {
		return err
	}

	if o.IsWriteConfigOnly() {
		return nil
	}

	daemon.SdNotify("READY=1")
	select {}
}
开发者ID:abhgupta,项目名称:origin,代码行数:32,代码来源:start_allinone.go

示例3: StartEtcdServer

// StartEtcdServer calls RunEtcdServer and then waits forever
func (o *EtcdOptions) StartEtcdServer() error {
	if err := o.RunEtcdServer(); err != nil {
		return err
	}

	go daemon.SdNotify("READY=1")
	select {}
}
开发者ID:pweil-,项目名称:origin,代码行数:9,代码来源:start_etcd.go

示例4: AcceptConnections

func (s *Server) AcceptConnections() {
	go systemdDaemon.SdNotify("READY=1")
	// close the lock so the listeners start accepting connections
	select {
	case <-s.start:
	default:
		close(s.start)
	}
}
开发者ID:tomasen,项目名称:restful,代码行数:9,代码来源:server.go

示例5: main

func main() {
	flag.Parse()

	exists, err := dirExists(*outputDir)
	if err != nil {
		log.Fatal(err)
	}

	if !exists {
		if err := os.Mkdir(*outputDir, 0755); err != nil {
			log.Fatal(err)
		}
	}

	cfg := client.Config{
		Endpoints: []string{*endpoint},
		Transport: client.DefaultTransport,
		// set timeout per request to fail fast when the target endpoint is unavailable
		HeaderTimeoutPerRequest: time.Second,
	}

	c, err := client.New(cfg)
	if err != nil {
		log.Fatal(err)
	}

	if err := c.Sync(context.Background()); err != nil {
		log.Fatal(err)
	}

	kapi := client.NewKeysAPI(c)

	resp, err := generateConfig(kapi)
	if err != nil {
		log.Fatal(err)
	}
	if systemdutil.IsRunningSystemd() {
		err := daemon.SdNotify("READY=1")
		if err != nil {
			log.Printf("failed to notify systemd for readiness: %v", err)
			if err == daemon.SdNotifyNoSocket {
				log.Printf("forgot to set Type=notify in systemd service file?")
			}
		}
	}
	if *watch {
		for {
			resp, err = generateConfigWatcher(kapi, resp)
			if err != nil {
				log.Fatal(err)
			}
		}
	}
	os.Exit(0)
}
开发者ID:themecloud,项目名称:etcd2envfile,代码行数:55,代码来源:etcd2envfile.go

示例6: Clean

func (r *SystemdConfig) Clean() {
	daemon.SdNotify("STOPPING=1")

	for service, filenames := range r.written {
		log.Printf("systemd: %s: removing configs...", service)
		for _, filename := range filenames {
			os.Remove(filename)
		}
		reload(service)
	}
}
开发者ID:raceli,项目名称:resolvable,代码行数:11,代码来源:systemd.go

示例7: StartNode

// StartNode calls RunNode and then waits forever
func (o NodeOptions) StartNode() error {
	if err := o.RunNode(); err != nil {
		return err
	}

	if o.IsWriteConfigOnly() {
		return nil
	}

	go daemon.SdNotify("READY=1")
	select {}
}
开发者ID:poomsujarit,项目名称:origin,代码行数:13,代码来源:start_node.go

示例8: AcceptConnections

// AcceptConnections allows clients to connect to the API server.
// Referenced Daemon is notified about this server, and waits for the
// daemon acknowledgement before the incoming connections are accepted.
func (s *Server) AcceptConnections(d *daemon.Daemon) {
	// Tell the init daemon we are accepting requests
	s.daemon = d
	s.registerSubRouter()
	go systemdDaemon.SdNotify("READY=1")
	// close the lock so the listeners start accepting connections
	select {
	case <-s.start:
	default:
		close(s.start)
	}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:15,代码来源:server_unix.go

示例9: StartMaster

// StartMaster calls RunMaster and then waits forever
func (o MasterOptions) StartMaster() error {
	if err := o.RunMaster(); err != nil {
		return err
	}

	if o.IsWriteConfigOnly() {
		return nil
	}

	// TODO: this should be encapsulated by RunMaster, but StartAllInOne has no
	// way to communicate whether RunMaster should block.
	go daemon.SdNotify("READY=1")
	select {}
}
开发者ID:sgallagher,项目名称:origin,代码行数:15,代码来源:start_master.go

示例10: StartMaster

// StartMaster calls RunMaster and then waits forever
func (o MasterOptions) StartMaster() error {
	if err := o.RunMaster(); err != nil {
		return err
	}

	if o.IsWriteConfigOnly() {
		return nil
	}

	go daemon.SdNotify("READY=1")
	select {}

	return nil
}
开发者ID:brandon-adams,项目名称:origin,代码行数:15,代码来源:start_master.go

示例11: NewCommandStartAllInOne

// This function provides a CLI handler for 'start' command
func NewCommandStartAllInOne(fullName string, out io.Writer) (*cobra.Command, *AllInOneOptions) {
	options := &AllInOneOptions{}

	cmds := &cobra.Command{
		Use:   "start",
		Short: "Launch StraYard All-In-One",
		Long:  allinoneLongDesc,
		Run: func(c *cobra.Command, args []string) {
			fmt.Println("haha")
			daemon.SdNotify("READY=1")
			select {}
		},
	}
	cmds.SetOutput(out)
	return cmds, options
}
开发者ID:vishnuvr,项目名称:strayard,代码行数:17,代码来源:start_allinone.go

示例12: RunServer

func RunServer(ctx context.Context, sm subnet.Manager, listenAddr, cafile, certfile, keyfile string) {
	// {network} is always required a the API level but to
	// keep backward compat, special "_" network is allowed
	// that means "no network"

	r := mux.NewRouter()
	r.HandleFunc("/v1/{network}/config", bindHandler(handleGetNetworkConfig, ctx, sm)).Methods("GET")

	r.HandleFunc("/v1/{network}/leases", bindHandler(handleAcquireLease, ctx, sm)).Methods("POST")
	r.HandleFunc("/v1/{network}/leases/{subnet}", bindHandler(handleWatchLease, ctx, sm)).Methods("GET")
	r.HandleFunc("/v1/{network}/leases/{subnet}", bindHandler(handleRenewLease, ctx, sm)).Methods("PUT")
	r.HandleFunc("/v1/{network}/leases/{subnet}", bindHandler(handleRevokeLease, ctx, sm)).Methods("DELETE")
	r.HandleFunc("/v1/{network}/leases", bindHandler(handleWatchLeases, ctx, sm)).Methods("GET")
	r.HandleFunc("/v1/", bindHandler(handleNetworks, ctx, sm)).Methods("GET")

	r.HandleFunc("/v1/{network}/reservations", bindHandler(handleListReservations, ctx, sm)).Methods("GET")
	r.HandleFunc("/v1/{network}/reservations", bindHandler(handleAddReservation, ctx, sm)).Methods("POST")
	r.HandleFunc("/v1/{network}/reservations/{subnet}", bindHandler(handleRemoveReservation, ctx, sm)).Methods("DELETE")

	l, err := listener(listenAddr, cafile, certfile, keyfile)
	if err != nil {
		log.Errorf("Error listening on %v: %v", listenAddr, err)
		return
	}

	c := make(chan error, 1)
	go func() {
		c <- http.Serve(l, httpLogger(r))
	}()

	daemon.SdNotify("READY=1")

	select {
	case <-ctx.Done():
		l.Close()
		<-c

	case err := <-c:
		log.Errorf("Error serving on %v: %v", listenAddr, err)
	}
}
开发者ID:luxas,项目名称:flannel,代码行数:41,代码来源:server.go

示例13: StoreAddress

func (r *SystemdConfig) StoreAddress(address string) error {
	data := templateArgs{address}

	for _, s := range r.services {
		pattern := filepath.Join(r.templatePath, s.dir, s.filepattern)

		log.Printf("systemd: %s: loading config from %s", s.name, pattern)

		templates, err := template.ParseGlob(pattern)
		if err != nil {
			log.Println("systemd:", err)
			continue
		}

		var written []string

		for _, t := range templates.Templates() {
			dest := filepath.Join(r.destPath, s.dir, t.Name())
			log.Println("systemd: generating", dest)
			fp, err := os.Create(dest)
			if err != nil {
				log.Println("systemd:", err)
				continue
			}
			written = append(written, dest)
			t.Execute(fp, data)
			fp.Close()
		}

		if written != nil {
			r.written[s.name] = written
			reload(s.name)
		} else {
			log.Println("systemd: %s: no configs written, skipping reload", s.name)
		}
	}

	daemon.SdNotify("READY=1")
	return nil
}
开发者ID:raceli,项目名称:resolvable,代码行数:40,代码来源:systemd.go

示例14: Run

// Run spawns the http servers (secure and insecure). It only returns if stopCh is closed
// or one of the ports cannot be listened on initially.
func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) {
	if s.SecureServingInfo != nil && s.Handler != nil {
		if err := s.serveSecurely(stopCh); err != nil {
			glog.Fatal(err)
		}
	}

	if s.InsecureServingInfo != nil && s.InsecureHandler != nil {
		if err := s.serveInsecurely(stopCh); err != nil {
			glog.Fatal(err)
		}
	}

	s.RunPostStartHooks()

	// err == systemd.SdNotifyNoSocket when not running on a systemd system
	if err := systemd.SdNotify("READY=1\n"); err != nil && err != systemd.SdNotifyNoSocket {
		glog.Errorf("Unable to send systemd daemon successful start message: %v\n", err)
	}

	<-stopCh
}
开发者ID:upmc-enterprises,项目名称:kubernetes,代码行数:24,代码来源:genericapiserver.go

示例15: StartAllInOne

// StartAllInOne:
// 1.  Creates the signer certificate if needed
// 2.  Calls RunMaster
// 3.  Calls RunNode
// 4.  If only writing configs, it exits
// 5.  Waits forever
func (o AllInOneOptions) StartAllInOne() error {
	if !o.IsWriteConfigOnly() {
		glog.Infof("Starting an OpenShift all-in-one")
	}

	masterOptions := MasterOptions{o.MasterArgs, o.CreateCerts, o.MasterConfigFile, o.Output}
	if err := masterOptions.RunMaster(); err != nil {
		return err
	}

	nodeOptions := NodeOptions{o.NodeArgs, o.NodeConfigFile, o.Output}
	if err := nodeOptions.RunNode(); err != nil {
		return err
	}

	if o.IsWriteConfigOnly() {
		return nil
	}

	daemon.SdNotify("READY=1")
	select {}

	return nil
}
开发者ID:brandon-adams,项目名称:origin,代码行数:30,代码来源:start_allinone.go


注:本文中的github.com/coreos/go-systemd/daemon.SdNotify函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。