mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05:00 
			
		
		
		
	server: read -conf flag before reading stdin config file
This commit is contained in:
		
							parent
							
								
									47717fee88
								
							
						
					
					
						commit
						70d6caf95b
					
				
							
								
								
									
										28
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								main.go
									
									
									
									
									
								
							@ -24,7 +24,6 @@ var (
 | 
				
			|||||||
	http2    bool // TODO: temporary flag until http2 is standard
 | 
						http2    bool // TODO: temporary flag until http2 is standard
 | 
				
			||||||
	quiet    bool
 | 
						quiet    bool
 | 
				
			||||||
	cpu      string
 | 
						cpu      string
 | 
				
			||||||
	confBody []byte // configuration data to use, piped from stdin
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
@ -39,18 +38,6 @@ func init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	config.AppName = "Caddy"
 | 
						config.AppName = "Caddy"
 | 
				
			||||||
	config.AppVersion = "0.6.0"
 | 
						config.AppVersion = "0.6.0"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Load piped configuration data, if any
 | 
					 | 
				
			||||||
	fi, err := os.Stdin.Stat()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		log.Fatal(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if fi.Mode()&os.ModeCharDevice == 0 {
 | 
					 | 
				
			||||||
		confBody, err = ioutil.ReadAll(os.Stdin)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Fatal(err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@ -117,8 +104,19 @@ func loadConfigs() ([]server.Config, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// stdin
 | 
						// stdin
 | 
				
			||||||
	if len(confBody) > 0 {
 | 
						// Load piped configuration data, if any
 | 
				
			||||||
		return config.Load("stdin", bytes.NewReader(confBody))
 | 
						fi, err := os.Stdin.Stat()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err == nil && fi.Mode()&os.ModeCharDevice == 0 {
 | 
				
			||||||
 | 
							confBody, err := ioutil.ReadAll(os.Stdin)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								log.Fatal(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if len(confBody) > 0 {
 | 
				
			||||||
 | 
								return config.Load("stdin", bytes.NewReader(confBody))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Caddyfile
 | 
						// Caddyfile
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user