1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

vps add ssh.interval

This commit is contained in:
shylinux 2018-05-15 18:49:11 +08:00
parent 0c675bcbaf
commit 90d9e44530
5 changed files with 37 additions and 4 deletions

View File

@ -207,7 +207,7 @@ func (c *Context) Begin(m *Message) *Context { // {{{
for i := 0; i < len(item)/2; i++ {
item[i], item[len(item)-i-1] = item[len(item)-i-1], item[i]
}
c.Caches["route"] = &Cache{Name: "服务数据", Value: strings.Join(item, "."), Help: "服务数据"}
c.Caches["module"] = &Cache{Name: "服务数据", Value: strings.Join(item, "."), Help: "服务数据"}
m.Index = 1
c.Pulse = m
@ -1669,6 +1669,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
"message": &Command{Name: "message code meta index", Help: "查看消息", Hand: func(m *Message, c *Context, key string, arg ...string) {
switch len(arg) { // {{{
case 0:
pulse := m.target.Pulse
if pulse != nil {
m.Echo("\033[31mPulse:\033[0m\n")
m.Echo("%d %s\n", pulse.code, pulse.Format())
}
m.Echo("\033[31mrequests:\033[0m\n")
for i, v := range m.target.Requests {
m.Echo("%d %s\n", i, v.Format())

View File

@ -646,6 +646,9 @@ func (nfs *NFS) Close(m *ctx.Message, arg ...string) bool { // {{{
case m.Source():
m.Source().Close(m.Spawn(m.Source()))
}
if m.Target() == Index {
return false
}
return true
}

View File

@ -5,6 +5,7 @@ import ( // {{{
"fmt"
"strings"
"time"
)
// }}}
@ -50,6 +51,18 @@ func (ssh *SSH) Close(m *ctx.Message, arg ...string) bool { // {{{
case m.Target():
case m.Source():
}
if m.Target() == Index {
go func() {
m.Target().Begin(m)
m.Sesss("nfs", "nfs")
for !m.Caps("stream") {
time.Sleep(time.Second * time.Duration(m.Confi("interval")))
go ssh.Message.Spawn(m.Target()).Copy(ssh.Message, "detail").Cmd()
time.Sleep(time.Second * time.Duration(m.Confi("interval")))
}
}()
return false
}
return true
}
@ -86,6 +99,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"domain": &ctx.Cache{Name: "domain", Value: "com", Help: "主机数量"},
},
Configs: map[string]*ctx.Config{
"interval": &ctx.Config{Name: "interval", Value: "3", Help: "主机数量"},
"domain": &ctx.Config{Name: "domain", Value: "com", Help: "主机数量"},
"domain.json": &ctx.Config{Name: "domain.json", Value: "var/domain.json", Help: "主机数量"},
"domain.png": &ctx.Config{Name: "domain.png", Value: "var/domain.png", Help: "主机数量"},
@ -115,6 +129,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
m.Find("nfs").CallBack(true, func(file *ctx.Message) *ctx.Message {
sub := file.Spawn(m.Target())
sub.Copy(m, "detail")
sub.Target().Start(sub)
m.Sessions["ssh"] = sub
@ -231,6 +246,15 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"close": &ctx.Command{Name: "close", Help: "连接断开", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
m.Target().Close(m)
}},
"list": &ctx.Command{Name: "list", Help: "连接断开", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
domain := m.Cap("domain")
m.Travel(c, func(m *ctx.Message) bool {
if m.Confs("domains") {
m.Echo("%s: %s.%s\n", m.Target().Name, domain, m.Conf("domains"))
}
return true
})
}},
"save": &ctx.Command{Name: "save", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
json := m.Sesss("nfs") // {{{
json.Put("option", "data", map[string]string{"domain": m.Cap("domain")})

View File

@ -132,7 +132,9 @@ func (tcp *TCP) Close(m *ctx.Message, arg ...string) bool { // {{{
}
}
}
if m.Target() == Index {
return false
}
return true
}

View File

@ -17,7 +17,6 @@ import ( // {{{
"bufio"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"
@ -175,7 +174,6 @@ func (web *WEB) Trans(m *ctx.Message, key string, hand func(*ctx.Message, *ctx.C
// }}}
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) { // {{{
if web.Message != nil {
log.Println()
web.Log("cmd", nil, "%v %s %s", r.RemoteAddr, r.Method, r.URL)
if web.Conf("logheaders") == "yes" {