Skip to content

Commit

Permalink
增加日志打印
Browse files Browse the repository at this point in the history
  • Loading branch information
haierkeys committed Oct 19, 2022
1 parent efb4422 commit 772b2a2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ define init
@echo "Build Init"
mkdir -p $(buildDir)
@cp -rf $(cfgFile) $(buildDir)
find $(buildDir) -type f -name "*.go" | xargs rm
endef
# @cp -rf $(keystoreDir) $(buildDir)
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Golang Multi-node Webhook Tools
Multi-node HTTP Endpoints Server (Multi-node Webhook Tools)
===
>multi-node-webhook 是 golang编写的多节点远程脚本/命令执行工具
>multi-node-webhook 是 golang编写的多节点服务器脚本/命令执行工具
主要用于远端服务器集群的通知脚本执行或代码程序更新部署操作
主要用于服务器集群的脚本执行(代码更新,程序部署)操作

### multi-node-webhook 特点:
1. 多节点执行,任意节点服务器都可以作为master服务器
Expand Down Expand Up @@ -98,3 +98,30 @@ CI/CD 打包docker镜像后,推送到`阿里云`镜像仓库\
匹配`POST`内容`"tag":"tag1"`中的`tag1`并将最终拼接为执行命令`command -a=tag1`
- *注意当 `hook`内没有定义`command`值则不会在对应的节点服务器执行,用于定义`webhook中心服务器`*

三.访问 Multi-Node-Webhook 并执行webhook
---
启动
./multi-node-webhook -c config.json -id master
访问URL
> http://{ip}:{port}/{hookKey}?node=1
- `ip` 服务器IP
- `port` 服务器端口
- `hookKey` 配置中hook脚本key
- `node` 仅限`当前节点`执行,不执行集群更新

四. 服务方式启动

vim /lib/systemd/system/node-webhook.service
```bash
[Unit]
Description=Multi-node HTTP Endpoints Server (Multi-node Webhook Tools)
Documentation=https://github.com/haierspi/multi-node-webhook-go
ConditionPathExists=/data/config.json

[Service]
ExecStart=/data/multi-node-webhook -c /data/config.json -id master

[Install]
WantedBy=multi-user.target
```
14 changes: 2 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"nodes" :[
{
"id": "master",
"host": ":8888"
},
{
"id": "node1",
"host": "127.0.0.1:6666"
"host": ":6000"
}
],
"hooks": [
Expand All @@ -15,13 +11,7 @@
"commands": [
{
"id": "master",
"command": "ls",
"display": true,
"parm_bind": "{\"-a=\":\"\\\"tag\\\":\\\"([a-z0-9.-]+)\\\"\"}"
},
{
"id": "node1",
"command": "ls",
"command": "/data/apps/dev-goapi_starfission/public_html/docker_redeploy.sh",
"display": true,
"parm_bind": "{\"-a=\":\"\\\"tag\\\":\\\"([a-z0-9.-]+)\\\"\"}"
}
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/haierspi/multi-node-webhook-go/pkg/httpclient"
"github.com/pkg/errors"
"io"
"log"
"net/http"
Expand All @@ -20,6 +18,9 @@ import (
"sync"
"syscall"
"time"

"github.com/haierspi/multi-node-webhook-go/pkg/httpclient"
"github.com/pkg/errors"
)

type Command struct {
Expand Down Expand Up @@ -196,6 +197,8 @@ func handle() http.HandlerFunc {
close(pushChan)
}()

w.WriteHeader(http.StatusOK) // 403

for msg := range pushChan {
if msg.Err != nil {
log.Printf(msg.Name+" run fail:\n%v\n", msg.Err)
Expand Down Expand Up @@ -243,6 +246,10 @@ func main() {
MaxHeaderBytes: 1 << 20,
}

log.Printf("Multi Node Webhook Is Start !Hostrun ok!\n")
log.Printf("Host:" + Host + "\n")
log.Printf("Id:" + Id + "\n")

go func() {
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("s.ListenAndServe err: %v", err)
Expand Down

0 comments on commit 772b2a2

Please sign in to comment.