1
0
forked from x/ContextOS

opt node.sh

This commit is contained in:
shylinux 2019-06-16 13:39:04 +08:00
parent 227b3475d1
commit 78df5d2ba3
4 changed files with 35 additions and 38 deletions

View File

@ -20,6 +20,10 @@ log() {
echo -e $*
}
install() {
if [ -n "$1" ]; then
mkdir $1; cd $1
fi
md5=md5sum
case `uname -s` in
"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"
case $1 in
install) install "$@";;
install) shift && install "$@";;
start|"") main "$@";;
create) mkdir -p $2; cd $2 && shift && shift && main "$@";;
restart) action 30;;

View File

@ -1,31 +1,5 @@
#! /bin/bash
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

View File

@ -141,11 +141,14 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"init_shy": "etc/init.shy",
"common_shy": "etc/common.shy",
"exit_shy": "etc/exit.shy",
"template_tar_gz": "usr/template",
"librarys_tar_gz": "usr/librarys",
},
}, Help: "运行环境"},
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
"system": []interface{}{"boot_sh", "node_sh", "init_shy", "common_shy", "exit_shy"},
"portal": []interface{}{"code_tmpl", "code_js", "context_js"},
"system": []interface{}{"boot.sh", "node.sh", "init.shy", "common.shy", "exit.shy"},
"portal": []interface{}{"template.tar.gz", "librarys.tar.gz"},
"list": map[string]interface{}{
"bench": "bin/bench.new",
"boot_sh": "bin/boot.sh",
@ -154,9 +157,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"common_shy": "etc/common.shy",
"exit_shy": "etc/exit.shy",
"code_tmpl": "usr/template/code/code.tmpl",
"code_js": "usr/librarys/code.js",
"context_js": "usr/librarys/context.js",
"template_tar_gz": "usr/template.tar.gz",
"librarys_tar_gz": "usr/librarys.tar.gz",
},
}, Help: "日志地址"},
@ -542,14 +544,22 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
return
}},
"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")
m.Assert(os.MkdirAll(p, 0777))
dir := m.Conf("publish", "path")
m.Assert(os.MkdirAll(dir, 0777))
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.Cmd("cli.system", "tar", "-zcvf", path.Join(p, "librarys.tar.gz"), "usr/librarys")
m.Cmdy("nfs.dir", dir, "dir_sort", "time", "time_r")
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) {
@ -572,8 +582,13 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}
restart = true
}
m.Add("append", "hash", kit.Hashs(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()

View File

@ -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]",
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) {
if len(arg) > 0 && arg[0] == "help" {
m.Cmdy(".help", "command", arg[1:])
return
}
all := false
if len(arg) > 0 && arg[0] == "all" {
all, arg = true, arg[1:]