當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。