1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-10-12 22:10:31 +08:00
parent 1428dcd427
commit 8360cae3c9
8 changed files with 45 additions and 20 deletions

View File

@ -64,7 +64,7 @@ func BinPath(arg ...string) string {
}
kit.For(arg, func(p string) {
list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN))
kit.For(kit.Reverse(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), lex.NL)), func(l string) {
kit.For(kit.Reverse(EtcPath(ice.Pulse)), func(l string) {
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
})
})

View File

@ -157,9 +157,8 @@ const RUNTIME = "runtime"
func init() {
Index.MergeCommands(ice.Commands{
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade restart logs conf", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procstat,procinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain,routine auto upgrade restart reboot logs conf", Icon: "Infomation.png", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
aaa.White(m, ice.ETC_PATH)
aaa.White(m, ice.LICENSE)
_runtime_init(m)
}},
@ -254,6 +253,9 @@ func init() {
RESTART: {Help: "重启", Hand: func(m *ice.Message, arg ...string) {
m.Go(func() { m.Sleep30ms(ice.EXIT, 1) })
}},
"reboot": {Help: "清空", Hand: func(m *ice.Message, arg ...string) {
m.Go(func() { m.Sleep30ms(ice.QUIT, 1) })
}},
"logs": {Help: "日志", Hand: func(m *ice.Message, arg ...string) {
OpenCmds(m, kit.Format("cd %s", kit.Path("")), "tail -f var/log/bench.log")
}},

View File

@ -30,11 +30,9 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
}
}
})
if bin == "" && nfs.Exists(m, ice.ETC_PATH) {
if text := m.Cmdx(nfs.CAT, ice.ETC_PATH, kit.Dict(aaa.UserRole, aaa.ROOT)); len(text) > 0 {
if bin = _system_find(m, arg[0], strings.Split(text, lex.NL)...); bin != "" {
m.Logs(FIND, "etcpath cmd", bin)
}
if bin == "" {
if bin = _system_find(m, arg[0], EtcPath(m)...); bin != "" {
m.Logs(FIND, "etcpath cmd", bin)
}
}
if bin == "" {
@ -156,11 +154,11 @@ func init() {
Index.MergeCommands(ice.Commands{
SYSTEM: {Name: "system cmd", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
for _, p := range arg {
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
kit.For(arg, func(p string) {
kit.If(!kit.IsIn(p, EtcPath(m)...), func() {
m.Cmd(nfs.PUSH, ice.ETC_PATH, strings.TrimSpace(p)+lex.NL)
}
}
})
})
m.Cmdy(nfs.CAT, ice.ETC_PATH)
}},
FIND: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_system_find(m, arg[0], arg[1:]...)) }},
@ -180,9 +178,7 @@ func init() {
}
func SystemFind(m *ice.Message, bin string, dir ...string) string {
if text := m.Cmdx(nfs.CAT, ice.ETC_PATH); len(text) > 0 {
dir = append(dir, strings.Split(text, lex.NL)...)
}
dir = append(dir, EtcPath(m)...)
return _system_find(m, bin, append(dir, _path_split(kit.Env(PATH))...)...)
}
func SystemExec(m *ice.Message, arg ...string) string { return strings.TrimSpace(m.Cmdx(SYSTEM, arg)) }
@ -190,3 +186,20 @@ func SystemCmds(m *ice.Message, cmds string, args ...ice.Any) string {
return strings.TrimRight(m.Cmdx(SYSTEM, "sh", "-c", kit.Format(cmds, args...), ice.Option{CMD_OUTPUT, ""}), lex.NL)
}
func IsSuccess(m *ice.Message) bool { return m.Append(CODE) == "" || m.Append(CODE) == "0" }
var _cache_path []string
func EtcPath(m *ice.Message) (res []string) {
if len(_cache_path) > 0 {
return _cache_path
}
nfs.Exists(m, ice.ETC_PATH, func(p string) {
kit.For(strings.Split(m.Cmdx(nfs.CAT, p, kit.Dict(aaa.UserRole, aaa.ROOT)), lex.NL), func(p string) {
kit.If(p != "" && !strings.HasPrefix(p, "# "), func() {
res = append(res, p)
})
})
})
_cache_path = res
return
}

View File

@ -5,6 +5,7 @@ import (
"fmt"
"path"
"strings"
"sync/atomic"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/lex"
@ -115,6 +116,9 @@ func init() {
ice.Info.Traceid = "short"
ice.Pulse.Option(ice.LOG_TRACEID, Traceid())
}
var _trace_count int64
func Traceid() (traceid string) {
ls := []string{}
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
@ -129,5 +133,8 @@ func Traceid() (traceid string) {
ls = ls[:0]
}
})
kit.If(len(ls) > 0, func() {
ls = append(ls, kit.Format(atomic.AddInt64(&_trace_count, 1)))
})
return strings.Join(ls, "-")
}

View File

@ -14,6 +14,7 @@ import (
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/log"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
@ -95,6 +96,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
return ""
}
msg := m.Spawn(f.target)
kit.If(h == STDIO, func() { msg.Option(ice.LOG_TRACEID, log.Traceid()) })
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
msg.SetResult().Cmdy(cli.SYSTEM, ls)
}

View File

@ -2,6 +2,7 @@ package web
import (
"net/http"
"path"
ice "shylinux.com/x/icebergs"
kit "shylinux.com/x/toolkits"
@ -12,10 +13,8 @@ const ADMIN = "admin"
func init() {
Index.MergeCommands(ice.Commands{
ADMIN: {Name: "admin index list", Help: "管理", Hand: func(m *ice.Message, arg ...string) {
args := []string{}
kit.If(len(arg) == 0, func() { arg = append(arg, SPACE, DOMAIN) })
kit.For(arg[1:], func(v string) { args = append(args, ice.ARG, v) })
m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, CHAT_CMD+arg[0], args)
m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, CHAT_CMD+path.Join(arg...))
}},
})
}

View File

@ -59,7 +59,7 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Commands: Commands{
loadImportant(m)
}},
QUIT: {Hand: func(m *Message, arg ...string) {
m.Go(func() { m.Sleep30ms(); os.Exit(0) })
m.Go(func() { m.Sleep30ms(); os.Exit(kit.Int(kit.Select("0", arg, 0))) })
}},
EXIT: {Hand: func(m *Message, arg ...string) {
m.Go(func() {

View File

@ -26,7 +26,9 @@ func (m *Message) join(arg ...Any) (string, []Any) {
i--
continue
case []string:
list = append(list, kit.JoinKV(DF+SP, SP, v...))
if len(v) > 0 {
list = append(list, kit.JoinKV(DF+SP, SP, v...))
}
i--
continue
}