github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/puppeth/wizard_nginx.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package main
    13  
    14  import (
    15  	"fmt"
    16  
    17  	"github.com/Sberex/go-sberex/log"
    18  )
    19  
    20  // ensureVirtualHost checks whether a reverse-proxy is running on the specified
    21  // host machine, and if yes requests a virtual host from the user to host a
    22  // specific web service on. If no proxy exists, the method will offer to deploy
    23  // one.
    24  //
    25  // If the user elects not to use a reverse proxy, an empty hostname is returned!
    26  func (w *wizard) ensureVirtualHost(client *sshClient, port int, def string) (string, error) {
    27  	proxy, _ := checkNginx(client, w.network)
    28  	if proxy != nil {
    29  		// Reverse proxy is running, if ports match, we need a virtual host
    30  		if proxy.port == port {
    31  			fmt.Println()
    32  			fmt.Printf("Shared port, which domain to assign? (default = %s)\n", def)
    33  			return w.readDefaultString(def), nil
    34  		}
    35  	}
    36  	// Reverse proxy is not running, offer to deploy a new one
    37  	fmt.Println()
    38  	fmt.Println("Allow sharing the port with other services (y/n)? (default = yes)")
    39  	if w.readDefaultString("y") == "y" {
    40  		nocache := false
    41  		if proxy != nil {
    42  			fmt.Println()
    43  			fmt.Printf("Should the reverse-proxy be rebuilt from scratch (y/n)? (default = no)\n")
    44  			nocache = w.readDefaultString("n") != "n"
    45  		}
    46  		if out, err := deployNginx(client, w.network, port, nocache); err != nil {
    47  			log.Error("Failed to deploy reverse-proxy", "err", err)
    48  			if len(out) > 0 {
    49  				fmt.Printf("%s\n", out)
    50  			}
    51  			return "", err
    52  		}
    53  		// Reverse proxy deployed, ask again for the virtual-host
    54  		fmt.Println()
    55  		fmt.Printf("Proxy deployed, which domain to assign? (default = %s)\n", def)
    56  		return w.readDefaultString(def), nil
    57  	}
    58  	// Reverse proxy not requested, deploy as a standalone service
    59  	return "", nil
    60  }