forked from x/ContextOS
vps add ssh.route 添加主机动态域名
This commit is contained in:
parent
a27b443df3
commit
bdb86ead00
@ -228,7 +228,7 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
}
|
||||
|
||||
if cli.nfs = m.Find("nfs"); m.Has("stdio") {
|
||||
cli.nfs.Cmd("scan", m.Cap("stream", "stdio"), m.Cmd("source", m.Cap("init.shy")).Get("result"))
|
||||
cli.nfs.Cmd("scan", m.Cap("stream", "stdio"), m.Spawn(m.Target()).Cmd("source", m.Cap("init.shy")).Get("result"))
|
||||
} else {
|
||||
if _, e := os.Stat(m.Cap("init.shy")); e == nil {
|
||||
cli.nfs.Cmd("scan", m.Cap("stream", m.Cap("init.shy")))
|
||||
@ -261,6 +261,9 @@ func (cli *CLI) Close(m *ctx.Message, arg ...string) bool { // {{{
|
||||
switch cli.Context {
|
||||
case m.Target():
|
||||
m.Echo(cli.nfs.Cap("return"))
|
||||
if p, ok := m.Source().Server.(*CLI); ok {
|
||||
p.target = cli.target
|
||||
}
|
||||
case m.Source():
|
||||
if m.Name == "aaa" {
|
||||
if !cli.Context.Close(m.Spawn(cli.Context), arg...) {
|
||||
|
@ -6,7 +6,6 @@ import ( // {{{
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
@ -355,7 +354,7 @@ func (m *Message) Log(action string, ctx *Context, str string, arg ...interface{
|
||||
l.Options("log", false)
|
||||
l.Cmd("log", action, fmt.Sprintf(str, arg...))
|
||||
} else {
|
||||
log.Printf(str, arg...)
|
||||
// log.Printf(str, arg...)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -1328,21 +1327,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
|
||||
"default": &Config{Name: "默认的搜索起点(root/back/home)", Value: "root", Help: "模块搜索的默认起点,root:从根模块,back:从父模块,home:从当前模块"},
|
||||
|
||||
"start": &Config{Name: "启动模块", Value: "cli", Help: "启动时自动运行的模块"},
|
||||
"init.shy": &Config{Name: "启动脚本", Value: "etc/init.shy", Help: "模块启动时自动运行的脚本"},
|
||||
"bench.log": &Config{Name: "日志文件", Value: "var/bench.log", Help: "模块日志输出的文件", Hand: func(m *Message, x *Config, arg ...string) string {
|
||||
if len(arg) > 0 { // {{{
|
||||
// if e := os.MkdirAll(path.Dir(arg[0]), os.ModePerm); e == nil {
|
||||
if l, e := os.Create(x.Value); e == nil {
|
||||
log.SetOutput(l)
|
||||
return arg[0]
|
||||
}
|
||||
return ""
|
||||
// }
|
||||
}
|
||||
return x.Value
|
||||
// }}}
|
||||
}},
|
||||
"start": &Config{Name: "启动模块", Value: "cli", Help: "启动时自动运行的模块"},
|
||||
"init.shy": &Config{Name: "启动脚本", Value: "etc/init.shy", Help: "模块启动时自动运行的脚本"},
|
||||
"bench.log": &Config{Name: "日志文件", Value: "var/bench.log", Help: "模块日志输出的文件"},
|
||||
"root": &Config{Name: "工作目录", Value: ".", Help: "所有模块的当前目录", Hand: func(m *Message, x *Config, arg ...string) string {
|
||||
if len(arg) > 0 { // {{{
|
||||
if !path.IsAbs(x.Value) {
|
||||
@ -1935,23 +1922,18 @@ func init() {
|
||||
|
||||
func Start(args ...string) {
|
||||
if len(args) > 0 {
|
||||
Pulse.Conf("start", args[0])
|
||||
Pulse.Conf("init.shy", args[0])
|
||||
}
|
||||
if len(args) > 1 {
|
||||
Pulse.Conf("init.shy", args[1])
|
||||
Pulse.Conf("bench.log", args[1])
|
||||
}
|
||||
if len(args) > 2 {
|
||||
Pulse.Conf("bench.log", args[2])
|
||||
} else {
|
||||
Pulse.Conf("bench.log", Pulse.Conf("bench.log"))
|
||||
Pulse.Conf("root", args[2])
|
||||
}
|
||||
if len(args) > 3 {
|
||||
Pulse.Conf("root", args[3])
|
||||
Pulse.Conf("start", args[3])
|
||||
}
|
||||
|
||||
Pulse.Options("log", true)
|
||||
|
||||
// log.Println("\n\n")
|
||||
Index.Group = "root"
|
||||
Index.Owner = Index.contexts["aaa"]
|
||||
Index.master = Index.contexts["cli"]
|
||||
@ -1959,8 +1941,9 @@ func Start(args ...string) {
|
||||
m.target.root = Index
|
||||
m.target.Begin(m)
|
||||
}
|
||||
// log.Println()
|
||||
Pulse.Sess("log", "log").Conf("bench.log", "var/bench.log")
|
||||
|
||||
Pulse.Options("log", true)
|
||||
Pulse.Sess("log", "log").Conf("bench.log", Pulse.Conf("bench.log"))
|
||||
|
||||
for _, m := range Pulse.Search(Pulse.Conf("start")) {
|
||||
m.Set("detail", Pulse.Conf("init.shy")).Set("option", "stdio").target.Start(m)
|
||||
|
@ -1,14 +1,17 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
package log // {{{
|
||||
// }}}
|
||||
import ( // {{{
|
||||
"contexts"
|
||||
"fmt"
|
||||
Log "log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// }}}
|
||||
|
||||
type LOG struct {
|
||||
module map[string]map[string]bool
|
||||
slient map[string]bool
|
||||
@ -19,7 +22,7 @@ type LOG struct {
|
||||
*ctx.Context
|
||||
}
|
||||
|
||||
func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server {
|
||||
func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
|
||||
c.Caches = map[string]*ctx.Cache{}
|
||||
c.Configs = map[string]*ctx.Config{}
|
||||
|
||||
@ -28,7 +31,8 @@ func (log *LOG) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
||||
return s
|
||||
}
|
||||
|
||||
func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
// }}}
|
||||
func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
||||
if log.Context == Index {
|
||||
Pulse = m
|
||||
}
|
||||
@ -45,6 +49,7 @@ func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
log.Configs["bench.log"] = &ctx.Config{Name: "日志文件", Value: "var/bench.log", Help: "模块日志输出的文件", Hand: func(m *ctx.Message, x *ctx.Config, arg ...string) string {
|
||||
if len(arg) > 0 {
|
||||
if m.Sess("nfs") == nil {
|
||||
os.Create(arg[0])
|
||||
m.Sess("nfs", "nfs").Cmd("open", arg[0])
|
||||
}
|
||||
return arg[0]
|
||||
@ -55,12 +60,14 @@ func (log *LOG) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
return log
|
||||
}
|
||||
|
||||
func (log *LOG) Start(m *ctx.Message, arg ...string) bool {
|
||||
// }}}
|
||||
func (log *LOG) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||
log.Message = m
|
||||
return false
|
||||
}
|
||||
|
||||
func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
|
||||
// }}}
|
||||
func (log *LOG) Close(m *ctx.Message, arg ...string) bool { // {{{
|
||||
switch log.Context {
|
||||
case m.Target():
|
||||
case m.Source():
|
||||
@ -68,13 +75,15 @@ func (log *LOG) Close(m *ctx.Message, arg ...string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
var Pulse *ctx.Message
|
||||
var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"slient": &ctx.Command{Name: "slient [[module] level state]", Help: "查看或设置日志开关, module: 模块名, level: 日志类型, state(true/false): 是否打印日志", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) { // {{{
|
||||
switch len(arg) {
|
||||
case 2:
|
||||
if len(arg) > 1 {
|
||||
@ -95,10 +104,10 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
m.Echo("%s(%s): %t\n", k, i, x)
|
||||
}
|
||||
}
|
||||
}
|
||||
} // }}}
|
||||
}},
|
||||
"color": &ctx.Command{Name: "color [level color]", Help: "查看或设置日志颜色, level: 日志类型, color: 文字颜色", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) { // {{{
|
||||
if len(arg) > 1 {
|
||||
c, e := strconv.Atoi(arg[1])
|
||||
m.Assert(e)
|
||||
@ -108,10 +117,10 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
for k, v := range log.color {
|
||||
m.Echo("\033[%dm%s: %d\033[0m\n", v, k, v)
|
||||
}
|
||||
}
|
||||
} // }}}
|
||||
}},
|
||||
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) {
|
||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) { // {{{
|
||||
if s, ok := log.slient[arg[0]]; ok && s == true {
|
||||
return
|
||||
}
|
||||
@ -167,7 +176,7 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
nfs.Cmd("write", fmt.Sprintf("%s%s%s %s\n", date, code, action, strings.Join(arg[1:], "")))
|
||||
}
|
||||
}
|
||||
}
|
||||
} // }}}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
@ -118,8 +118,11 @@ var Pulse *ctx.Message
|
||||
var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
Caches: map[string]*ctx.Cache{
|
||||
"nhost": &ctx.Cache{Name: "主机数量", Value: "0", Help: "主机数量"},
|
||||
"route": &ctx.Cache{Name: "route", Value: "", Help: "主机数量"},
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"route": &ctx.Config{Name: "route", Value: "com", Help: "主机数量"},
|
||||
},
|
||||
Configs: map[string]*ctx.Config{},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"listen": &ctx.Command{Name: "listen address protocol", Help: "监听连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
msg := m.Sess("file", "nfs")
|
||||
@ -129,7 +132,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
sub.Start(fmt.Sprintf("host%d", Pulse.Capi("nhost", 1)), "打开文件", sub.Meta["detail"]...)
|
||||
sub.Cap("stream", msg.Target().Name)
|
||||
sub.Target().Sessions["file"] = msg
|
||||
sub.Target(msg.Target())
|
||||
sub.Echo(sub.Target().Name)
|
||||
sub.Spawn(sub.Target()).Cmd("send", "context", "ssh")
|
||||
sub.Spawn(sub.Target()).Cmd("send", "route", sub.Target().Name, msg.Cap("route")+"."+msg.Conf("route"))
|
||||
}
|
||||
return false, true
|
||||
}, false).Cmd(m.Meta["detail"])
|
||||
@ -151,7 +157,18 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
msg.Copy(m, "detail").Cmd()
|
||||
m.Copy(msg, "result")
|
||||
}},
|
||||
"remote": &ctx.Command{Name: "remote detail...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
"route": &ctx.Command{Name: "route", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Conf("route", arg[0])
|
||||
m.Cap("route", arg[1]+"."+arg[0])
|
||||
}},
|
||||
"dispatch": &ctx.Command{Name: "dispatch cmd arg...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Travel(m.Target(), func(m *ctx.Message) bool {
|
||||
msg := m.Spawn(m.Target())
|
||||
msg.Cmd("send", arg)
|
||||
return true
|
||||
})
|
||||
}},
|
||||
"register": &ctx.Command{Name: "remote detail...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
ssh, ok := m.Target().Server.(*SSH)
|
||||
m.Assert(ok)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user