diff --git a/bin/boot.sh b/bin/boot.sh index a17c5760..d62e5177 100755 --- a/bin/boot.sh +++ b/bin/boot.sh @@ -3,8 +3,9 @@ ctx_log=${ctx_log:="var/log"} ctx_app=${ctx_app:="bench"} ctx_bin=${ctx_app} && [ -f bin/${ctx_app} ] && ctx_bin=$(pwd)/bin/${ctx_app} -# ctx_box= # ctx_cas= +# ctx_ups= +# ctx_box= ctx_dev=${ctx_dev:="https://shylinux.com"} ctx_root=${ctx_root:=/usr/local/context} ctx_home=${ctx_home:=~/context} @@ -54,7 +55,11 @@ action() { dir=./ && [ -d "$1" ] && dir=$1 && shift [ -d "${dir}" ] && cd ${dir} -log "dev:$ctx_dev\ndir: $dir\nbin: $ctx_bin\n" +log "ups:$ctx_ups" +log "box:$ctx_box" +log "dev:$ctx_dev" +log "bin:$ctx_bin" +log "dir:$dir" case $1 in install) shift && install "$@";; diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index ca5a0eac..9d2080e8 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -103,7 +103,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", "runtime": &ctx.Config{Name: "runtime", Value: map[string]interface{}{ "init_env": []interface{}{ "ctx_log", "ctx_app", "ctx_bin", - "ctx_box", "ctx_cas", "ctx_dev", + "ctx_ups", "ctx_box", "ctx_dev", + "ctx_cas", "ctx_root", "ctx_home", "web_port", "ssh_port", }, @@ -137,9 +138,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", }, "import": []interface{}{ "github.com/nsf/termbox-go", - "github.com/skip2/go-qrcode", + "github.com/gomodule/redigo", "github.com/go-sql-driver/mysql", "github.com/gomarkdown/markdown", + "github.com/skip2/go-qrcode", "github.com/PuerkitoBio/goquery", "github.com/go-cas/cas", }, @@ -163,6 +165,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", "upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{ "system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"}, "portal": []interface{}{"template.tar.gz", "librarys.tar.gz"}, + "script": []interface{}{"test.php"}, "list": map[string]interface{}{ "bench": "bin/bench.new", "boot_sh": "bin/boot.sh", @@ -547,6 +550,15 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", list = append(list, []string{value}) }) + m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get", + "cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list) + + case "import": + list := [][]string{} + m.Confm("project", "import", func(index int, value string) { + list = append(list, []string{value}) + }) + m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get", "cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list) } @@ -569,6 +581,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", []string{"windows", "amd64"}, []string{"darwin", "amd64"}, }) + m.Echo("done %s", m.Time()) return } @@ -588,9 +601,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", }) p := m.Cmdx("nfs.path", m.Conf("compile", "bench")) - if m.Cmdy("cli.system", env, "go", "build", "-o", path.Join(m.Conf("publish", "path"), name), p); m.Result(0) == "" { + q := path.Join(m.Conf("publish", "path"), name) + if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" { + m.Append("time", m.Time()) m.Append("bin", name) - m.Append("hash", kit.Hashs(p)) + m.Append("hash", kit.Hashs(q)) m.Table() } } @@ -625,7 +640,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", return }}, - "upgrade": &ctx.Command{Name: "upgrade bench|system|extend|plugin|portal|client|script|project", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + "upgrade": &ctx.Command{Name: "upgrade project|bench|system|portal|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) == 0 { m.Cmdy("ctx.config", "upgrade") return @@ -640,10 +655,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", restart := false for _, link := range kit.View([]string{arg[0]}, m.Confm("upgrade")) { file := kit.Select(link, m.Conf("upgrade", []string{"list", strings.Replace(link, ".", "_", -1)})) + if arg[0] == "script" { + file = path.Join("usr/script", file) + } - if m.Cmd("web.get", "dev", fmt.Sprintf("publish/%s", link), - "GOOS", m.Conf("runtime", "host.GOOS"), "GOARCH", m.Conf("runtime", "host.GOARCH"), - "save", file); strings.HasPrefix(file, "bin/") { + m.Cmd("web.get", "dev", fmt.Sprintf("publish/%s", link), + "GOARCH", m.Conf("runtime", "host.GOARCH"), + "GOOS", m.Conf("runtime", "host.GOOS"), + "upgrade", arg[0], "save", file) + + if strings.HasPrefix(file, "bin/") { if m.Cmd("cli.system", "chmod", "a+x", file); link == "bench" { m.Cmd("cli.system", "mv", "bin/bench", fmt.Sprintf("bin/bench_%s", m.Time("20060102_150405"))) m.Cmd("cli.system", "mv", "bin/bench.new", "bin/bench") @@ -652,8 +673,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", restart = true } - m.Add("append", "hash", kit.Hashs(file)) + m.Add("append", "time", m.Time()) m.Add("append", "file", file) + m.Add("append", "hash", kit.Hashs(file)) if strings.HasSuffix(link, ".tar.gz") { m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file)) @@ -686,6 +708,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Echo(", wait 1s") m.GoFunc(m, func(m *ctx.Message) { time.Sleep(time.Second * 1) + m.Cmd("nfs._exit") os.Exit(kit.Int(code)) }) return diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index f0383030..213e95da 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -2,10 +2,13 @@ package mdb import ( "contexts/ctx" + "net" + "time" "toolkit" "database/sql" _ "github.com/go-sql-driver/mysql" + "github.com/gomodule/redigo/redis" "encoding/json" "fmt" @@ -14,6 +17,7 @@ import ( type MDB struct { *sql.DB + conn redis.Conn *ctx.Context } @@ -122,6 +126,30 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", kit.Select("数据源", m.Option("dbhelp")), arg...) return }}, + "redis": &ctx.Command{Name: "redis conn address [protocol]", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) { + switch arg[0] { + case "conn": + c, e := net.Dial(kit.Select("tcp", arg, 2), arg[1]) + m.Assert(e) + mdb.conn = redis.NewConn(c, time.Second*10, time.Second*10) + default: + args := []interface{}{} + for _, v:=range arg[1:] { + args = append(args, v) + } + res, err := mdb.conn.Do(arg[0], args...) + m.Assert(err) + switch val := res.(type) { + case redis.Error: + m.Echo("%v", val) + default: + m.Echo("%v", kit.Format(res)) + } + } + } + return + }}, "exec": &ctx.Command{Name: "exec sql [arg]", Help: "操作数据库, sql: SQL语句, arg: 操作参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) && mdb.DB != nil { which := make([]interface{}, 0, len(arg)) diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 719ba976..917b9c54 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -1146,6 +1146,10 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", m.Conf("paths", -2, m.Conf("runtime", "boot.ctx_root")) return }}, + "_exit": &ctx.Command{Name: "_init", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + termbox.Close() + return + }}, "pwd": &ctx.Command{Name: "pwd [all] | [[index] path] ", Help: "工作目录,all: 查看所有, index path: 设置路径, path: 设置当前路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if len(arg) > 0 && arg[0] == "all" { m.Cmdy("nfs.config", "paths") diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index f005c351..ad902316 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -71,21 +71,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }, }, "project": []interface{}{ - map[string]interface{}{"componet_name": "compile", "componet_help": "compile", - "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile", - "componet_args": []interface{}{}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "编译"}, - }, - "display": map[string]interface{}{"hide_append": true, "show_result": true}, - }, - map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", - "componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "", - "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "runtime", - "componet_args": []interface{}{"system"}, "inputs": []interface{}{ - map[string]interface{}{"type": "button", "value": "运行"}, - }, - }, map[string]interface{}{"componet_name": "context", "componet_help": "context", "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "", "componet_type": "private", "componet_ctx": "ctx", "componet_cmd": "context", @@ -174,7 +159,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_args": []interface{}{}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "gg"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "gg", "view": "hide"}, map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}}, map[string]interface{}{"type": "button", "value": "执行"}, }, @@ -184,13 +169,71 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", "componet_args": []interface{}{}, "inputs": []interface{}{ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, - map[string]interface{}{"type": "text", "name": "cmd", "value": "gg"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "gg", "view": "hide"}, 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": "button", "value": "执行"}, }, }, + 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{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "php"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "usr/script/test.php"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "redis", "componet_help": "redis", + "componet_tmpl": "componet", "componet_view": "Company", "componet_init": "", + "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "pod"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "context", "view": "hide"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "mdb", "view": "hide"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "redis", "view": "hide"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "get"}, + map[string]interface{}{"type": "text", "name": "cmd", "value": "test"}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + }, + "context": []interface{}{ + map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", + "componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "runtime", + "componet_args": []interface{}{"system"}, "inputs": []interface{}{ + map[string]interface{}{"type": "button", "value": "运行"}, + }, + }, + map[string]interface{}{"componet_name": "project", "componet_help": "project", + "componet_tmpl": "componet", "componet_view": "componet", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "project", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"import"}}, + map[string]interface{}{"type": "button", "value": "执行"}, + }, + }, + map[string]interface{}{"componet_name": "compile", "componet_help": "compile", + "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "action"}, + map[string]interface{}{"type": "button", "value": "编译"}, + }, + "display": map[string]interface{}{"hide_append": true, "show_result": true}, + }, + map[string]interface{}{"componet_name": "publish", "componet_help": "publish", + "componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "", + "componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile", + "componet_args": []interface{}{}, "inputs": []interface{}{ + map[string]interface{}{"type": "text", "name": "action"}, + map[string]interface{}{"type": "button", "value": "编译"}, + }, + "display": map[string]interface{}{"hide_append": true, "show_result": true}, + }, }, }, Help: "组件列表"}, }, @@ -386,6 +429,11 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", } switch arg[0] { case "auto": // 自动连接 + m.Log("fuck", "what %v", m.Conf("runtime", "boot.ctx_ups")) + if m.Confs("runtime", "boot.ctx_ups") { + m.Cmd("ssh.remote", "dial", m.Conf("runtime", "boot.ctx_ups")) + break + } if m.Cmd("ssh.remote", "dial", "dev", "/shadow"); !m.Confs("runtime", "boot.ctx_box") { m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port")) m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port")) diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index f6d79d99..e37e67e9 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -1128,8 +1128,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if strings.HasSuffix(key, "bench") { key = key + "." + m.Option("GOOS") + "." + m.Option("GOARCH") } + p := "" + if m.Option("upgrade") == "script" { + p = m.Cmdx("nfs.path", path.Join("usr/script", key)) + } key = strings.Replace(key, ".", "_", -1) - p := m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key)) + if p == "" { + p = m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key)) + } if p == "" { p = m.Cmdx("nfs.path", m.Conf("publish", []string{"list", key})) } diff --git a/src/toolkit/kit.go b/src/toolkit/kit.go index 7f7bfb3b..cfd90f7a 100644 --- a/src/toolkit/kit.go +++ b/src/toolkit/kit.go @@ -204,6 +204,8 @@ func Format(arg ...interface{}) string { result = append(result, fmt.Sprintf("%t", val)) case string: result = append(result, val) + case []byte: + result = append(result, string(val)) case []rune: result = append(result, string(val)) case []string: diff --git a/usr/librarys/chat.css b/usr/librarys/chat.css index 01624f61..ec07f049 100644 --- a/usr/librarys/chat.css +++ b/usr/librarys/chat.css @@ -64,4 +64,5 @@ fieldset.Steam div.create pre:hover { fieldset div.output { clear:both; + max-height:800px; } diff --git a/usr/librarys/example.css b/usr/librarys/example.css index d5911f08..f8303de3 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -15,15 +15,26 @@ fieldset { legend { margin-left:10px; } -fieldset div.output { - padding:6px; +fieldset form.option div { + margin-right:6px; + float:left; +} +fieldset form.option div.hide { + display:none; +} +fieldset form.option div input.args { + width:80px; +} +fieldset form.option div.cmd input.args { + color:white; + background-color: black; + width:160px; } fieldset form.option label { margin-right:6px; } -fieldset form.option div { - margin-right:6px; - float:left; +fieldset div.output { + padding:6px; } fieldset div.output div.item:hover { background-color:red; @@ -40,6 +51,7 @@ fieldset div.output div.code { padding:10px; overflow:auto; border:solid 3px green; + max-height:640px; } fieldset div.output div.code span.red { color:red; diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 08e4cd3a..63b68838 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -494,7 +494,7 @@ function Plugin(field, tool, args, plugin) { item.className = "args" } - var ui = kit.AppendChild(option, [{type: "div", list: [{type: "label", inner: item.label||""}, input]}]) + var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}]) page.plugin = field page.input = ui[name]