上传cmd 同步协议
This commit is contained in:
parent
79b05f2f2f
commit
44f02046f2
@ -18,6 +18,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -64,6 +65,14 @@ var restart = &cobra.Command{
|
||||
start()
|
||||
},
|
||||
}
|
||||
var sync = &cobra.Command{
|
||||
Use: "sync",
|
||||
Short: "同步服务器",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
lego.Recover("sync")
|
||||
syncServer()
|
||||
},
|
||||
}
|
||||
|
||||
func emptyRun(*cobra.Command, []string) {}
|
||||
|
||||
@ -80,7 +89,7 @@ func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(&crosspath, "cross", "c", "./cross.json", "游戏跨服配置")
|
||||
RootCmd.PersistentFlags().StringVarP(&sid, "sid", "i", "", "区服id")
|
||||
RootCmd.PersistentFlags().BoolVarP(&openlog, "log", "l", false, "输出日志")
|
||||
RootCmd.AddCommand(confCmd, startCmd, stopCmd, restart)
|
||||
RootCmd.AddCommand(confCmd, startCmd, stopCmd, restart, sync)
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -89,7 +98,7 @@ func main() {
|
||||
log.SetFileName("./s.log"),
|
||||
log.SetLoglevel(log.DebugLevel),
|
||||
log.SetUniqueLog(true),
|
||||
log.SetIsDebug(false)); err != nil {
|
||||
log.SetIsDebug(true)); err != nil {
|
||||
panic(fmt.Sprintf("Sys log Init err:%v", err))
|
||||
} else {
|
||||
log.Infof("Sys log Init success !")
|
||||
@ -221,6 +230,72 @@ func stop() {
|
||||
log.Infof("stop succ!")
|
||||
}
|
||||
|
||||
//同步服务器
|
||||
func syncServer() {
|
||||
if sid != "" {
|
||||
switch sid {
|
||||
case "qa":
|
||||
exesshcomd("10.0.0.9", `
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务准备同步--QA测试服"}}';
|
||||
cd /home/liwei/dreamworks; svn revert -R . ; svn update
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/cmd /home/liwei/dreamworks/cmd;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/gateway /home/liwei/dreamworks/gateway;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/mainte /home/liwei/dreamworks/mainte;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/worker /home/liwei/dreamworks/worker;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/json/* /home/liwei/dreamworks/json/;
|
||||
sudo cp -f /home/liwei/go_dreamfactory/bin/wordfilter.txt /home/liwei/dreamworks/wordfilter.txt;
|
||||
cd /home/liwei/dreamworks; svn add . --no-ignore --force ; svn commit -m "同步服务器" *;
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务停止--QA测试服"}}';
|
||||
`)
|
||||
exesshcomd("101.35.121.71", `
|
||||
cd /data/dreamworksserver/s80; python stopserver.py; python install.py; python start.py;
|
||||
cd /data/dreamworksserver/s100; python stopserver.py; python install.py; python start.py;
|
||||
`)
|
||||
exesshcomd("101.35.125.220", `
|
||||
cd /data/dreamworksserver/s90; python stopserver.py; python install.py; python start.py;
|
||||
cd /data/dreamworksserver/s110; python stopserver.py; python install.py; python start.py;
|
||||
curl -XPOST -s -L 'https://oapi.dingtalk.com/robot/send?access_token=c6d2066cd4b36882b5dc3033e359a1c1b259eb4fd6cb69f397a65f544dbce86f' -H 'Content-Type: application/json' -H "charset:utf-8" -d '{"msgtype": "text","text": {"content": "* 服务启动--QA测试服"}}';
|
||||
`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func exesshcomd(addr, cmd string) (err error) {
|
||||
var (
|
||||
config *ssh.ClientConfig
|
||||
sshClient *ssh.Client
|
||||
session *ssh.Session
|
||||
combo []byte
|
||||
)
|
||||
//创建sshp登陆配置
|
||||
config = &ssh.ClientConfig{
|
||||
Timeout: time.Second, //ssh 连接time out 时间一秒钟, 如果ssh验证错误 会在一秒内返回
|
||||
User: "root",
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //这个可以, 但是不够安全
|
||||
}
|
||||
config.Auth = []ssh.AuthMethod{ssh.Password("Legu.cc()123")}
|
||||
//dial 获取ssh client
|
||||
sshClient, err = ssh.Dial("tcp", fmt.Sprintf("%s:22", addr), config)
|
||||
if err != nil {
|
||||
log.Fatal("创建ssh client 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
defer sshClient.Close()
|
||||
|
||||
//创建ssh-session
|
||||
session, err = sshClient.NewSession()
|
||||
if err != nil {
|
||||
log.Fatal("创建ssh session 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
defer session.Close()
|
||||
//执行远程命令
|
||||
combo, err = session.CombinedOutput(cmd)
|
||||
if err != nil {
|
||||
log.Fatal("远程执行cmd 失败", log.Field{Key: "err", Value: err.Error()})
|
||||
}
|
||||
log.Println("命令输出:", string(combo))
|
||||
return
|
||||
}
|
||||
|
||||
// /转换区服配置到服务配置
|
||||
func rederServiceSttings(config *comm.GameConfig) (ss []*core.ServiceSttings, err error) {
|
||||
ss = make([]*core.ServiceSttings, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user