增加停止服务的方式

pull/23/head
630892807@qq.com 4 years ago
parent e59b341282
commit e12aa03fd8

@ -34,4 +34,5 @@ func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(installCmd)
rootCmd.AddCommand(stopCmd)
}

@ -2,27 +2,29 @@ package cmd
import (
"embed"
"fmt"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
"github.com/taoshihan1991/imaptool/controller"
"github.com/taoshihan1991/imaptool/middleware"
"github.com/taoshihan1991/imaptool/router"
"github.com/taoshihan1991/imaptool/tools"
"github.com/taoshihan1991/imaptool/ws"
"github.com/zh-five/xdaemon"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
)
var (
Port string
port string
daemon bool
)
var serverCmd = &cobra.Command{
Use: "server",
Short: "example:go-fly server -p 8081",
Short: "启动http服务",
Example: "go-fly server -c config/",
Run: func(cmd *cobra.Command, args []string) {
run()
@ -36,7 +38,7 @@ var templatesEmbed embed.FS
var jsEmbed embed.FS
func init() {
serverCmd.PersistentFlags().StringVarP(&Port, "port", "p", "8081", "监听端口号")
serverCmd.PersistentFlags().StringVarP(&port, "port", "p", "8081", "监听端口号")
serverCmd.PersistentFlags().BoolVarP(&daemon, "daemon", "d", false, "是否为守护进程模式")
}
func run() {
@ -56,8 +58,7 @@ func run() {
d.Run()
}
baseServer := "0.0.0.0:" + Port
controller.Port = Port
baseServer := "0.0.0.0:" + port
log.Println("start server...\r\ngohttp://" + baseServer)
tools.Logger().Println("start server...\r\ngohttp://" + baseServer)
@ -76,11 +77,14 @@ func run() {
engine.Use(middleware.NewMidLogger())
router.InitViewRouter(engine)
router.InitApiRouter(engine)
//记录pid
ioutil.WriteFile("gofly.sock", []byte(fmt.Sprintf("%d,%d", os.Getppid(), os.Getpid())), 0666)
//限流类
tools.NewLimitQueue()
//清理
ws.CleanVisitorExpire()
//后端websocket
go ws.WsServerBackend()
//logFile, _ := os.OpenFile("./fatal.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)
//tools.RedirectStderr(logFile)
//tcp服务
//go controller.NewTcpServer(tcpBaseServer)
engine.Run(baseServer)
}

@ -0,0 +1,30 @@
package cmd
import (
"github.com/spf13/cobra"
"io/ioutil"
"os/exec"
"runtime"
"strings"
)
var stopCmd = &cobra.Command{
Use: "stop",
Short: "停止http服务",
Run: func(cmd *cobra.Command, args []string) {
pids, err := ioutil.ReadFile("gofly.sock")
if err != nil {
return
}
pidSlice := strings.Split(string(pids), ",")
var command *exec.Cmd
for _, pid := range pidSlice {
if runtime.GOOS == "windows" {
command = exec.Command("taskkill.exe", "/f", "/pid", pid)
} else {
command = exec.Command("kill", pid)
}
command.Start()
}
},
}

@ -29,7 +29,6 @@ func InitApiRouter(engine *gin.Engine) {
//前后聊天
engine.GET("/ws_kefu", middleware.JwtApiMiddleware, ws.NewKefuServer)
engine.GET("/ws_visitor", middleware.Ipblack, ws.NewVisitorServer)
go ws.WsServerBackend()
engine.GET("/messages", controller.GetVisitorMessage)
engine.GET("/message_notice", controller.SendVisitorNotice)

@ -1,6 +1,6 @@
.launchButtonBox{
position: fixed!important;
bottom: 10px;
bottom: 2px;
right: 20px;
left: auto;
z-index: 999999;
@ -54,13 +54,13 @@
display: none;
}
.launchButton{
height: 48px;
height: 42px;
width: auto;
z-index: 10000000000000!important;
background: #fac917;
border-radius: 2px;
border: 0!important;
border-radius: 20px;
box-shadow: 0 3px 15px 0 rgba(0,0,0,.25)!important;
background: rgb(18, 122, 202);
box-shadow: rgba(0, 0, 0, 0.06) 0px 1px 6px, rgba(0, 0, 0, 0.16) 0px 2px 32px;
box-sizing: border-box!important;
padding: 0 25px;
cursor: pointer!important;
@ -80,11 +80,11 @@
height: 48px;
}
.launchButtonText {
color: #312927;
color: #fff;
display: inline-block!important;
font-family: -apple-system,BlinkMacSystemFont,segoe ui,Roboto,Oxygen,Ubuntu,Cantarell,fira sans,droid sans,helvetica neue,sans-serif!important;
font-size: 1em;
line-height: 48px;
line-height: 42px;
font-weight: 700!important;
overflow: hidden!important;
text-overflow: ellipsis!important;
@ -226,4 +226,4 @@
.launchButtonNotice:after{
right: 4%;
}
}
}

@ -8,7 +8,7 @@ import (
var LimitQueue map[string][]int64
var ok bool
func init() {
func NewLimitQueue() {
cleanLimitQueue()
}
func cleanLimitQueue() {

@ -179,7 +179,7 @@ func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content s
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, welcome.Content, "kefu")
}
}
func cleanVisitorExpire() {
func CleanVisitorExpire() {
go func() {
log.Println("cleanVisitorExpire start...")
for {

@ -66,7 +66,6 @@ func init() {
},
}
go UpdateVisitorStatusCron()
cleanVisitorExpire()
}
func SendServerJiang(title string, content string, domain string) string {
noticeServerJiang, err := strconv.ParseBool(models.FindConfig("NoticeServerJiang"))

Loading…
Cancel
Save