diff --git a/bin/boot.sh b/bin/boot.sh index d62e5177..b5655028 100755 --- a/bin/boot.sh +++ b/bin/boot.sh @@ -41,7 +41,11 @@ install() { && ./${ctx_app} upgrade ${target} && ${md5} ${ctx_app} \ && mv ${ctx_app} bin/${ctx_app} } +hup() { + echo "term hup" +} main() { + trap HUP hup while true; do ${ctx_bin} "$@" && break log "restarting..." && sleep 3 diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 37aff460..ec78ea8a 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -478,6 +478,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", // 解析结果 switch m.Option("cmd_parse") { + case "format": + var data interface{} + if json.Unmarshal(out.Bytes(), &data) == nil { + if b, e := json.MarshalIndent(data, "", " "); e == nil { + m.Echo(string(b)) + break + } + } + m.Echo(out.String()) case "json": var data interface{} if json.Unmarshal(out.Bytes(), &data) == nil { diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index 213e95da..1be6c17b 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -134,6 +134,14 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", m.Assert(e) mdb.conn = redis.NewConn(c, time.Second*10, time.Second*10) default: + if mdb.conn == nil { + m.Echo("not open") + break + } + if mdb.conn.Err() != nil { + m.Echo("%v", mdb.conn.Err()) + return + } args := []interface{}{} for _, v:=range arg[1:] { args = append(args, v) diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 4f99f4fa..966caec1 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -1126,6 +1126,10 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", "dir_type": &ctx.Config{Name: "dir_type(file/dir/both/all)", Value: "both", Help: "dir命令输出的文件类型, file: 只输出普通文件, dir: 只输出目录文件, 否则输出所有文件"}, "dir_fields": &ctx.Config{Name: "dir_fields(time/type/name/size/line/hash)", Value: "time size line filename", Help: "dir命令输出文件名的类型, name: 文件名, tree: 带缩进的文件名, path: 相对路径, full: 绝对路径"}, + "grep": &ctx.Config{Name: "grep", Value: map[string]interface{}{ + "list": map[string]interface{}{ + }, + }, Help: "dir命令输出文件名的类型, name: 文件名, tree: 带缩进的文件名, path: 相对路径, full: 绝对路径"}, "git": &ctx.Config{Name: "git", Value: map[string]interface{}{ "args": []interface{}{"-C", "@git_dir"}, "info": map[string]interface{}{"cmds": []interface{}{"log", "status", "branch"}}, @@ -1287,6 +1291,73 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", } return }}, + "grep": &ctx.Command{Name: "grep", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) > 0 { + switch arg[0]{ + case "add": + m.Confv("grep", []string{"list", arg[1]}, map[string]interface{}{ + "pos": 0, + "offset": 0, + "file": arg[2], + }) + return + + case "head": + m.Confm("grep", "list", func(key string, value map[string]interface{}) { + if len(arg) == 1 || key == arg[1] { + value["pos"] = 0 + value["offset"] = 0 + } + }) + return + case "tail": + m.Confm("grep", "list", func(key string, value map[string]interface{}) { + if len(arg) == 1 || key == arg[1] { + value["pos"] = -1 + value["offset"] = 0 + } + }) + return + } + } + + m.Confm("grep", "list", func(key string, value map[string]interface{}) { + f, e := os.Open(kit.Format(value["file"])) + m.Assert(e) + defer f.Close() + + // s, e := f.Stat() + // m.Assert(e) + + begin, e := f.Seek(int64(kit.Int(value["pos"])), 0) + if kit.Int(value["pos"]) == -1 { + begin, e = f.Seek(0, 2) + } + m.Assert(e) + + n := 0 + bio := bufio.NewScanner(f) + for i := 0; i < m.Optioni("page.limit") && bio.Scan(); i++ { + text := bio.Text() + if len(arg) == 0 || strings.Contains(text, arg[0]){ + m.Add("append", "key", key) + // m.Add("append", "pos",begin+int64(n)) + // m.Add("append", "len",len(text)) + // m.Add("append", "end",s.Size()) + m.Add("append", "line", kit.Int(value["offset"])) + m.Add("append", "text", text) + } else { + i-- + } + n+=len(text)+1 + value["offset"] = kit.Int(value["offset"]) + 1 + } + + value["pos"] = begin + int64(n) + }) + m.Table() + return + }}, "hash": &ctx.Command{Name: "hash filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { dir, name := path.Split(arg[0]) diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index a92149f5..f6170d67 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -62,16 +62,27 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"deploygo", "deploy"}}, map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_dir"}, - map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_branch"}, + map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_branch", "view": "long"}, map[string]interface{}{"type": "button", "value": "执行"}, }, }, + map[string]interface{}{"componet_name": "test", "componet_help": "test", + "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "cli", "upgrade"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "portal", "system", "bench"}}, + map[string]interface{}{"type": "text", "name": "action", "view": "long"}, + map[string]interface{}{"type": "button", "value": "升级"}, + }, + "display": map[string]interface{}{"show_result": true}, + }, map[string]interface{}{"componet_name": "php", "componet_help": "php", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", - "componet_args": []interface{}{"$$", "php"}, "inputs": []interface{}{ + "componet_args": []interface{}{"$$", "php", "cmd_parse", "format"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "usr/script/test.php"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "usr/script/test.php", "view": "long"}, map[string]interface{}{"type": "button", "value": "执行"}, }, }, @@ -79,9 +90,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_args": []interface{}{"$$", "context", "mdb", "redis"}, "inputs": []interface{}{ - map[string]interface{}{"type": "text", "name": "pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "values": []interface{}{"get", "del"}}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "test"}, + map[string]interface{}{"type": "text", "name": "pod", "value": "redis"}, + map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"get", "del"}}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "test", "view": "long"}, map[string]interface{}{"type": "button", "value": "执行"}, }, }, @@ -122,9 +133,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }, map[string]interface{}{"componet_name": "upgrade", "componet_help": "upgrade", "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "upgrade", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"bench", "system", "portal", "script"}}, + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{"$$", "context", "cli", "upgrade"}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "portal", "system", "bench"}}, map[string]interface{}{"type": "text", "name": "action"}, map[string]interface{}{"type": "button", "value": "升级"}, }, @@ -159,7 +171,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", "componet_type": "public", "componet_ctx": "aaa", "componet_cmd": "clip", "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"label": "content", "type": "text", "name": "content"}, + map[string]interface{}{"type": "text", "name": "content", "view": "long"}, map[string]interface{}{"type": "button", "value": "运行"}, }, }, @@ -244,7 +256,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_args": []interface{}{"$$", "context", "web", "post", "$$", "content_type", "application/json", "parse", "json"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, - map[string]interface{}{"type": "text", "name": "url", "value": "/"}, + map[string]interface{}{"type": "text", "name": "url", "value": "/", "view": "long"}, map[string]interface{}{"type": "button", "value": "执行"}, }, }, @@ -254,7 +266,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_args": []interface{}{"$$", "context", "web", "get"}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, map[string]interface{}{"type": "text", "name": "spide", "imports": "plugin_site"}, - map[string]interface{}{"type": "text", "name": "url", "value": "/"}, + map[string]interface{}{"type": "text", "name": "url", "value": "/", "view": "long"}, map[string]interface{}{"type": "button", "value": "执行"}, }, }, diff --git a/usr/librarys/example.css b/usr/librarys/example.css index f8303de3..6b990c65 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -30,6 +30,9 @@ fieldset form.option div.cmd input.args { background-color: black; width:160px; } +fieldset form.option div.long input.args { + width:320px; +} fieldset form.option label { margin-right:6px; } @@ -59,6 +62,10 @@ fieldset div.output div.code span.red { fieldset div.output div.code span.green { color:green; } +fieldset div.output table td { + word-break:break-all; + min-width:40px; +} fieldset.toast { background-color:#ffffff00;