util.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package control
  2. import (
  3. "bufio"
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "strings"
  8. "time"
  9. "github.com/rancher/os/config"
  10. "github.com/rancher/os/pkg/log"
  11. "github.com/pkg/errors"
  12. )
  13. func yes(question string) bool {
  14. fmt.Printf("%s [y/N]: ", question)
  15. in := bufio.NewReader(os.Stdin)
  16. line, err := in.ReadString('\n')
  17. if err != nil {
  18. log.Fatal(err)
  19. }
  20. return strings.ToLower(line[0:1]) == "y"
  21. }
  22. func formatImage(image string, cfg *config.CloudConfig) string {
  23. domainRegistry := cfg.Rancher.Environment["REGISTRY_DOMAIN"]
  24. if domainRegistry != "docker.io" && domainRegistry != "" {
  25. return fmt.Sprintf("%s/%s", domainRegistry, image)
  26. }
  27. return image
  28. }
  29. func symLinkEngineBinary(version string) []symlink {
  30. baseSymlink := []symlink{
  31. {"/var/lib/rancher/engine/docker", "/usr/bin/docker"},
  32. {"/var/lib/rancher/engine/dockerd", "/usr/bin/dockerd"},
  33. {"/var/lib/rancher/engine/docker-init", "/usr/bin/docker-init"},
  34. {"/var/lib/rancher/engine/docker-proxy", "/usr/bin/docker-proxy"},
  35. {"/usr/share/ros/os-release", "/usr/lib/os-release"},
  36. {"/usr/share/ros/os-release", "/etc/os-release"},
  37. }
  38. if strings.Contains(version, "18.09") {
  39. baseSymlink = append(baseSymlink, []symlink{
  40. {"/var/lib/rancher/engine/containerd", "/usr/bin/containerd"},
  41. {"/var/lib/rancher/engine/ctr", "/usr/bin/ctr"},
  42. {"/var/lib/rancher/engine/containerd-shim", "/usr/bin/containerd-shim"},
  43. {"/var/lib/rancher/engine/runc", "/usr/bin/runc"},
  44. }...)
  45. } else {
  46. baseSymlink = append(baseSymlink, []symlink{
  47. {"/var/lib/rancher/engine/docker-containerd", "/usr/bin/docker-containerd"},
  48. {"/var/lib/rancher/engine/docker-containerd-ctr", "/usr/bin/docker-containerd-ctr"},
  49. {"/var/lib/rancher/engine/docker-containerd-shim", "/usr/bin/docker-containerd-shim"},
  50. {"/var/lib/rancher/engine/docker-runc", "/usr/bin/docker-runc"},
  51. }...)
  52. }
  53. return baseSymlink
  54. }
  55. func checkZfsBackingFS(driver, dir string) error {
  56. if driver != "zfs" {
  57. return nil
  58. }
  59. for i := 0; i < 4; i++ {
  60. mountInfo, err := ioutil.ReadFile("/proc/self/mountinfo")
  61. if err != nil {
  62. continue
  63. }
  64. for _, mount := range strings.Split(string(mountInfo), "\n") {
  65. if strings.Contains(mount, dir) && strings.Contains(mount, driver) {
  66. return nil
  67. }
  68. }
  69. time.Sleep(1 * time.Second)
  70. }
  71. return errors.Errorf("BackingFS: %s not match storage-driver: %s", dir, driver)
  72. }
  73. func checkGlobalCfg() bool {
  74. _, err := os.Stat("/proc/1/root/boot/global.cfg")
  75. if err == nil || os.IsExist(err) {
  76. return true
  77. }
  78. return false
  79. }