1
0
forked from x/ContextOS

add node.sh

This commit is contained in:
shaoying 2019-02-02 21:05:03 +08:00
parent 07b6af2772
commit 6de57291b5
9 changed files with 141 additions and 81 deletions

View File

@ -53,11 +53,11 @@ tar_all: tar linux64 darwin win64
linux_arm:
GOARCH=arm GOOS=linux go build -o $(upgrade)bench.linux.arm $(BENCH)
linux32:
GOARCH=386 GOOS=linux go build -o $(upgrade)bench.linux32 $(BENCH)
GOARCH=386 GOOS=linux go build -o $(upgrade)bench.linux.386 $(BENCH)
linux64:
GOARCH=amd64 GOOS=linux go build -o $(upgrade)bench.linux64 $(BENCH)
GOARCH=amd64 GOOS=linux go build -o $(upgrade)bench.linux.amd64 $(BENCH)
darwin:
GOARCH=amd64 GOOS=darwin go build -o $(upgrade)bench.darwin $(BENCH)
GOARCH=amd64 GOOS=darwin go build -o $(upgrade)bench.darwin.amd64 $(BENCH)
win32:
GOARCH=386 GOOS=windows go build -o $(upgrade)bench.win32.exe $(BENCH)
win64:

71
bin/boot.sh Executable file
View File

@ -0,0 +1,71 @@
#! /bin/bash
export dev="https://shylinux.com"
export box_root="/usr/local/context"
export box_home="~/context"
bench="bench"
log() {
echo -e $*
}
prepare() {
mkdir -p bin etc usr
mkdir -p var/log var/tmp var/run
}
install() {
[ -n "$1" ] && dev=$1 && shift
case `uname -s` in
"Darwin") GOOS=darwin GOARCH=amd64;;
*) GOOS=linux GOARCH=386;;
esac
case `uname -m` in
"x86_64") GOARCH=amd64;;
"armv7l") GOARCH=arm;;
esac
log "dev: $dev\nGOOS: $GOOS\nGOARCH: $GOARCH"
dev=$dev/code/upgrade
wget -O etc/exit.shy $dev/exit_shy
wget -O etc/init.shy $dev/init_shy
wget -O etc/common.shy $dev/common_shy
wget -O bin/bench "$dev/bench?GOOS=$GOOS&GOARCH=$GOARCH" && chmod u+x bin/bench
wget -O bin/boot.sh $dev/boot_sh && chmod u+x bin/boot.sh
wget -O bin/node.sh $dev/node_sh && chmod u+x bin/node.sh
}
state() {
md=md5sum && [ `uname -s` = "Darwin" ] && md=md5
for file in bin/node.sh bin/boot.sh bin/bench etc/init.shy etc/common.shy etc/exit.shy; do
echo `$md $file`
done
}
action() {
log "kill" $1 && kill -$1 $pid
}
main() {
while true; do
$bench "$@" 2>var/log/boot.log && break
log "restarting..." && sleep 3
done
}
dir=$box_root
[ -d "$1" ] && dir=$1 && shift
[ -d "$dir" ] && cd $dir
[ -f bin/bench ] && bench=bin/bench
pid=`cat var/run/bench.pid`
log "dir: $dir\nbench: $bench\npid: $pid"
case $1 in
install) shift; prepare && install "$@";;
start|"") shift; prepare && main "$@";;
state) state;;
stop) action QUIT;;
restart) action USR1;;
upgrade) action USR2;;
esac

27
bin/node.sh Executable file
View File

@ -0,0 +1,27 @@
#! /bin/bash
export box="http://localhost:9094"
bench="bench"
log() {
echo -e $*
}
prepare() {
mkdir -p bin etc usr
mkdir -p var/run var/log var/tmp
}
main() {
while true; do
$bench "$@" 2>var/log/boot.log && break
log "restarting..." && sleep 3
done
}
case $1 in
create) mkdir $2 && cd $2 && shift && shift && prepare && main "$@";;
init) shift; prepare && main "$@";;
*) mkdir -p var/run var/log && main "$@";;
esac

View File

@ -1,62 +0,0 @@
#! /bin/bash
log() {
echo $*
}
prepare() {
log "prepare dir"
mkdir -p bin etc usr
mkdir -p var/log var/tmp var/run
}
dir=/usr/local/context
[ -d "$1" ] && dir=$1 && shift
[ -d "$dir" ] && cd $dir
bench=bench
[ -f bin/bench ] && bench=bin/bench
pid=`cat var/run/bench.pid`
case $1 in
help)
cat<<END
$0: context boot script
install: install context
restart: restart context
start: start context
stop: stop context
END
;;
install)
dev=$2
prepare
wget -O etc/exit.shy $2/code/upgrade/exit_shy
wget -O etc/init.shy $2/code/upgrade/init_shy
wget -O etc/common.shy $2/code/upgrade/common_shy
wget -O bin/bench $2/code/upgrade/bench && chmod u+x bin/bench
wget -O bin/boot.sh $2/code/upgrade/boot_sh && chmod u+x bin/boot.sh
;;
upgrade)
log "kill" usr1
kill -USR2 $pid
;;
start|"")
prepare
while true; do
pwd
log $bench
$bench 2>var/log/error.log && break
log "restarting..."
sleep 3
done
;;
stop)
log "kill" quit
kill -QUIT $pid
;;
restart)
log "kill" usr1
kill -USR1 $pid
;;
esac

