wizard_nginx.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "fmt"
  19. "github.com/ethereum/go-ethereum/log"
  20. )
  21. // ensureVirtualHost checks whether a reverse-proxy is running on the specified
  22. // host machine, and if yes requests a virtual host from the user to host a
  23. // specific web service on. If no proxy exists, the method will offer to deploy
  24. // one.
  25. //
  26. // If the user elects not to use a reverse proxy, an empty hostname is returned!
  27. func (w *wizard) ensureVirtualHost(client *sshClient, port int, def string) (string, error) {
  28. if proxy, _ := checkNginx(client, w.network); 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. if out, err := deployNginx(client, w.network, port); err != nil {
  41. log.Error("Failed to deploy reverse-proxy", "err", err)
  42. if len(out) > 0 {
  43. fmt.Printf("%s\n", out)
  44. }
  45. return "", err
  46. }
  47. // Reverse proxy deployed, ask again for the virtual-host
  48. fmt.Println()
  49. fmt.Printf("Proxy deployed, which domain to assign? (default = %s)\n", def)
  50. return w.readDefaultString(def), nil
  51. }
  52. // Reverse proxy not requested, deploy as a standalone service
  53. return "", nil
  54. }