diff --git a/README.md b/README.md index 8b84c40..6e6ec8e 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ ## `docker`运行 ``` -// 简单示例(0.5.*及以前的版本默认端口8080,0.6.*以后的版本端口改为18080) +// 简单示例 docker run -d -p 8080:8080 gotoeasy/glc -// 外挂数据目录(0.5.*及以前的版本默认端口8080,0.6.*以后的版本端口改为18080) +// 外挂数据目录 docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc ``` @@ -55,10 +55,13 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc - [x] `GLC_AMQP_ADDR`消息队列`rabbitMq`连接地址,例:`amqp://user:password@ip:port/`,默认空白 - [x] `GLC_AMQP_JSON_FORMAT`消息队列`rabbitMq`消息文本是否为`json`格式,默认`true` -## 命令行启动参数 +## 命令行启动参数(适用`0.6.*`及以上版本) +- [x] 支持命令行参数`-v`查看版本 - [x] 在Linux系统下支持命令行参数`-d`以后台方式启动 - [x] 在Linux系统下支持命令行参数`stop`关闭程序 - [x] 在Linux系统下支持命令行参数`restart`重启程序 +- [x] 服务端口可通过环境变量`GLC_SERVER_PORT`设定,默认`8080` +- [x] 其他环境变量同以上`docker`启动环境变量 ## 接口 @@ -75,13 +78,12 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc top.gotoeasy glc-logback-appender - 0.5.1 + 0.6.0 ``` ```xml - http://127.0.0.1:18080/glc/v1/log/add X-GLC-AUTH:glogcenter @@ -92,7 +94,6 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc - 127.0.0.1 5672 @@ -114,11 +115,17 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc - [ ] 界面优化 - [ ] 多语言 - [ ] 分词优化 + + +### 版本`0.6.0` + - [x] 升级使用Go1.19 -- [x] 支持命令行参数使用`-d`以后台方式启动 -- [x] 支持命令行参数使用`stop`停止程序 -- [x] 支持命令行参数使用`restart`重启程序 -- [x] 默认端口由`8080`改为`18080` +- [x] 优化执行文件体积,此版本考虑直接运行发布,以适用更多部署场景 +- [x] 支持命令行参数使用`-v`查看版本 +- [x] 在Linux系统下支持命令行参数使用`-d`以后台方式启动 +- [x] 在Linux系统下支持命令行参数使用`stop`停止程序 +- [x] 在Linux系统下支持命令行参数使用`restart`重启程序 +- [x] `logback`用`jar`包,支持通过设定环境变量`GLC_ENABLE=false`关闭日志发送功能 ### 版本`0.5.0` diff --git a/glc/Dockerfile b/glc/Dockerfile index 409f79e..b8449ae 100644 --- a/glc/Dockerfile +++ b/glc/Dockerfile @@ -22,7 +22,7 @@ COPY . /goproject COPY --from=webbuilder /webproject/www/web/dist www/web/ ENV GOPROXY https://goproxy.cn,direct -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build +RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-w -s" # ---------------------------- @@ -40,5 +40,5 @@ RUN alpine_version=`cat /etc/issue | head -1 | awk '{print $5}'` \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone \ && rm -rf /var/cache/apk/* -EXPOSE 18080 +EXPOSE 8080 ENTRYPOINT ["glc"] diff --git a/glc/conf/config.go b/glc/conf/config.go index 1f953c8..ff3dceb 100644 --- a/glc/conf/config.go +++ b/glc/conf/config.go @@ -48,7 +48,7 @@ func UpdateConfigByEnv() { storeChanLength = GetenvInt("GLC_STORE_CHAN_LENGTH", 64) // 存储通道长度 maxIdleTime = GetenvInt("GLC_MAX_IDLE_TIME", 180) // 最大闲置时间(秒),超过闲置时间将自动关闭,0时表示不关闭 storeNameAutoAddDate = GetenvBool("GLC_STORE_NAME_AUTO_ADD_DATE", true) // 存储名是否自动添加日期(日志量大通常按日单位区分存储),默认true - serverPort = GetenvInt("GLC_SERVER_PORT", 18080) // web服务端口,默认18080 + serverPort = GetenvInt("GLC_SERVER_PORT", 8080) // web服务端口,默认8080 contextPath = Getenv("GLC_CONTEXT_PATH", "/glc") // web服务contextPath enableSecurityKey = GetenvBool("GLC_ENABLE_SECURITY_KEY", false) // web服务是否开启API秘钥校验,默认false headerSecurityKey = Getenv("GLC_HEADER_SECURITY_KEY", "X-GLC-AUTH") // web服务API秘钥的header键名 diff --git a/glc/main.go b/glc/main.go index c12296b..91d7d9f 100644 --- a/glc/main.go +++ b/glc/main.go @@ -5,4 +5,3 @@ import "glc/onstart" func main() { onstart.Run() } - \ No newline at end of file diff --git a/glc/onstart/daemon.go b/glc/onstart/daemon.go index b29a94d..995555a 100644 --- a/glc/onstart/daemon.go +++ b/glc/onstart/daemon.go @@ -12,25 +12,11 @@ import ( func init() { - // 仅支持linux - if runtime.GOOS != "linux" { - return - } - - // pid 目录、文件 - pidpath := "." - pidfile := "glc.pid" - u, err := user.Current() - if err == nil { - pidpath = filepath.Join(u.HomeDir, ".glogcenter") - os.MkdirAll(pidpath, 0766) - } - pidpathfile := filepath.Join(pidpath, pidfile) - - // 操作系统是linux时,支持以命令行参数【-d】后台方式启动,【stop】停止 + // 命令行参数解析,【-d】后台方式启动,【stop】停止,【restart】重启,【-v/version/--version/-version】查看版本 daemon := false stop := false restart := false + version := false for index, arg := range os.Args { if index == 0 { continue @@ -44,7 +30,30 @@ func init() { if arg == "restart" { restart = true } + if arg == "-v" || arg == "version" || arg == "--version" || arg == "-version" { + version = true + } } + // 查看版本 + if version { + fmt.Printf("%s\n", VERSION) + os.Exit(0) + } + + // 其余参数仅支持linux + if runtime.GOOS != "linux" { + return + } + + // pid 目录、文件 + pidpath := "." + pidfile := "glc.pid" + u, err := user.Current() + if err == nil { + pidpath = filepath.Join(u.HomeDir, ".glogcenter") + os.MkdirAll(pidpath, 0766) + } + pidpathfile := filepath.Join(pidpath, pidfile) rs := checkPidFile(pidpathfile) if rs != nil { diff --git a/glc/onstart/version.go b/glc/onstart/version.go new file mode 100644 index 0000000..1075c72 --- /dev/null +++ b/glc/onstart/version.go @@ -0,0 +1,3 @@ +package onstart + +const VERSION = "glogcenter 0.6.0"