1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 09:34:05 +08:00
icebergs/base/cli/forever.go
2022-02-12 15:20:38 +08:00

40 lines
1.0 KiB
Go

package cli
import (
"os"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/nfs"
kit "shylinux.com/x/toolkits"
)
const FOREVER = "forever"
func init() {
const SERVE = "serve"
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
FOREVER: {Name: "forever", Help: "启动", Action: map[string]*ice.Action{
SERVE: {Name: "serve", Help: "服务", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(FOREVER, os.Args[0], SERVE, START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
for {
if arg[1] == SERVE {
if _, e := os.Stat(ice.BIN_ICE_BIN); e == nil {
arg[0] = nfs.PWD + ice.BIN_ICE_BIN
}
}
println(kit.Format("%s run %s", kit.Now(), kit.Join(arg, ice.SP)))
switch msg := m.Cmd(SYSTEM, arg); msg.Append(CODE) {
case "0":
println(kit.Format("%s exit", kit.Now()))
return
default:
m.Sleep("1s")
}
}
}}},
})
}