3
etc/common.shy Normal file
View File

@ -0,0 +1,3 @@
~web
spide dev client new "https://shylinux.com"
spide dev client new "http://172.20.10.12:9094"

View File

@ -39,6 +39,10 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
}
func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Optionv("ps_target", Index)
if len(arg) > 0 && arg[0] == "daemon" {
m.Options("daemon", true)
arg = arg[1:]
}
m.Cmd("log.init")
m.Cmd("gdb.init")
@ -1337,6 +1341,10 @@ func Start(args ...string) bool {
if len(args) == 0 {
args = append(args, os.Args[1:]...)
}
if len(args) > 0 && args[0] == "daemon" {
Pulse.Options("daemon", true)
args = args[1:]
}
if Index.Begin(Pulse, args...); Index.Start(Pulse, args...) {
return Index.Close(Pulse, args...)

View File

@ -874,12 +874,11 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
nfs.Configs["prompt"] = &ctx.Config{Value: ""}
if nfs.in = m.Optionv("in").(*os.File); m.Has("out") {
if nfs.out = m.Optionv("out").(*os.File); m.Cap("goos") != "windows" && m.Confs("term", "enable") {
if nfs.out = m.Optionv("out").(*os.File); m.Cap("goos") != "windows" && !m.Options("daemon") {
nfs.Term(m, "init")
defer nfs.Term(m, "exit")
}
what := make(chan bool)
if m.Confs("term", "loop") {
if what := make(chan bool); m.Options("daemon") {
<-what
}
}
@ -1023,7 +1022,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
},
Configs: map[string]*ctx.Config{
"term": &ctx.Config{Name: "term", Value: map[string]interface{}{
"enable": 1, "loop": 0,
"width": 80, "height": "24",
"left": 0, "top": 0, "right": 80, "bottom": 24,

View File

@ -8,6 +8,8 @@ import (
"net"
"strconv"
"strings"
"time"
"toolkit"
)
type TCP struct {
@ -79,13 +81,25 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
m.Assert(e)
conf := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
c, e := tls.Dial(m.Cap("protocol"), m.Cap("address"), conf)
m.Assert(e)
tcp.Conn = c
for i := 0; i < m.Confi("retry", "counts"); i++ {
if c, e := tls.Dial(m.Cap("protocol"), m.Cap("address"), conf); e == nil {
tcp.Conn = c
break
} else {
m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e)
}
time.Sleep(kit.Duration(m.Conf("retry", "interval")))
}
} else {
c, e := net.Dial(m.Cap("protocol"), m.Cap("address"))
m.Assert(e)
tcp.Conn = c
for i := 0; i < m.Confi("retry", "counts"); i++ {
if c, e := net.Dial(m.Cap("protocol"), m.Cap("address")); e == nil {
tcp.Conn = c
break
} else {
m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e)
}
time.Sleep(kit.Duration(m.Conf("retry", "interval")))
}
}
m.Log("info", "%s dial %s", m.Cap("nclient"),
@ -170,6 +184,9 @@ var Index = &ctx.Context{Name: "tcp", Help: "网络中心",
"address": &ctx.Config{Name: "address", Value: ":9090", Help: "网络地址"},
"security": &ctx.Config{Name: "security(true/false)", Value: "false", Help: "加密通信"},
"protocol": &ctx.Config{Name: "protocol(tcp/tcp4/tcp6)", Value: "tcp4", Help: "网络协议"},
"retry": &ctx.Config{Name: "retry", Value: map[string]interface{}{
"interval": "3s", "counts": 5,
}, Help: "网络协议"},
},
Commands: map[string]*ctx.Command{
"listen": &ctx.Command{Name: "listen address [security [protocol]]", Help: "网络监听", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {

View File

@ -215,9 +215,10 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
},
}, Help: "组件列表"},
"upgrade": &ctx.Config{Name: "upgrade", Value: map[string]interface{}{
"system": []interface{}{"exit_shy", "common_shy", "init_shy", "bench", "boot.sh"},
"system": []interface{}{"exit_shy", "common_shy", "init_shy", "bench", "boot_sh"},
"portal": []interface{}{"code_tmpl", "code_js", "context_js"},
"file": map[string]interface{}{
"node_sh": "bin/node.sh",
"boot_sh": "bin/boot.sh",
"bench": "bin/bench.new",
"init_shy": "etc/init.shy",
@ -242,14 +243,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
p = bench
}
}
m.Log("fuck", "wha t%v", p)
if _, e = os.Stat(p); e != nil {
list := strings.Split(key, "/")
m.Log("fuck", "wha t%v", list)
p = m.Cmdx("nfs.path", m.Conf("upgrade", []string{"file", list[len(list)-1]}))
}
m.Log("fuck", "wha t%v", e)
m.Log("info", "upgrade %s %s", p, m.Cmdx("aaa.hash", "file", p))
http.ServeFile(m.Optionv("response").(http.ResponseWriter), m.Optionv("request").(*http.Request), p)
@ -262,8 +260,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
if m.Confs("upgrade", arg[0]) {
arg = arg[1:]
m.Confm("upgrade", arg[0], func(index int, value string) {
key, arg = arg[0], arg[1:]
m.Confm("upgrade", key, func(index int, value string) {
arg = append(arg, value)
})
}