Skip to content

Commit

Permalink
Merge pull request #61 from ncwsky/main
Browse files Browse the repository at this point in the history
日志输出处理
  • Loading branch information
newpanjing authored Feb 11, 2023
2 parents 2b8b816 + d77c054 commit 5a36fca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
13 changes: 13 additions & 0 deletions core/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import (
"gofound/web/router"
"log"
"net/http"

//_ "net/http/pprof"
"os"
"os/signal"

//"runtime"
"syscall"
"time"
)
Expand Down Expand Up @@ -40,8 +44,17 @@ func NewTokenizer(dictionaryPath string) *words.Tokenizer {
// Initialize 初始化
func Initialize() {

//runtime.SetMutexProfileFraction(1) // 开启对锁调用的跟踪
//runtime.SetBlockProfileRate(1) // 开启对阻塞操作的跟踪

//go func() { http.ListenAndServe("0.0.0.0:6060", nil) }()

global.CONFIG = Parser()

if !global.CONFIG.Debug {
log.SetOutput(os.Stdout) //将记录器的输出设置为os.Stdout
}

defer func() {

if r := recover(); r != nil {
Expand Down
33 changes: 17 additions & 16 deletions gofound.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ start() {
exit 1
else
## Change from /dev/null to something like /var/log/$PROG if you want to save output.
$PROG_PATH/$PROG $PROG_ARGS 2>&1 >/var/log/$PROG &
$PROG_PATH/$PROG $PROG_ARGS 2>&1 >>/var/log/$PROG &
#pid=`ps ax | grep -i '/usr/bin/frps' | grep -v 'grep' | sed 's/^\([0-9]\{1,\}\).*/\1/g' | head -n 1`
pid=`ps -ef | grep $PROG_PATH/$PROG | grep -v grep | awk '{print $2}'`
#echo $PROG_PATH/$PROG $PROG_ARGS
Expand Down Expand Up @@ -82,26 +82,27 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi

case "$1" in
start)
start
exit 0
;;
stop)
stop
exit 0
case "$1" in
start)
start
exit 0
;;
stop)
echo '' > /var/log/$PROG
stop
exit 0
;;
reload|restart|force-reload)
stop
start
exit 0
reload|restart|force-reload)
stop
start
exit 0
;;
status)
status
exit 0
;;
*)
*)
echo "Usage: $0 {start|stop|restart|status}" 1>&2
exit 1
;;
exit 1
;;
esac
18 changes: 18 additions & 0 deletions gofound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

#每分钟检测gofound运行
#*/1 * * * * /data/gofound/gofound.sh > /dev/null 2>&1

#每3点 重启gofound
#0 3 * * * /etc/init.d/gofound.d restart

count=`ps -fe |grep "gofound"|grep "config.yaml" -c`

echo $count
if [ $count -lt 1 ]; then
echo "restart"
echo $(date +%Y-%m-%d_%H:%M:%S) >/data/gofound/restart.log
/etc/init.d/gofound.d restart
else
echo "is running"
fi
2 changes: 2 additions & 0 deletions web/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"gofound/global"
"gofound/web/admin"
"gofound/web/middleware"
"io"
"log"
"mime"
"strings"
Expand All @@ -18,6 +19,7 @@ func SetupRouter() *gin.Engine {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard //禁止Gin的控制台输出
}

router := gin.Default()
Expand Down

0 comments on commit 5a36fca

Please sign in to comment.