This commit is contained in:
gotoeasy 2022-09-15 21:41:22 +08:00
parent 4ae7490239
commit 8216694934
6 changed files with 48 additions and 30 deletions

View File

@ -34,10 +34,10 @@
## `docker`运行
```
// 简单示例(0.5.*及以前的版本默认端口80800.6.*以后的版本端口改为18080)
// 简单示例
docker run -d -p 8080:8080 gotoeasy/glc
// 外挂数据目录(0.5.*及以前的版本默认端口80800.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
<dependency>
<groupId>top.gotoeasy</groupId>
<artifactId>glc-logback-appender</artifactId>
<version>0.5.1</version>
<version>0.6.0</version>
</dependency>
```
```xml
<!-- logback配置例子1发送至 glogcenter -->
<!-- 0.5.1及以上版本,可通过设定环境变量 GLC_ENABLE=false 关闭发送功能 -->
<appender name="GLC" class="top.gotoeasy.framework.glc.logback.appender.GlcHttpJsonAppender">
<glcApiUrl>http://127.0.0.1:18080/glc/v1/log/add</glcApiUrl> <!-- 可通过环境变量 GLC_API_URL 设定 -->
<glcApiKey>X-GLC-AUTH:glogcenter</glcApiKey> <!-- 可通过环境变量 GLC_API_KEY 设定 -->
@ -92,7 +94,6 @@ docker run -d -p 8080:8080 -v /glc:/glogcenter gotoeasy/glc
</appender>
<!-- logback配置例子2发送至 rabbitmq -->
<!-- 0.5.1及以上版本,可通过设定环境变量 GLC_ENABLE=false 关闭发送功能 -->
<appender name="GLC" class="top.gotoeasy.framework.glc.logback.appender.GlcAmqpAppender">
<amqpHost>127.0.0.1</amqpHost> <!-- 可通过环境变量 GLC_AMQP_HOST 设定 -->
<amqpPort>5672</amqpPort> <!-- 可通过环境变量 GLC_AMQP_PORT 设定 -->
@ -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`

View File

@ -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"]

View File

@ -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键名

View File

@ -5,4 +5,3 @@ import "glc/onstart"
func main() {
onstart.Run()
}

View File

@ -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 {

3
glc/onstart/version.go Normal file
View File

@ -0,0 +1,3 @@
package onstart
const VERSION = "glogcenter 0.6.0"