Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

日志输出处理 #61

Merged
merged 5 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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