forked from x/icebergs
add some
This commit is contained in:
parent
1428dcd427
commit
8360cae3c9
@ -64,7 +64,7 @@ func BinPath(arg ...string) string {
|
|||||||
}
|
}
|
||||||
kit.For(arg, func(p 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))
|
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)) })
|
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -157,9 +157,8 @@ const RUNTIME = "runtime"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
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) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
aaa.White(m, ice.ETC_PATH)
|
|
||||||
aaa.White(m, ice.LICENSE)
|
aaa.White(m, ice.LICENSE)
|
||||||
_runtime_init(m)
|
_runtime_init(m)
|
||||||
}},
|
}},
|
||||||
@ -254,6 +253,9 @@ func init() {
|
|||||||
RESTART: {Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
RESTART: {Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Go(func() { m.Sleep30ms(ice.EXIT, 1) })
|
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) {
|
"logs": {Help: "日志", Hand: func(m *ice.Message, arg ...string) {
|
||||||
OpenCmds(m, kit.Format("cd %s", kit.Path("")), "tail -f var/log/bench.log")
|
OpenCmds(m, kit.Format("cd %s", kit.Path("")), "tail -f var/log/bench.log")
|
||||||
}},
|
}},
|
||||||
|
@ -30,13 +30,11 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if bin == "" && nfs.Exists(m, ice.ETC_PATH) {
|
if bin == "" {
|
||||||
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], EtcPath(m)...); bin != "" {
|
||||||
if bin = _system_find(m, arg[0], strings.Split(text, lex.NL)...); bin != "" {
|
|
||||||
m.Logs(FIND, "etcpath cmd", bin)
|
m.Logs(FIND, "etcpath cmd", bin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if bin == "" {
|
if bin == "" {
|
||||||
if bin = _system_find(m, arg[0], m.Option(CMD_DIR), ice.BIN, nfs.PWD); bin != "" {
|
if bin = _system_find(m, arg[0], m.Option(CMD_DIR), ice.BIN, nfs.PWD); bin != "" {
|
||||||
m.Logs(FIND, "contexts cmd", bin)
|
m.Logs(FIND, "contexts cmd", bin)
|
||||||
@ -156,11 +154,11 @@ func init() {
|
|||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
SYSTEM: {Name: "system cmd", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
|
SYSTEM: {Name: "system cmd", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
|
||||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
for _, p := range arg {
|
kit.For(arg, func(p string) {
|
||||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
|
kit.If(!kit.IsIn(p, EtcPath(m)...), func() {
|
||||||
m.Cmd(nfs.PUSH, ice.ETC_PATH, strings.TrimSpace(p)+lex.NL)
|
m.Cmd(nfs.PUSH, ice.ETC_PATH, strings.TrimSpace(p)+lex.NL)
|
||||||
}
|
})
|
||||||
}
|
})
|
||||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||||
}},
|
}},
|
||||||
FIND: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_system_find(m, arg[0], arg[1:]...)) }},
|
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 {
|
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, EtcPath(m)...)
|
||||||
dir = append(dir, strings.Split(text, lex.NL)...)
|
|
||||||
}
|
|
||||||
return _system_find(m, bin, append(dir, _path_split(kit.Env(PATH))...)...)
|
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)) }
|
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)
|
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" }
|
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
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
"shylinux.com/x/icebergs/base/lex"
|
||||||
@ -115,6 +116,9 @@ func init() {
|
|||||||
ice.Info.Traceid = "short"
|
ice.Info.Traceid = "short"
|
||||||
ice.Pulse.Option(ice.LOG_TRACEID, Traceid())
|
ice.Pulse.Option(ice.LOG_TRACEID, Traceid())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _trace_count int64
|
||||||
|
|
||||||
func Traceid() (traceid string) {
|
func Traceid() (traceid string) {
|
||||||
ls := []string{}
|
ls := []string{}
|
||||||
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
|
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
|
||||||
@ -129,5 +133,8 @@ func Traceid() (traceid string) {
|
|||||||
ls = ls[:0]
|
ls = ls[:0]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
kit.If(len(ls) > 0, func() {
|
||||||
|
ls = append(ls, kit.Format(atomic.AddInt64(&_trace_count, 1)))
|
||||||
|
})
|
||||||
return strings.Join(ls, "-")
|
return strings.Join(ls, "-")
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
"shylinux.com/x/icebergs/base/ctx"
|
"shylinux.com/x/icebergs/base/ctx"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
"shylinux.com/x/icebergs/base/lex"
|
||||||
|
"shylinux.com/x/icebergs/base/log"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
"shylinux.com/x/icebergs/base/tcp"
|
"shylinux.com/x/icebergs/base/tcp"
|
||||||
@ -95,6 +96,7 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
msg := m.Spawn(f.target)
|
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() {
|
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
|
||||||
msg.SetResult().Cmdy(cli.SYSTEM, ls)
|
msg.SetResult().Cmdy(cli.SYSTEM, ls)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
@ -12,10 +13,8 @@ const ADMIN = "admin"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
ADMIN: {Name: "admin index list", Help: "管理", Hand: func(m *ice.Message, arg ...string) {
|
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.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+path.Join(arg...))
|
||||||
m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, CHAT_CMD+arg[0], args)
|
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
2
init.go
2
init.go
@ -59,7 +59,7 @@ var Index = &Context{Name: ICE, Help: "冰山模块", Commands: Commands{
|
|||||||
loadImportant(m)
|
loadImportant(m)
|
||||||
}},
|
}},
|
||||||
QUIT: {Hand: func(m *Message, arg ...string) {
|
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) {
|
EXIT: {Hand: func(m *Message, arg ...string) {
|
||||||
m.Go(func() {
|
m.Go(func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user