mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
add forever
This commit is contained in:
parent
10c8d7b799
commit
a3acc9deb3
@ -45,13 +45,10 @@ func _user_search(m *ice.Message, name, text string) {
|
|||||||
|
|
||||||
func UserRoot(m *ice.Message, arg ...string) { // password username userrole
|
func UserRoot(m *ice.Message, arg ...string) { // password username userrole
|
||||||
userrole := kit.Select(ROOT, arg, 2)
|
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_USERROLE, userrole)
|
||||||
m.Option(ice.MSG_USERNAME, username)
|
m.Option(ice.MSG_USERNAME, username)
|
||||||
|
_user_create(m, userrole, username, kit.Select("", arg, 0))
|
||||||
if !_user_exists(m, username) {
|
|
||||||
_user_create(m, userrole, username, kit.Select("", arg, 0))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
func UserRole(m *ice.Message, username interface{}) (role string) {
|
func UserRole(m *ice.Message, username interface{}) (role string) {
|
||||||
if role = VOID; username == ice.Info.UserName {
|
if role = VOID; username == ice.Info.UserName {
|
||||||
|
@ -6,4 +6,4 @@ const CLI = "cli"
|
|||||||
|
|
||||||
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
|
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
39
base/cli/forever.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}},
|
||||||
|
})
|
||||||
|
}
|
@ -37,7 +37,7 @@ func _runtime_init(m *ice.Message) {
|
|||||||
if ls := kit.Split(text, "="); len(ls) > 1 {
|
if ls := kit.Split(text, "="); len(ls) > 1 {
|
||||||
switch ls[0] {
|
switch ls[0] {
|
||||||
case "ID", "ID_LIKE":
|
case "ID", "ID_LIKE":
|
||||||
osid = strings.TrimSpace(osid + ice.SP + ls[1])
|
osid = strings.TrimSpace(ls[1] + ice.SP + osid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -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)) {
|
if msg.Option(ice.MSG_USERNAME) == "" && msg.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) {
|
||||||
aaa.UserRoot(msg) // 主机认证
|
aaa.UserRoot(msg) // 主机认证
|
||||||
msg.Debug("what %v", msg.FormatMeta())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" {
|
if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" {
|
||||||
|
@ -63,8 +63,6 @@ func init() {
|
|||||||
// 执行编译
|
// 执行编译
|
||||||
_autogen_version(m.Spawn())
|
_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.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) {
|
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)
|
m.Copy(msg)
|
||||||
return
|
return
|
||||||
@ -73,8 +71,12 @@ func init() {
|
|||||||
// 编译成功
|
// 编译成功
|
||||||
m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file)
|
m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file)
|
||||||
m.Cmdy(nfs.DIR, file, "time,path,size,link,action")
|
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, 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()
|
m.StatusTimeCount()
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
@ -179,17 +179,15 @@ func init() {
|
|||||||
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||||
web.PushStream(m)
|
web.PushStream(m)
|
||||||
defer m.ProcessHold()
|
defer m.ProcessHold()
|
||||||
defer m.ToastSuccess()
|
|
||||||
|
|
||||||
osid := m.Cmdx(cli.RUNTIME, "host.OSID")
|
osid := m.Cmdx(cli.RUNTIME, "host.OSID")
|
||||||
switch {
|
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):
|
case strings.Contains(osid, cli.ALPINE):
|
||||||
m.Cmd(cli.SYSTEM, "apk", "add", "git", "go")
|
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) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
switch len(arg) {
|
switch len(arg) {
|
||||||
|
@ -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)))
|
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 {
|
if len(arg) == 0 {
|
||||||
arg = append(arg, "misc", "core", "base", "project", "binary", "source")
|
arg = append(arg, "core", "binary")
|
||||||
}
|
}
|
||||||
for _, k := range arg {
|
for _, k := range arg {
|
||||||
if buf, err := kit.Render(m.Config(kit.Keys(ice.CONTEXTS, k)), m); m.Assert(err) {
|
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(
|
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", `# 下载源码
|
"source", `# 下载源码
|
||||||
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp 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", `# 创建项目
|
"project", `# 创建项目
|
||||||
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
|
ctx_temp=$(mktemp); curl -fsSL https://shylinux.com -o $ctx_temp; source $ctx_temp project
|
||||||
`,
|
`,
|
||||||
"base", `# 开发环境
|
"base", `# 开发环境
|
||||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp dev
|
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", `# 终端环境
|
"misc", `# 终端环境
|
||||||
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp
|
export ctx_dev={{.Option "httphost"}}; ctx_temp=$(mktemp); curl -fsSL $ctx_dev -o $ctx_temp; source $ctx_temp
|
||||||
|
@ -189,6 +189,7 @@ const (
|
|||||||
COMMIT = "commit"
|
COMMIT = "commit"
|
||||||
COMMENT = "comment"
|
COMMENT = "comment"
|
||||||
VERSION = "version"
|
VERSION = "version"
|
||||||
|
STASH = "stash"
|
||||||
)
|
)
|
||||||
const STATUS = "status"
|
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), TAG, m.Option(VERSION))
|
||||||
_repos_cmd(m, m.Option(REPOS), PUSH, "--tags")
|
_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) {
|
ADD: {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_repos_cmd(m, m.Option(REPOS), ADD, m.Option(nfs.FILE))
|
_repos_cmd(m, m.Option(REPOS), ADD, m.Option(nfs.FILE))
|
||||||
}}, OPT: {Name: "opt", Help: "优化"}, PRO: {Name: "pro", Help: "升级"},
|
}}, OPT: {Name: "opt", Help: "优化"}, PRO: {Name: "pro", Help: "升级"},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user