wizard_nginx.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. proxy, _ := checkNginx(client, w.network)
  29. if proxy != nil {
  30. // Reverse proxy is running, if ports match, we need a virtual host
  31. if proxy.port == port {
  32. fmt.Println()
  33. fmt.Printf("Shared port, which domain to assign? (default = %s)\n", def)
  34. return w.readDefaultString(def), nil
  35. }
  36. }
  37. // Reverse proxy is not running, offer to deploy a new one
  38. fmt.Println()
  39. fmt.Println("Allow sharing the port with other services (y/n)? (default = yes)")
  40. if w.readDefaultYesNo(true) {
  41. nocache := false
  42. if proxy != nil {
  43. fmt.Println()
  44. fmt.Printf("Should the reverse-proxy be rebuilt from scratch (y/n)? (default = no)\n")
  45. nocache = w.readDefaultYesNo(false)
  46. }
  47. if out, err := deployNginx(client, w.network, port, nocache); err != nil {
  48. log.Error("Failed to deploy reverse-proxy", "err", err)
  49. if len(out) > 0 {
  50. fmt.Printf("%s\n", out)
  51. }
  52. return "", err
  53. }
  54. // Reverse proxy deployed, ask again for the virtual-host
  55. fmt.Println()
  56. fmt.Printf("Proxy deployed, which domain to assign? (default = %s)\n", def)
  57. return w.readDefaultString(def), nil
  58. }
  59. // Reverse proxy not requested, deploy as a standalone service
  60. return "", nil
  61. }