mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt node.sh
This commit is contained in:
parent
227b3475d1
commit
78df5d2ba3
@ -20,6 +20,10 @@ log() {
|
|||||||
echo -e $*
|
echo -e $*
|
||||||
}
|
}
|
||||||
install() {
|
install() {
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
mkdir $1; cd $1
|
||||||
|
fi
|
||||||
|
|
||||||
md5=md5sum
|
md5=md5sum
|
||||||
case `uname -s` in
|
case `uname -s` in
|
||||||
"Darwin") GOOS=darwin GOARCH=amd64 md5=md5;;
|
"Darwin") GOOS=darwin GOARCH=amd64 md5=md5;;
|
||||||
@ -51,7 +55,7 @@ dir=./ && [ -d "$1" ] && dir=$1 && shift
|
|||||||
log "dev:$ctx_dev\ndir: $dir\nbin: $ctx_bin\n"
|
log "dev:$ctx_dev\ndir: $dir\nbin: $ctx_bin\n"
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
install) install "$@";;
|
install) shift && install "$@";;
|
||||||
start|"") main "$@";;
|
start|"") main "$@";;
|
||||||
create) mkdir -p $2; cd $2 && shift && shift && main "$@";;
|
create) mkdir -p $2; cd $2 && shift && shift && main "$@";;
|
||||||
restart) action 30;;
|
restart) action 30;;
|
||||||
|
28
bin/node.sh
28
bin/node.sh
@ -1,31 +1,5 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
export ctx_box=${ctx_box:="http://localhost:9094"}
|
export ctx_box=${ctx_box:="http://localhost:9094"}
|
||||||
export ctx_root="/usr/local/context"
|
|
||||||
export ctx_home=~/context
|
|
||||||
|
|
||||||
ctx_bin="bench" && [ -e bin/bench ] && ctx_bin=bin/bench
|
|
||||||
export ctx_bin
|
|
||||||
|
|
||||||
log() {
|
|
||||||
echo -e $*
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
|
||||||
mkdir -p bin etc usr
|
|
||||||
mkdir -p var/run var/log var/tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
while true; do
|
|
||||||
$ctx_bin "$@" 2>var/log/boot.log && break
|
|
||||||
log "restarting..." && sleep 3
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
case $1 in
|
|
||||||
create) mkdir -p $2; cd $2 && shift && shift && prepare && main "$@";;
|
|
||||||
init) shift; prepare && main "$@";;
|
|
||||||
*) mkdir -p var/run var/log && main "$@";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
[ -f bin/boot.sh ] && source bin/boot.sh || source boot.sh
|
||||||
|
@ -141,11 +141,14 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"init_shy": "etc/init.shy",
|
"init_shy": "etc/init.shy",
|
||||||
"common_shy": "etc/common.shy",
|
"common_shy": "etc/common.shy",
|
||||||
"exit_shy": "etc/exit.shy",
|
"exit_shy": "etc/exit.shy",
|
||||||
|
|
||||||
|
"template_tar_gz": "usr/template",
|
||||||
|
"librarys_tar_gz": "usr/librarys",
|
||||||
},
|
},
|
||||||
}, Help: "运行环境"},
|
}, Help: "运行环境"},
|
||||||
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
|
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
|
||||||
"system": []interface{}{"boot_sh", "node_sh", "init_shy", "common_shy", "exit_shy"},
|
"system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"},
|
||||||
"portal": []interface{}{"code_tmpl", "code_js", "context_js"},
|
"portal": []interface{}{"template.tar.gz", "librarys.tar.gz"},
|
||||||
"list": map[string]interface{}{
|
"list": map[string]interface{}{
|
||||||
"bench": "bin/bench.new",
|
"bench": "bin/bench.new",
|
||||||
"boot_sh": "bin/boot.sh",
|
"boot_sh": "bin/boot.sh",
|
||||||
@ -154,9 +157,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"common_shy": "etc/common.shy",
|
"common_shy": "etc/common.shy",
|
||||||
"exit_shy": "etc/exit.shy",
|
"exit_shy": "etc/exit.shy",
|
||||||
|
|
||||||
"code_tmpl": "usr/template/code/code.tmpl",
|
"template_tar_gz": "usr/template.tar.gz",
|
||||||
"code_js": "usr/librarys/code.js",
|
"librarys_tar_gz": "usr/librarys.tar.gz",
|
||||||
"context_js": "usr/librarys/context.js",
|
|
||||||
},
|
},
|
||||||
}, Help: "日志地址"},
|
}, Help: "日志地址"},
|
||||||
|
|
||||||
@ -542,14 +544,22 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"publish": &ctx.Command{Name: "publish", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"publish": &ctx.Command{Name: "publish", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
p := m.Conf("publish", "path")
|
dir := m.Conf("publish", "path")
|
||||||
m.Assert(os.MkdirAll(p, 0777))
|
m.Assert(os.MkdirAll(dir, 0777))
|
||||||
|
|
||||||
m.Confm("publish", "list", func(key string, value string) {
|
m.Confm("publish", "list", func(key string, value string) {
|
||||||
m.Cmd("nfs.copy", path.Join(p, key), m.Cmdx("nfs.path", value))
|
p := m.Cmdx("nfs.path", value)
|
||||||
|
if s, e := os.Stat(p); e == nil {
|
||||||
|
if s.IsDir() {
|
||||||
|
m.Cmd("cli.system", "tar", "-zcf", path.Join(dir, key), "-C", path.Dir(p), path.Base(value))
|
||||||
|
} else {
|
||||||
|
m.Cmd("nfs.copy", path.Join(dir, key), p)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
})
|
})
|
||||||
m.Cmd("cli.system", "tar", "-zcvf", path.Join(p, "template.tar.gz"), "usr/template")
|
m.Cmdy("nfs.dir", dir, "dir_sort", "time", "time_r")
|
||||||
m.Cmd("cli.system", "tar", "-zcvf", path.Join(p, "librarys.tar.gz"), "usr/librarys")
|
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"upgrade": &ctx.Command{Name: "upgrade bench|system|extend|plugin|portal|client|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"upgrade": &ctx.Command{Name: "upgrade bench|system|extend|plugin|portal|client|script", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
@ -572,8 +582,13 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
restart = true
|
restart = true
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Add("append", "hash", kit.Hashs(file))
|
m.Add("append", "hash", kit.Hashs(file))
|
||||||
m.Add("append", "file", file)
|
m.Add("append", "file", file)
|
||||||
|
|
||||||
|
if strings.HasSuffix(link, ".tar.gz") {
|
||||||
|
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Table()
|
m.Table()
|
||||||
|
|
||||||
|
@ -685,6 +685,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
"command": &Command{Name: "command [all] [show]|[list [begin [end]] [prefix] test [key val]...]|[add [list_name name] [list_help help] cmd...]|[delete cmd]",
|
"command": &Command{Name: "command [all] [show]|[list [begin [end]] [prefix] test [key val]...]|[add [list_name name] [list_help help] cmd...]|[delete cmd]",
|
||||||
Help: "查看或修改命令, show: 查看命令;\nlist: 查看列表命令, begin: 起始索引, end: 截止索引, prefix: 过滤前缀, test: 执行命令;\nadd: 添加命令, list_name: 命令别名, list_help: 命令帮助;\ndelete: 删除命令",
|
Help: "查看或修改命令, show: 查看命令;\nlist: 查看列表命令, begin: 起始索引, end: 截止索引, prefix: 过滤前缀, test: 执行命令;\nadd: 添加命令, list_name: 命令别名, list_help: 命令帮助;\ndelete: 删除命令",
|
||||||
Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
|
if len(arg) > 0 && arg[0] == "help" {
|
||||||
|
m.Cmdy(".help", "command", arg[1:])
|
||||||
|
return
|
||||||
|
}
|
||||||
all := false
|
all := false
|
||||||
if len(arg) > 0 && arg[0] == "all" {
|
if len(arg) > 0 && arg[0] == "all" {
|
||||||
all, arg = true, arg[1:]
|
all, arg = true, arg[1:]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user