func loadAsset(path, defaultValue string) string { devPath := fmt.Sprintf( "%s/src/github.com/emccode/rexray/daemon/module/admin/html/%s", os.Getenv("GOPATH"), path) if util.FileExists(devPath) { v, _ := ioutil.ReadFile(devPath) log.Printf("Loaded %s from %s\n", path, devPath) return string(v) } exeDir, _, _ := util.GetThisPathParts() relPath := fmt.Sprintf( "%s/html/%s", exeDir, path) if util.FileExists(relPath) { v, _ := ioutil.ReadFile(devPath) log.Printf("Loaded %s from %s\n", path, relPath) return string(v) } return defaultValue }
func tryToStartDaemon() { _, _, thisAbsPath := util.GetThisPathParts() fmt.Print("Starting REX-Ray...") signal := make(chan byte) client := fmt.Sprintf("%s/%s.sock", os.TempDir(), util.RandomString(32)) log.WithField("client", client).Debug("trying to start service") l, lErr := net.Listen("unix", client) failOnError(lErr) go func() { conn, acceptErr := l.Accept() if acceptErr != nil { fmt.Printf("FAILED!\n %v\n", acceptErr) panic(acceptErr) } defer conn.Close() defer os.Remove(client) log.Debug("accepted connection") buff := make([]byte, 1) conn.Read(buff) log.Debug("received data") signal <- buff[0] }() cmdArgs := []string{ "start", fmt.Sprintf("--client=%s", client), fmt.Sprintf("--logLevel=%v", r.Config.LogLevel)} if r.Config.Host != "" { cmdArgs = append(cmdArgs, fmt.Sprintf("--host=%s", r.Config.Host)) } cmd := exec.Command(thisAbsPath, cmdArgs...) cmd.Stderr = os.Stderr cmdErr := cmd.Start() failOnError(cmdErr) sigVal := <-signal if sigVal != 0 { fmt.Println("FAILED!") panic(1) } pid, _ := util.ReadPidFile() fmt.Printf("SUCESS!\n\n") fmt.Printf(" The REX-Ray daemon is now running at PID %d. To\n", pid) fmt.Printf(" shutdown the daemon execute the following command:\n\n") fmt.Printf(" sudo %s stop\n\n", thisAbsPath) }
func install() { checkOpPerms("installed") _, _, exeFile := util.GetThisPathParts() if runtime.GOOS == "linux" { switch getInitSystemType() { case SystemD: installSystemD(exeFile) case UpdateRcD: installUpdateRcd(exeFile) case ChkConfig: installChkConfig(exeFile) } } }
func uninstall(pkgManager bool) { checkOpPerms("uninstalled") _, _, binFile := util.GetThisPathParts() // if the uninstall command was executed manually we should check to see // if this file is owned by a package manager and remove it that way if so if !pkgManager { log.WithField("binFile", binFile).Debug("is this a managed file?") var pkgName string if isRpmInstall(binFile, &pkgName) { uninstallRpm(pkgName) return } else if isDebInstall(binFile, &pkgName) { uninstallDeb(pkgName) return } } func() { defer func() { recover() }() stop() }() switch GetInitSystemType() { case SystemD: uninstallSystemD() case UpdateRcD: uninstallUpdateRcd() case ChkConfig: uninstallChkConfig() } os.RemoveAll(util.EtcDirPath()) os.RemoveAll(util.RunDirPath()) os.RemoveAll(util.LibDirPath()) os.RemoveAll(util.LogDirPath()) if !pkgManager { os.Remove(binFile) if util.IsPrefixed() { os.RemoveAll(util.GetPrefix()) } } }
func Install() { checkOpPerms("installed") _, _, exeFile := util.GetThisPathParts() os.Chown(exeFile, 0, 0) exec.Command("chmod", "4755", exeFile).Run() switch GetInitSystemType() { case SYSTEMD: installSystemD(exeFile) case UPDATERCD: installUpdateRcd(exeFile) case CHKCONFIG: installChkConfig(exeFile) } }
func Install() { checkOpPerms("installed") _, _, thisAbsPath := util.GetThisPathParts() exeDir := filepath.Dir(EXEFILE) os.MkdirAll(exeDir, 0755) os.Chown(exeDir, 0, 0) exec.Command("cp", "-f", thisAbsPath, EXEFILE).Run() os.Chown(EXEFILE, 0, 0) exec.Command("chmod", "4755", EXEFILE).Run() switch GetInitSystemType() { case SYSTEMD: installSystemD() case UPDATERCD: installUpdateRcd() case CHKCONFIG: installChkConfig() } }