本文整理汇总了Golang中github.com/toolkits/file.SelfDir函数的典型用法代码示例。如果您正苦于以下问题:Golang SelfDir函数的具体用法?Golang SelfDir怎么用?Golang SelfDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SelfDir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: InsureNewVersionFiles
func InsureNewVersionFiles(da *model.DesiredAgent) error {
if FilesReady(da) {
return nil
}
downloadTarballCmd := BuildCommand(da.RunUser, "wget", "-q", da.TarballUrl, "-O", path.Join(da.AgentVersionDir, da.TarballFilename))
downloadTarballCmd.Dir = file.SelfDir()
_, err := ExecuteCommandWithOutput(downloadTarballCmd)
if err != nil {
logger.Errorln("wget -q", da.TarballUrl, "-O", da.TarballFilename, "fail", err)
return err
}
downloadMd5Cmd := BuildCommand(da.RunUser, "wget", "-q", da.Md5Url, "-O", path.Join(da.AgentVersionDir, da.Md5Filename))
downloadMd5Cmd.Dir = file.SelfDir()
_, err = ExecuteCommandWithOutput(downloadMd5Cmd)
if err != nil {
log.Println("wget -q", da.Md5Url, "-O", da.Md5Filename, "fail", err)
return err
}
if "" != da.ConfigFileName && "" != da.ConfigRemoteUrl {
downloadConfigCmd := BuildCommand(da.RunUser, "wget", "-q", da.ConfigRemoteUrl, "-O", path.Join(da.AgentVersionDir, da.ConfigFileName))
downloadConfigCmd.Dir = file.SelfDir()
_, err := ExecuteCommandWithOutput(downloadConfigCmd)
if err != nil {
logger.Errorln("wget -q", da.ConfigRemoteUrl, "-O", da.ConfigFileName, "fail", err)
}
return err
}
return Md5sumCheck(da.RunUser, da.AgentVersionDir, da.TarballFilename, da.Md5Filename)
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:33,代码来源:start.go
示例2: WriteVersion
func WriteVersion(da *model.DesiredAgent) (err error) {
if CurrentUser == da.RunUser {
file.WriteString(path.Join(da.AgentDir, ".version"), da.Version)
} else {
file.WriteString(path.Join(file.SelfDir(), ".version"), da.Version)
_, err = utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo mv .version %s/", da.AgentDir))
if nil != err {
return
}
_, err = utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo chown -R %s:%s %s", da.RunUser, da.RunUser, path.Join(da.AgentDir, ".version")))
}
return
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:14,代码来源:start.go
示例3: StopAgentOf
func StopAgentOf(da *model.DesiredAgent, lastRunUser, lastWorkDir string) error {
agentDir := path.Join(lastWorkDir, da.Name)
version := ReadVersion(lastRunUser, agentDir)
if "" == version {
version = da.Version
}
if version == da.Version && da.RunUser == lastRunUser && da.WorkDir == lastWorkDir {
// do nothing
return nil
}
versionDir := path.Join(agentDir, version)
if !CheckDirectoryExists(lastRunUser, versionDir) {
logger.Warn("user: %s, %s nonexistent", lastRunUser, versionDir)
return nil
}
err := ControlStopIn(lastRunUser, versionDir)
if nil != err {
return err
}
cmd := BuildCommand(lastRunUser, "rm", "-rf", versionDir)
cmd.Dir = file.SelfDir()
_, err = ExecuteCommandWithOutput(cmd)
return err
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:28,代码来源:stop.go
示例4: Md5sumCheck
func Md5sumCheck(runUser, workdir, tarfile, md5file string) error {
var cmd *exec.Cmd
var md5Actual string
if "darwin" == runtime.GOOS {
cmd = BuildCommand(runUser, "md5", "-q", path.Join(workdir, tarfile))
} else {
cmd = BuildCommand(runUser, "md5sum", path.Join(workdir, tarfile))
}
cmd.Dir = file.SelfDir()
bs, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("cd %s; md5sum -c %s fail", workdir, md5file)
}
strMd5file, _ := file.ToString(path.Join(workdir, md5file))
if "" == strMd5file {
return fmt.Errorf("md5file is empty")
}
if "darwin" == runtime.GOOS {
md5Actual = strings.Replace(string(bs), "\n", "", -1)
} else {
md5Actual = strings.Fields(string(bs))[0]
}
md5Except := strings.Fields(strMd5file)[0]
if md5Actual == md5Except {
return nil
}
return fmt.Errorf("md5Actual:%s, md5Except:%s<<<===end", md5Actual, md5Except)
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:31,代码来源:start.go
示例5: configCommonRoutes
func configCommonRoutes() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(g.VERSION))
})
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, file.SelfDir())
})
http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, g.Config())
})
http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.RemoteAddr, "127.0.0.1") {
g.ParseConfig(g.ConfigFile)
RenderDataJson(w, "ok")
} else {
RenderDataJson(w, "no privilege")
}
})
}
开发者ID:masato25,项目名称:graph,代码行数:26,代码来源:common.go
示例6: CheckUserExists
func CheckUserExists(username string) bool {
_, err := ExecuteCommand(file.SelfDir(), fmt.Sprintf("id -u %s", username))
if nil != err {
return false
}
return true
}
开发者ID:coraldane,项目名称:ops-common,代码行数:7,代码来源:system.go
示例7: configAdminRoutes
func configAdminRoutes() {
http.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) {
if g.IsTrustable(r.RemoteAddr) {
w.Write([]byte("exiting..."))
go func() {
time.Sleep(time.Second)
os.Exit(0)
}()
} else {
w.Write([]byte("no privilege"))
}
})
http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
if g.IsTrustable(r.RemoteAddr) {
g.ParseConfig(g.ConfigFile)
RenderDataJson(w, g.Config())
} else {
w.Write([]byte("no privilege"))
}
})
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, file.SelfDir())
})
http.HandleFunc("/ips", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, g.TrustableIps())
})
}
开发者ID:tplink-zgc,项目名称:falcon-agent,代码行数:30,代码来源:admin.go
示例8: Control
func Control(runUser, workdir, arg string) (string, error) {
cmd := BuildCommand(runUser, path.Join(workdir, "control"), arg)
cmd.Dir = file.SelfDir()
out, err := ExecuteCommandWithOutput(cmd)
if err != nil {
logger.Error("cd %s; ./control %s fail %v. output: %s\n", workdir, arg, err, out)
}
return out, err
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:9,代码来源:control.go
示例9: GetUserByPid
func GetUserByPid(pid int) string {
cmd := exec.Command("sh", "-c", fmt.Sprintf("ps aux|awk '{if(%d==$2){print $1}}'", pid))
cmd.Dir = file.SelfDir()
bs, err := cmd.CombinedOutput()
if nil != err {
log.Println("getUserByPid error", err)
return ""
}
return strings.Replace(string(bs), "\n", "", -1)
}
开发者ID:coraldane,项目名称:ops-common,代码行数:10,代码来源:system.go
示例10: Untar
func Untar(da *model.DesiredAgent) error {
cmd := BuildCommand(da.RunUser, "tar", "zxf", path.Join(da.AgentVersionDir, da.TarballFilename), "-C", da.AgentVersionDir)
cmd.Dir = file.SelfDir()
err := cmd.Run()
if err != nil {
log.Println("tar zxf", da.TarballFilename, "fail", err)
return err
}
return nil
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:10,代码来源:start.go
示例11: ReadVersion
func ReadVersion(username, agentDir string) string {
versionFile := path.Join(agentDir, ".version")
cmd := BuildCommand(username, "sh", "read_file.sh", versionFile)
cmd.Dir = file.SelfDir()
version, err := ExecuteCommandWithOutput(cmd)
if err != nil {
logger.Warn("%s is nonexistent,error: %v", versionFile, err)
return ""
}
return version
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:11,代码来源:control.go
示例12: InsureRunUserExists
func InsureRunUserExists(da *model.DesiredAgent) error {
if CurrentUser == da.RunUser { //ops-updater和 Agent运行用户一致
return nil
} else if HasSudoPermission {
if utils.CheckUserExists(da.RunUser) {
return nil
}
_, err := utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo useradd %s", da.RunUser))
return err
}
return fmt.Errorf("you donot have permission to insure user %s", da.RunUser)
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:12,代码来源:start.go
示例13: InsureUserDir
func InsureUserDir(fp, username string, createByRoot bool) error {
var err error
if CheckDirectoryExists(username, fp) {
return nil
}
if CurrentUser == username {
return os.MkdirAll(fp, os.ModePerm)
} else if HasSudoPermission {
if createByRoot {
_, err = utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo mkdir -p %s", fp))
if nil != err {
return err
}
_, err = utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo chown -R %s:%s %s", username, username, fp))
} else {
_, err = utils.ExecuteCommand(file.SelfDir(), fmt.Sprintf("sudo -u %s mkdir -p %s", username, fp))
}
}
return err
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:21,代码来源:start.go
示例14: CheckFileOrDirExists
func CheckFileOrDirExists(username, fp, fileType string) bool {
if CurrentUser == username {
return file.IsExist(fp)
} else {
cmd := BuildCommand(username, "sh", "check_file.sh", fileType, fp)
cmd.Dir = file.SelfDir()
strOut, err := ExecuteCommandWithOutput(cmd)
if nil != err {
logger.Errorln("check dir exists", strOut, err)
return false
}
result, _ := strconv.ParseBool(strings.Replace(strOut, "\n", "", -1))
return result
}
return false
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:16,代码来源:control.go
示例15: configCommonRoutes
func configCommonRoutes() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
})
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("%s\n", g.VERSION)))
})
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("%s\n", file.SelfDir())))
})
http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, g.Config())
})
}
开发者ID:niean,项目名称:anteye,代码行数:17,代码来源:common.go
示例16: BuildHeartbeatRequest
func BuildHeartbeatRequest(hostname string, desiredAgents []*model.DesiredAgent) model.HeartbeatRequest {
req := model.HeartbeatRequest{Hostname: hostname}
req.Ip = utils.GetLocalIP()
req.UpdaterVersion = g.VERSION
req.RunUser = CurrentUser
realAgents := []*model.RealAgent{}
now := time.Now().Unix()
for _, da := range desiredAgents {
agentDir := path.Join(da.WorkDir, da.Name)
// 如果目录下没有.version,我们认为这根本不是一个agent
version := ReadVersion(da.RunUser, agentDir)
if "" == version {
logger.Error("read %s/.version fail\n", agentDir)
continue
}
controlFile := path.Join(agentDir, version, "control")
if !CheckFileExists(da.RunUser, controlFile) {
logger.Errorln(controlFile, "is nonexistent, user:", da.RunUser)
continue
}
cmd := BuildCommand(da.RunUser, path.Join(agentDir, version, "control"), "status")
cmd.Dir = f.SelfDir()
status, err := ExecuteCommandWithOutput(cmd)
if err != nil {
status = err.Error()
}
realAgent := &model.RealAgent{
Name: da.Name,
Version: version,
Status: status,
Timestamp: now,
}
realAgent.RunUser = da.RunUser
realAgent.WorkDir = da.WorkDir
realAgents = append(realAgents, realAgent)
}
req.RealAgents = realAgents
return req
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:46,代码来源:request.go
示例17: configCommonRoutes
func configCommonRoutes() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(g.VERSION))
})
http.HandleFunc("/versiongit", func(w http.ResponseWriter, r *http.Request) {
s := fmt.Sprintf("%s %s", g.VERSION, g.COMMIT)
w.Write([]byte(s))
})
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, file.SelfDir())
})
}
开发者ID:Jimbean0615,项目名称:query,代码行数:18,代码来源:common.go
示例18: ReadDesiredAgents
func ReadDesiredAgents() []*model.DesiredAgent {
var desiredAgents []*model.DesiredAgent
strJson, err := f.ToTrimString(path.Join(f.SelfDir(), "desired_agent.json"))
if nil != err {
logger.Errorln("read desired agent file error", err)
return desiredAgents
}
err = json.Unmarshal([]byte(strJson), &desiredAgents)
if nil != err {
logger.Errorln("unmarshal json error", strJson, err)
}
for _, da := range desiredAgents {
actualVersion := ReadVersion(da.RunUser, path.Join(da.WorkDir, da.Name))
if "" != actualVersion {
da.Version = actualVersion
}
}
return desiredAgents
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:20,代码来源:request.go
示例19: configRoutes
//.........这里部分代码省略.........
data := map[string]interface{}{
"mailLogs": mailLogs,
"start": start,
"stop": stop,
"currentPage": currentPage,
"showPrePage": showPrePage,
"prePageStart": prePageStart,
"prePageStop": prePageStop,
"nextPageStart": nextPageStart,
"nextPageStop": nextPageStop,
}
Render(w, "home/index.html", data)
})
// GET
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
data := status.Check()
Render(w, "status/index.html", data)
})
// GET
http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
Render(w, "home/login.html", nil)
})
http.HandleFunc("/doLogin", func(w http.ResponseWriter, r *http.Request) {
if !lastErrorTime.IsZero() && (time.Now().Sub(lastErrorTime) < time.Minute) {
w.Write([]byte("Pls try after " + time.Now().Add(time.Minute).String()))
return
}
r.ParseForm()
if len(r.Form["password"]) < 1 {
w.Write([]byte("Need password."))
return
}
if len(r.Form["username"]) < 1 {
w.Write([]byte("Need username."))
return
}
password := r.Form["password"][0]
username := r.Form["username"][0]
if password != config.Config().Password || username != config.Config().Username {
lastErrorTime = time.Now()
w.Write([]byte("I love you, Pls don't hurt me."))
return
} else {
storeUsername(w, r, username)
http.Redirect(w, r, "/", http.StatusFound)
return
}
})
http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
storeUsername(w, r, "")
http.Redirect(w, r, "/login", http.StatusFound)
return
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
})
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
if nil != checkLoggedIn(w, r) {
return
}
w.Write([]byte(fmt.Sprintf("%s\n", config.VERSION)))
})
http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
if nil != checkLoggedIn(w, r) {
return
}
w.Write([]byte(fmt.Sprintf("%s\n", file.SelfDir())))
})
http.HandleFunc("/config", func(w http.ResponseWriter, r *http.Request) {
if nil != checkLoggedIn(w, r) {
return
}
RenderOKJson(w, config.Config())
})
http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
if nil != checkLoggedIn(w, r) {
return
}
config.Parse(config.ConfigFile)
RenderOKJson(w, config.Config())
})
http.HandleFunc("/public/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})
}
开发者ID:baiyuxiong,项目名称:gomail,代码行数:101,代码来源:routes.go
示例20: WorkDir
func (this *FrameController) WorkDir() {
this.Ctx.WriteString(file.SelfDir())
}
开发者ID:coraldane,项目名称:ops-meta,代码行数:3,代码来源:frame_controller.go
注:本文中的github.com/toolkits/file.SelfDir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论