1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

add forever

This commit is contained in:
harveyshao 2022-02-12 15:20:38 +08:00
parent 10c8d7b799
commit a3acc9deb3
9 changed files with 64 additions and 23 deletions

View File

@ -45,13 +45,10 @@ func _user_search(m *ice.Message, name, text string) {
func UserRoot(m *ice.Message, arg ...string) { // password username userrole
userrole := kit.Select(ROOT, arg, 2)
username := kit.Select(kit.Select("shy", ice.Info.UserName), arg, 1)
username := kit.Select(kit.Select("root", ice.Info.UserName), arg, 1)
m.Option(ice.MSG_USERROLE, userrole)
m.Option(ice.MSG_USERNAME, username)
if !_user_exists(m, username) {
_user_create(m, userrole, username, kit.Select("", arg, 0))
}
_user_create(m, userrole, username, kit.Select("", arg, 0))
}
func UserRole(m *ice.Message, username interface{}) (role string) {
if role = VOID; username == ice.Info.UserName {

View File

@ -6,4 +6,4 @@ const CLI = "cli"
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE) }
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE, FOREVER) }

39
base/cli/forever.go Normal file
View File

@ -0,0 +1,39 @@
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")
}
}
}}},
})
}

View File

@ -37,7 +37,7 @@ func _runtime_init(m *ice.Message) {
if ls := kit.Split(text, "="); len(ls) > 1 {
switch ls[0] {
case "ID", "ID_LIKE":
osid = strings.TrimSpace(osid + ice.SP + ls[1])
osid = strings.TrimSpace(ls[1] + ice.SP + osid)
}
}
})

View File

@ -180,7 +180,6 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr
if msg.Option(ice.MSG_USERNAME) == "" && msg.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) {
aaa.UserRoot(msg) // 主机认证
msg.Debug("what %v", msg.FormatMeta())
}
if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" {

View File

@ -63,8 +63,6 @@ func init() {
// 执行编译
_autogen_version(m.Spawn())
m.Optionv(cli.CMD_ENV, kit.Simple(m.Configv(cli.ENV), cli.HOME, os.Getenv(cli.HOME), cli.PATH, os.Getenv(cli.PATH), cli.GOOS, goos, cli.GOARCH, arch))
m.Debug("what %v", os.Getenv(cli.PATH))
m.Debug("what %v", m.FormatMeta())
if msg := m.Cmd(cli.SYSTEM, "go", "build", "-o", file, main, ice.SRC_VERSION_GO, ice.SRC_BINPACK_GO); !cli.IsSuccess(msg) {
m.Copy(msg)
return
@ -73,8 +71,12 @@ func init() {
// 编译成功
m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file)
m.Cmdy(nfs.DIR, file, "time,path,size,link,action")
name := path.Base(m.Append(nfs.PATH))
m.EchoScript(kit.Format("# 下载启动\ncurl -fOL %s && chmod u+x %s\n./%s forever serve dev %s\ntail -f var/log/bench.log",
m.MergeURL2(kit.Format("/publish/%s", name)), name, name, m.MergeURL2(ice.PS)))
m.Cmd(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH)
m.Cmd(PUBLISH, ice.CONTEXTS, ice.CORE)
m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE)
m.Cmdy(PUBLISH, ice.CONTEXTS, "binary")
m.StatusTimeCount()
}},
}})

View File

@ -179,17 +179,15 @@ func init() {
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
web.PushStream(m)
defer m.ProcessHold()
defer m.ToastSuccess()
osid := m.Cmdx(cli.RUNTIME, "host.OSID")
switch {
case strings.Contains(osid, cli.CENTOS):
m.Cmd(cli.SYSTEM, "yum", "install", "-y", "git", "golang")
case strings.Contains(osid, cli.UBUNTU):
m.Cmd(cli.SYSTEM, "apt", "install", "-y", "git", "golang")
case strings.Contains(osid, cli.ALPINE):
m.Cmd(cli.SYSTEM, "apk", "add", "git", "go")
default:
m.Toast("please install git and go")
}
m.ToastSuccess()
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch len(arg) {

View File

@ -102,7 +102,7 @@ echo "hello world"
m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1)))
if len(arg) == 0 {
arg = append(arg, "misc", "core", "base", "project", "binary", "source")
arg = append(arg, "core", "binary")
}
for _, k := range arg {
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
@ -159,20 +159,21 @@ echo "hello world"
}
var _contexts = kit.Dict(
"binary", `# 官方启动
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp binary
`,
"core", `# 脚本启动
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app
`,
"source", `# 下载源码
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp source
`,
"binary", `# 安装应用
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp binary
`,
"project", `# 创建项目
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
`,
"base", `# 开发环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
`,
"core", `# 生产环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp app
`,
"misc", `# 终端环境
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp

View File

@ -189,6 +189,7 @@ const (
COMMIT = "commit"
COMMENT = "comment"
VERSION = "version"
STASH = "stash"
)
const STATUS = "status"
@ -227,6 +228,10 @@ func init() {
_repos_cmd(m, m.Option(REPOS), TAG, m.Option(VERSION))
_repos_cmd(m, m.Option(REPOS), PUSH, "--tags")
}},
STASH: {Name: "stash", Help: "缓存", Hand: func(m *ice.Message, arg ...string) {
_status_each(m, STASH, cli.SYSTEM, GIT, STASH)
m.ProcessHold()
}},
ADD: {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
_repos_cmd(m, m.Option(REPOS), ADD, m.Option(nfs.FILE))
}}, OPT: {Name: "opt", Help: "优化"}, PRO: {Name: "pro", Help: "升级"},