mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	sd_notify ready status when accepting API requests
This commit is contained in:
		
							parent
							
								
									afbea3f13f
								
							
						
					
					
						commit
						97088ebef7
					
				
					 2 changed files with 38 additions and 2 deletions
				
			
		
							
								
								
									
										7
									
								
								api.go
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								api.go
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -10,6 +10,7 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
	"github.com/dotcloud/docker/archive"
 | 
			
		||||
	"github.com/dotcloud/docker/auth"
 | 
			
		||||
	"github.com/dotcloud/docker/systemd"
 | 
			
		||||
	"github.com/dotcloud/docker/utils"
 | 
			
		||||
	"github.com/gorilla/mux"
 | 
			
		||||
	"io"
 | 
			
		||||
| 
						 | 
				
			
			@ -1184,8 +1185,6 @@ func ServeRequest(srv *Server, apiversion float64, w http.ResponseWriter, req *h
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
 | 
			
		||||
	log.Printf("Listening for HTTP on %s (%s)\n", addr, proto)
 | 
			
		||||
 | 
			
		||||
	r, err := createRouter(srv, logging)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
| 
						 | 
				
			
			@ -1216,5 +1215,9 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
	httpSrv := http.Server{Addr: addr, Handler: r}
 | 
			
		||||
 | 
			
		||||
	log.Printf("Listening for HTTP on %s (%s)\n", addr, proto)
 | 
			
		||||
	// Tell the init daemon we are accepting requests
 | 
			
		||||
	go systemd.SdNotify("READY=1")
 | 
			
		||||
	return httpSrv.Serve(l)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										33
									
								
								systemd/sd_notify.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								systemd/sd_notify.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
package systemd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"net"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var SdNotifyNoSocket = errors.New("No socket")
 | 
			
		||||
 | 
			
		||||
// Send a message to the init daemon. It is common to ignore the error.
 | 
			
		||||
func SdNotify(state string) error {
 | 
			
		||||
	socketAddr := &net.UnixAddr{
 | 
			
		||||
		Name: os.Getenv("NOTIFY_SOCKET"),
 | 
			
		||||
		Net:  "unixgram",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if socketAddr.Name == "" {
 | 
			
		||||
		return SdNotifyNoSocket
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err = conn.Write([]byte(state))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue