From 439d60c124303364609199031ff12785ca4204cf Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sat, 22 Jan 2022 17:40:20 +0800 Subject: [PATCH] opt dream --- base/cli/runtime.go | 15 +++++++++------ base/cli/system.go | 10 ++++++++++ base/web/dream.go | 14 +++++++++----- base/web/serve.go | 1 - base/web/space.go | 6 ++++-- core/code/autogen.go | 1 - core/code/compile.go | 15 ++++++++------- misc/mp/login.go | 1 - 8 files changed, 40 insertions(+), 23 deletions(-) diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 7ad13ad4..1ee07d56 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -16,22 +16,23 @@ import ( ) func _runtime_init(m *ice.Message) { - // 版本信息 + // 版本信息 make kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Make)), func(key string, value interface{}) { m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(key)), value) }) - // 环境变量 + // 环境变量 conf for _, k := range []string{CTX_SHY, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_USER, CTX_SHARE, CTX_RIVER} { m.Conf(RUNTIME, kit.Keys(CONF, k), os.Getenv(k)) } - // 主机信息 + // 主机信息 host m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH) m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS) m.Conf(RUNTIME, kit.Keys(HOST, "pid"), os.Getpid()) + m.Conf(RUNTIME, kit.Keys(HOST, HOME), os.Getenv(HOME)) - // 启动信息 + // 启动信息 boot if name, e := os.Hostname(); e == nil { m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Select(name, os.Getenv("HOSTNAME"))) } @@ -52,16 +53,18 @@ func _runtime_init(m *ice.Message) { ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME)) ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME)) - // 启动次数 + // 启动次数 boot count := kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT))) + 1 m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count) m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), m.Cmdx(SYSTEM, "which", os.Args[0])) - // 节点信息 + // 节点信息 node m.Conf(RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time()) NodeInfo(m, "worker", m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))) runtime.GOMAXPROCS(kit.Int(kit.Select("1", m.Conf(RUNTIME, kit.Keys(HOST, "GOMAXPROCS"))))) + m.Debug("what home %v", os.Getenv(HOME)) + m.Debug("what path %v", os.Getenv(PATH)) } func _runtime_hostinfo(m *ice.Message) { if f, e := os.Open("/proc/cpuinfo"); e == nil { diff --git a/base/cli/system.go b/base/cli/system.go index e37fea5e..1e6394b2 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -5,6 +5,7 @@ import ( "io" "os" "os/exec" + "path" "strings" ice "shylinux.com/x/icebergs" @@ -28,6 +29,15 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd { env := kit.Simple(m.Optionv(CMD_ENV)) for i := 0; i < len(env)-1; i += 2 { cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1])) + if env[i] == PATH { + for _, p := range strings.Split(env[i+1], ice.DF) { + if _, err := os.Stat(path.Join(p, arg[0])); err == nil { + cmd.Path = path.Join(p, arg[0]) + m.Debug("what %v", cmd.Path) + break + } + } + } } if len(cmd.Env) > 0 { m.Log_EXPORT(CMD_ENV, cmd.Env) diff --git a/base/web/dream.go b/base/web/dream.go index 4ada2cae..e217c4f8 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -69,20 +69,20 @@ func _dream_show(m *ice.Message, name string) { return // 已经启动 } } - if m.Richs(SPACE, nil, name, nil) != nil { + if m.Cmd(SPACE, name).Length() > 0 { return // 已经启动 } m.Optionv(cli.CMD_DIR, p) m.Optionv(cli.CMD_ENV, kit.Simple( - cli.CTX_DEV, "http://:"+m.Cmd(SERVE).Append(tcp.PORT), + cli.CTX_DEV, "http://:"+m.Cmd(SERVE, ice.OptionFields("")).Append(tcp.PORT), cli.PATH, kit.Path(path.Join(p, ice.BIN))+":"+kit.Path(ice.BIN)+":"+os.Getenv(cli.PATH), - cli.USER, ice.Info.UserName, m.Configv(cli.ENV), + cli.USER, ice.Info.UserName, cli.HOME, os.Getenv(cli.HOME), m.Configv(cli.ENV), )) m.Optionv(cli.CMD_OUTPUT, path.Join(p, m.Config(kit.Keys(cli.ENV, cli.CTX_LOG)))) // 启动任务 - m.Cmd(cli.DAEMON, m.Configv(ice.CMD), ice.DEV, ice.DEV, mdb.NAME, name, m.OptionSimple(RIVER)) + m.Cmd(cli.DAEMON, "ice.bin", SPACE, tcp.DIAL, ice.DEV, ice.DEV, mdb.NAME, name, m.OptionSimple(RIVER)) defer m.Event(DREAM_CREATE, kit.SimpleKV("", m.Option(mdb.TYPE), name)...) m.Sleep3s() } @@ -100,7 +100,12 @@ func init() { cli.START: {Name: "start name repos river", Help: "启动", Hand: func(m *ice.Message, arg ...string) { _dream_show(m, m.Option(mdb.NAME, kit.Select(path.Base(m.Option(nfs.REPOS)), m.Option(mdb.NAME)))) }}, + DREAM_STOP: {Name: "dream.stop type name", Help: "停止", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) + m.Cmd(DREAM, cli.START, m.OptionSimple(mdb.NAME)) + }}, cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(SPACE, mdb.REMOVE, m.OptionSimple(mdb.NAME)) m.Cmdy(SPACE, m.Option(mdb.NAME), "exit", "0") }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { @@ -117,7 +122,6 @@ func init() { }}, }, Configs: map[string]*ice.Config{ DREAM: {Name: DREAM, Help: "梦想家", Value: kit.Data(nfs.PATH, ice.USR_LOCAL_WORK, - ice.CMD, kit.List("ice.bin", SPACE, tcp.DIAL), cli.ENV, kit.Dict(cli.CTX_LOG, ice.BIN_BOOT_LOG), "miss", `#!/bin/bash if [ "$ISH_CONF_PRE" = "" ]; then diff --git a/base/web/serve.go b/base/web/serve.go index b159f978..48fad8bd 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -145,7 +145,6 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" { msg.Option(ice.MSG_SESSID, sessid) } - msg.Debug("what %v", msg.FormatMeta()) // 参数转换 for k, v := range r.Form { diff --git a/base/web/space.go b/base/web/space.go index 0442bdf1..07730829 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -275,8 +275,9 @@ func init() { args := append([]string{mdb.TYPE, kind, mdb.NAME, name}, m.OptionSimple(SHARE, RIVER)...) m.Go(func() { - h := m.Rich(SPACE, nil, kit.Dict(SOCKET, s, mdb.TEXT, text, args)) - defer m.Confv(SPACE, kit.Keys(mdb.HASH, h), "") + m.Rich(SPACE, nil, kit.Dict(SOCKET, s, mdb.TEXT, text, args)) + // h := m.Rich(SPACE, nil, kit.Dict(SOCKET, s, mdb.TEXT, text, args)) + // defer m.Confv(SPACE, kit.Keys(mdb.HASH, h), "") m.Log_CREATE(SPACE, name, mdb.TYPE, kind) switch kind { @@ -298,6 +299,7 @@ func init() { case WORKER: // 工作节点 m.Event(DREAM_START, args...) defer m.Event(DREAM_STOP, args...) + defer m.Cmd(DREAM, DREAM_STOP, args) default: // 服务节点 m.Event(SPACE_START, args...) defer m.Event(SPACE_STOP, args...) diff --git a/core/code/autogen.go b/core/code/autogen.go index b92a47ca..1bdbc99a 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -179,7 +179,6 @@ func init() { _autogen_source(m, m.Option(mdb.ZONE), m.Option(mdb.NAME)) } m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO))) - m.Debug("what %v", m.FormatMeta()) }}, ssh.SCRIPT: {Name: "script", Help: "脚本:生成 etc/miss.sh", Hand: func(m *ice.Message, arg ...string) { _autogen_miss(m) diff --git a/core/code/compile.go b/core/code/compile.go index 9c612b6a..1b6a3930 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -19,8 +19,7 @@ func init() { COMPILE: {Name: COMPILE, Help: "编译", Value: kit.Data( nfs.PATH, ice.USR_PUBLISH, cli.ENV, kit.Dict( "GOPRIVATE", "shylinux.com,github.com", "GOPROXY", "https://goproxy.cn,direct", - cli.HOME, os.Getenv(cli.HOME), cli.PATH, os.Getenv(cli.PATH), - "GOCACHE", os.Getenv("GOCACHE"), "CGO_ENABLED", "0", + "CGO_ENABLED", "0", ), GO, kit.List(GO, cli.BUILD), )}, }, Commands: map[string]*ice.Command{ @@ -58,11 +57,13 @@ func init() { kit.Keys(kit.Select(ice.ICE, kit.TrimExt(main), main != ice.SRC_MAIN_GO), goos, arch)) } + m.Debug("what home %v", os.Getenv(cli.HOME)) + m.Debug("what path %v", os.Getenv(cli.PATH)) + // 执行编译 _autogen_version(m.Spawn()) - m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.GOOS, goos, cli.GOARCH, arch)) - // if msg := m.Cmd(cli.SYSTEM, m.Configv(GO), "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { - if msg := m.Cmd(cli.SYSTEM, m.Configv(GO), "-v", "-o", file, main, ice.SRC_VERSION_GO); !cli.IsSuccess(msg) { + m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.HOME, os.Getenv(cli.HOME), cli.PATH, os.Getenv(cli.PATH), cli.GOOS, goos, cli.GOARCH, arch)) + if msg := m.Cmd(cli.SYSTEM, "go", "build", "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) { m.Copy(msg) return } @@ -70,8 +71,8 @@ func init() { // 编译成功 m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file) m.Cmdy(nfs.DIR, file, "time,path,size,link,action") - m.Cmdy(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH) - m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE) + m.Cmd(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH) + m.Cmd(PUBLISH, ice.CONTEXTS, ice.CORE) m.StatusTimeCount() }}, }}) diff --git a/misc/mp/login.go b/misc/mp/login.go index 79b7e3cc..c2a0578c 100644 --- a/misc/mp/login.go +++ b/misc/mp/login.go @@ -49,7 +49,6 @@ func init() { }}, aaa.USER: {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) { m.Option(aaa.USERNAME, m.Option(ice.MSG_USERNAME)) - m.Debug("what %v", m.FormatMeta()) m.Cmd(aaa.USER, mdb.MODIFY, aaa.USERNICK, m.Option("nickName"), aaa.USERZONE, MP, aaa.AVATAR, m.Option("avatarUrl"), aaa.GENDER, kit.Select("女", "男", m.Option(aaa.GENDER) == "1"),