forked from x/icebergs
opt some
This commit is contained in:
parent
5b0a86f019
commit
93e32aa8a0
@ -62,8 +62,7 @@ func init() {
|
||||
defer logs.Println(ice.EXIT)
|
||||
break
|
||||
}
|
||||
m.Sleep("1s")
|
||||
if logs.Println(); m.Config("log.save") == ice.TRUE {
|
||||
if logs.Println(); m.Sleep("1s").Config("log.save") == ice.TRUE {
|
||||
back := kit.Format("var/log.%s", logs.Now().Format("20060102_150405"))
|
||||
m.Cmd(SYSTEM, "cp", "-r", "var/log", back, ice.Maps{CMD_OUTPUT: ""})
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ func _runtime_init(m *ice.Message) {
|
||||
for _, k := range ENV_LIST {
|
||||
switch m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)); k {
|
||||
case CTX_PID:
|
||||
ice.Info.PidPath = kit.Select(path.Join(ice.VAR_LOG, ice.ICE_PID), kit.Env(k))
|
||||
// ice.Info.PidPath = kit.Select(path.Join(ice.VAR_LOG, ice.ICE_PID), kit.Env(k))
|
||||
ice.Info.PidPath = kit.Env(k)
|
||||
case CTX_SHARE:
|
||||
ice.Info.CtxShare = kit.Env(k)
|
||||
case CTX_RIVER:
|
||||
|
@ -27,6 +27,9 @@ func _signal_process(m *ice.Message, p string, s os.Signal) {
|
||||
if p == "" {
|
||||
b, _ := file.ReadFile(ice.Info.PidPath)
|
||||
p = string(b)
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
}
|
||||
if p, e := os.FindProcess(kit.Int(kit.Select(kit.Format(os.Getpid()), p))); e == nil {
|
||||
p.Signal(s)
|
||||
@ -55,6 +58,9 @@ func init() {
|
||||
}
|
||||
_signal_listen(m, 2, mdb.NAME, "重启", ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, "退出", ice.CMD, "exit 0")
|
||||
if ice.Info.PidPath == "" {
|
||||
return
|
||||
}
|
||||
if f, p, e := logs.CreateFile(ice.Info.PidPath); e == nil {
|
||||
defer f.Close()
|
||||
fmt.Fprint(f, os.Getpid())
|
||||
|
@ -81,7 +81,6 @@ const (
|
||||
)
|
||||
const (
|
||||
BENCH = "bench"
|
||||
TRACE = "trace"
|
||||
)
|
||||
const (
|
||||
FILE = "file"
|
||||
@ -93,11 +92,9 @@ const LOG = "log"
|
||||
var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}),
|
||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{
|
||||
mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT,
|
||||
}),
|
||||
DEBUG, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "debug.log"), mdb.LIST, []string{ice.LOG_DEBUG}),
|
||||
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "error.log"), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
|
||||
TRACE, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "trace.log"), mdb.LIST, []string{ice.LOG_DEBUG}),
|
||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT}),
|
||||
)},
|
||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_START, ice.LOG_CMDS}),
|
||||
@ -107,9 +104,6 @@ var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||
}, Commands: ice.Commands{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Confm(VIEW, nil, func(key string, value ice.Map) {
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
||||
})
|
||||
m.Confm(FILE, nil, func(key string, value ice.Map) {
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, FILE), key) })
|
||||
if f, p, e := logs.CreateFile(kit.Format(value[nfs.PATH])); e == nil {
|
||||
@ -118,6 +112,9 @@ var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
m.Logs(mdb.CREATE, nfs.FILE, p)
|
||||
}
|
||||
})
|
||||
m.Confm(VIEW, nil, func(key string, value ice.Map) {
|
||||
kit.Fetch(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
}}
|
||||
|
12
init.go
12
init.go
@ -92,8 +92,12 @@ func Run(arg ...string) string {
|
||||
if len(arg) == 0 && len(os.Args) > 1 {
|
||||
arg = kit.Simple(os.Args[1:], kit.Split(kit.Env(CTX_ARG)))
|
||||
}
|
||||
if len(arg) == 0 && runtime.GOOS == "windows" {
|
||||
arg = append(arg, SERVE, START, DEV, DEV)
|
||||
if len(arg) == 0 {
|
||||
if runtime.GOOS == "windows" {
|
||||
arg = append(arg, SERVE, START, DEV, DEV)
|
||||
} else {
|
||||
arg = append(arg, "forever", START, DEV, DEV)
|
||||
}
|
||||
}
|
||||
Pulse.meta[MSG_DETAIL] = arg
|
||||
kit.Fetch(kit.Sort(os.Environ()), func(env string) {
|
||||
@ -102,14 +106,12 @@ func Run(arg ...string) string {
|
||||
}
|
||||
})
|
||||
time.Local = time.FixedZone("Beijing", 28800)
|
||||
Pulse.time = time.Now()
|
||||
if Pulse._cmd == nil {
|
||||
if Pulse.time = time.Now(); Pulse._cmd == nil {
|
||||
Pulse._cmd = &Command{RawHand: logs.FileLines(3)}
|
||||
}
|
||||
switch Index.Merge(Index).Begin(Pulse, arg...); kit.Select("", arg, 0) {
|
||||
case SERVE, SPACE:
|
||||
if os.Getenv("ctx_log") == "" {
|
||||
// logs.Disable(true)
|
||||
// os.Stderr.Close()
|
||||
}
|
||||
if Index.Start(Pulse, arg...) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user