Skip to content

Commit

Permalink
解决非root用户执行报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mzky committed Sep 4, 2019
1 parent c4239fc commit a29ce2c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
Binary file modified easyNmon
Binary file not shown.
2 changes: 2 additions & 0 deletions internal/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type NmonReport struct {
func GenIndexPage(nr *NmonReport, fPath string) {
tpl := template.Must(template.New("data.tpl").ParseFiles(filepath.Join("web", "chart", "data.tpl")))
file, err := os.Create(filepath.Join(fPath, "data.json"))
os.Chmod(filepath.Join(fPath, "data.json"), os.ModePerm)

if err != nil {
log.Println(err)
}
Expand Down
9 changes: 7 additions & 2 deletions main/easyNmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func main() {

ReportDir = *dir
NmonPath = *nmonpath
err := os.MkdirAll(ReportDir, 755)
syscall.Umask(0)
err := os.MkdirAll(ReportDir, os.ModePerm)
if err != nil {
fmt.Println("easyNmon启动权限不足!")
return
Expand Down Expand Up @@ -132,7 +133,7 @@ func start(c *gin.Context) { // 格式 ?n=name&t=time&f=60 参数均可为空
}
go func() {
fp := filepath.Join(ReportDir, fileName)
os.MkdirAll(fp, 777)
os.MkdirAll(fp, os.ModePerm)

buf, err := ioutil.ReadFile("web/chart/index.html")
if err != nil {
Expand All @@ -147,6 +148,10 @@ func start(c *gin.Context) { // 格式 ?n=name&t=time&f=60 参数均可为空
exec.Command("cp", "-f", "web/js/echarts.min.js", fp).Run()
// exec.Command("cp", "-f", "web/chart/index.html", fp).Run()
exec.Command("/bin/bash", "-c", strings.Join([]string{NmonPath, "-f -t -s", frequency, "-c", strconv.Itoa(t * 60 / f), "-m", fp, "-F", name}, " ")).Run()
os.Chmod(filepath.Join(fp, "index.html"), os.ModePerm)
os.Chmod(filepath.Join(fp, "echarts.min.js"), os.ModePerm)
os.Chmod(filepath.Join(fp, name), os.ModePerm)

time.Sleep(time.Second * 2)
internal.GetNmonReport(fp, name)
time.Sleep(time.Second * time.Duration(t*60+2))
Expand Down
2 changes: 1 addition & 1 deletion web/chart/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
});
}
ajaxGet();
setInterval(ajaxGet, 1000);
setInterval(ajaxGet, {{loopTime}});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
监控频率 </label>
<div class="am-u-sm-7">
<input type="text" class="am-form-field tpl-form-no-bg" id="frequency"
placeholder="输入监控频率">
placeholder="输入监控频率" value="30">
<small>单位为秒,推荐设置30秒以上</small>
</div>

Expand Down

0 comments on commit a29ce2c

Please sign in to comment.