1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt boot.sh

This commit is contained in:
shaoying 2019-06-16 04:04:35 +08:00
parent 607635523a
commit ad59a74939
6 changed files with 64 additions and 34 deletions

View File

@ -19,16 +19,19 @@ log() {
echo -e $*
}
install() {
md5=md5sum
case `uname -s` in
"Darwin") GOOS=darwin GOARCH=amd64;;
"Darwin") GOOS=darwin GOARCH=amd64 md5=md5;;
*) GOOS=linux GOARCH=386;;
esac
case `uname -m` in
"x86_64") GOARCH=amd64;;
"armv7l") GOARCH=arm;;
esac
wget -O ${ctx_app} "$ctx_dev/publish/${ctx_app}?GOOS=$GOOS&GOARCH=$GOARCH" && chmod a+x ${ctx_app} \
&& ./${ctx_app} upgrade system && md5sum ${ctx_app} \
&& ./${ctx_app} upgrade system \
&& ${md5} ${ctx_app} \
&& mv ${ctx_app} bin/${ctx_app}
}
main() {
@ -38,8 +41,8 @@ main() {
done
}
action() {
pid=$(cat var/run/bench.log)
log "kill" $1 && kill -$1 ${pid}
pid=$(cat var/run/bench.pid)
log "kill" $1 $pid && kill -$1 ${pid}
}
@ -51,8 +54,9 @@ case $1 in
install) install "$@";;
start|"") main "$@";;
create) mkdir -p $2; cd $2 && shift && shift && main "$@";;
upgrade) action USR2;;
restart) action USR1;;
stop) action QUIT;;
restart) action 30;;
upgrade) action 31;;
quit) action QUIT;;
term) action TERM;;
esac

View File

@ -578,18 +578,29 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Table()
if restart {
m.Cmd("cli.quit", 1)
m.Cmd("cli.quit", 2)
}
return
}},
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Cmd("cli.source", m.Conf("system", "script.exit"))
m.Append("directory", "")
m.Echo("wait 1s, restarting...")
code := kit.Select("0", arg, 0)
switch code {
case "0":
m.Cmd("cli.source", m.Conf("system", "script.exit"))
m.Echo("quit")
case "1":
m.Echo("term")
case "2":
m.Cmd("cli.source", m.Conf("system", "script.exit"))
m.Echo("restart")
}
m.Append("directory", "")
m.Echo(", wait 1s")
m.GoFunc(m, func(m *ctx.Message) {
time.Sleep(time.Second * 1)
os.Exit(kit.Int(kit.Select("0", arg, 0)))
os.Exit(kit.Int(code))
})
return
}},
@ -676,7 +687,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
if !strings.HasPrefix(text, "sess") && m.Options("remote") {
text = m.Current(text)
}
kit.Log("fuck", "what %v", text)
// 解析代码片段
m.Sess("yac").Call(func(msg *ctx.Message) *ctx.Message {

View File

@ -1280,12 +1280,12 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message))
}
func (m *Message) GoFunc(msg *Message, hand ...func(msg *Message)) *Message {
go func() {
ngo := msg.Option("routine", m.Capi("ngo", 1))
msg.Log("info", "%v safe go begin", ngo)
kit.Log("error", "%s ngo %s start", msg.Format(), ngo)
msg.Option("routine", m.Capi("ngo", 1))
// msg.Log("info", "%v safe go begin", ngo)
// kit.Log("error", "%s ngo %s start", msg.Format(), ngo)
m.TryCatch(msg, true, hand...)
kit.Log("error", "%s ngo %s end", msg.Format(), ngo)
msg.Log("info", "%v safe go end", ngo)
// kit.Log("error", "%s ngo %s end", msg.Format(), ngo)
// msg.Log("info", "%v safe go end", ngo)
}()
return m
}

View File

@ -43,11 +43,11 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool {
Pulse.Option("log.disable", false)
m.Cap("stream", "shy")
m.Cmd("log._init")
m.Cmd("gdb._init")
m.Cmd("yac._init")
return false
m.Cmd("gdb._init")
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
} else {
m.Cmd("yac._init")
for _, v := range m.Spawn().Cmd(arg).Meta["result"] {
fmt.Printf("%s", v)
}

View File

@ -2,6 +2,7 @@ package gdb
import (
"contexts/ctx"
"time"
"toolkit"
"os"
@ -36,6 +37,9 @@ func (gdb *GDB) Value(m *ctx.Message, arg ...interface{}) bool {
return false
}
func (gdb *GDB) Wait(msg *ctx.Message, arg ...interface{}) interface{} {
if !kit.EnableDebug {
return nil
}
m := gdb.Message()
if m.Cap("status") != "start" {
return nil
@ -94,15 +98,24 @@ func (gdb *GDB) Start(m *ctx.Message, arg ...string) bool {
case sig := <-gdb.goon:
action := m.Conf("signal", sig)
m.Log("signal", "%v: %v", action, sig)
break
switch action {
case "segv":
case "quit":
m.Cmd("cli.exit", 0)
case "QUIT":
m.Cmd("cli.quit", 0)
case "TERM":
m.Cmd("cli.quit", 1)
case "restart":
m.Cmd("cli.exit", 1)
m.Cmd("cli.quit", 2)
case "upgrade":
m.Find("web.code").Cmd("upgrade", "system")
m.Cmd("cli.upgrade", "bench")
m.Cmd("cli.upgrade", "system")
case "WINCH":
m.Cmd("nfs.term", "init")
case "TRAP":
kit.EnableDebug = true
case "CONT":
gdb.wait <- time.Now().Format("2006-01-02 15:04:05")
case "TSTP":
kit.EnableDebug = false
default:
// gdb.Goon(nil, "cache", "read", "value")
}
@ -123,31 +136,33 @@ var Index = &ctx.Context{Name: "gdb", Help: "调试中心",
Configs: map[string]*ctx.Config{
"logpid": &ctx.Config{Name: "logpid", Value: "var/run/bench.pid", Help: ""},
"signal": &ctx.Config{Name: "signal", Value: map[string]interface{}{
"1": "HUP",
"2": "INT",
"3": "QUIT",
"15": "TERM",
"28": "WINCH",
"30": "USR1",
"31": "USR2",
"30": "restart",
"31": "upgrade",
"1": "HUP",
// "2": "INT",
// "9": "KILL",
// "10": "BUS",
// "11": "SEGV",
// "17": "STOP",
// "23": "IO",
"5": "TRAP",
"6": "ABRT",
"18": "TSTP",
"19": "CONT",
"6": "ABRT",
"14": "ALRM",
"20": "CHLD",
"19": "CONT",
"18": "TSTP",
"21": "TTIN",
"22": "TTOUT",
"13": "PIPE",
"16": "URG",
"23": "IO",
"4": "ILL",
"7": "EMT",

View File

@ -17,6 +17,7 @@ import (
)
var DisableLog = false
var EnableDebug = false
func Log(action string, str string, args ...interface{}) {
if DisableLog {