Skip to content

Commit 866d18e

Browse files
committed
整理项目文件
1 parent cff3d83 commit 866d18e

File tree

7 files changed

+79
-123
lines changed

7 files changed

+79
-123
lines changed

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Binaries for programs and plugins
2-
supervisor-event-listener
2+
supervisor-eventlistener
33
*.exe
44
*.dll
55
*.so
@@ -12,8 +12,7 @@ supervisor-event-listener
1212
*.out
1313

1414
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
15-
.glide/
16-
.idear
15+
.*/
1716
vendor/**/*.yml
1817
vendor/**/.gitignore
19-
build/
18+
build/

.vscode/launch.json

-17
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 qiang.ou
3+
Copyright (c) 2017-2021 qiang.ou
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
project_name:=supervisor-event-listener
2-
project_version:=1.2.2
1+
project_name:=supervisor-eventlistener
2+
project_version:=1.2.3
33
root_dir := $(abspath $(CURDIR))
44
build_dir := $(root_dir)/build
55
GOPATH := ${HOME}/go
66

77

8-
.PHONY: clean
98
clean:
109
rm -fr $(build_dir)
1110

12-
.PHONY: build-bydocker
11+
1312
build-bydocker:
1413
sudo docker run -it --rm \
1514
-v $(GOPATH)/:/root/go/ \
1615
-v $(root_dir)/:/$(project_name) \
1716
-w /$(project_name)/ \
18-
golang:1.16.2-buster \
17+
golang:1.17.0-buster \
1918
make build
2019

2120

22-
.PHONY: build
2321
build:
24-
GO111MODULE=on go build -o $(project_name) ./$(project_name).go
22+
GO111MODULE=on go build -o $(project_name) ./main.go
2523

2624

27-
.PHONY: release
2825
release: clean build-bydocker
29-
mkdir -p $(build_dir)/$(project_name)/
30-
mv ./supervisor-event-listener $(build_dir)/$(project_name)/
31-
cp ./supervisor-event-listener.toml $(build_dir)/$(project_name)/
26+
mkdir -p $(build_dir)/$(project_name)/
27+
mv ./supervisor-eventlistener $(build_dir)/$(project_name)/
28+
cp ./conf/config.toml $(build_dir)/$(project_name)/
3229
cd $(build_dir) && tar -zcvf $(project_name)-$(project_version).tar.gz $(project_name)
30+
@echo ...created $(build_dir)/$(project_name)-$(project_version).tar.gz
3331
@echo ...done.
3432

3533

@@ -38,19 +36,21 @@ log:
3836
tmux split-window -t "dev:0"
3937
tmux split-window -t "dev:0.0" -h
4038
tmux split-window -t "dev:0.2" -h
41-
tmux send-keys -t "dev:0.0" "bash -c 'tail -f /tmp/supervisor-event-listener.log'" Enter
42-
tmux send-keys -t "dev:0.1" "bash -c 'sudo supervisorctl tail -f supervisor-event-listener'" Enter
39+
tmux send-keys -t "dev:0.0" "bash -c 'tail -f /tmp/supervisor-eventlistener.log'" Enter
40+
tmux send-keys -t "dev:0.1" "bash -c 'sudo supervisorctl tail -f $(project_name)'" Enter
4341
tmux set-option -g mouse on
4442
tmux attach -t dev
4543
tmux kill-session -t dev
4644

4745

4846
test-integration:
4947
go build
50-
sudo supervisorctl stop supervisor-event-listener
51-
sudo cp ./supervisor-event-listener /usr/local/bin/
48+
sudo supervisorctl stop $(project_name)
49+
sudo cp ./$(project_name) /usr/local/bin/
5250
sudo cp ./tests/supervisor-app.ini /etc/supervisor.d/
53-
sudo supervisorctl remove supervisor-event-listener
54-
sudo supervisorctl update supervisor-event-listener
55-
sudo supervisorctl tail -f supervisor-event-listener stderr
51+
sudo supervisorctl remove $(project_name)
52+
sudo supervisorctl update $(project_name)
53+
sudo supervisorctl tail -f $(project_name) stderr
54+
5655

56+
.PHONY: clean build build-bydocker release log test-integration

README.md

+57-79
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,57 @@
1-
# supervisor-event-listener
2-
Supervisor事件通知, 支持邮件, Slack, WebHook
3-
4-
## 简介
5-
Supervisor是*nix环境下的进程管理工具, 可以把前台进程转换为守护进程, 当进程异常退出时自动重启.
6-
supervisor-event-listener监听进程异常退出事件, 并发送通知.
7-
8-
## 下载
9-
[v1.0](https://github.com/ouqiang/supervisor-event-listener/releases)
10-
11-
### 源码安装
12-
* `go get -u github.com/ouqiang/supervisor-event-listener`
13-
14-
## Supervisor配置
15-
```ini
16-
[eventlistener:supervisor-event-listener]
17-
; 默认读取配置文件/etc/supervisor-event-listener.ini
18-
command=/path/to/supervisor-event-listener
19-
; 指定配置文件路径
20-
;command=/path/to/supervisor-event-listener -c /path/to/supervisor-event-listener.ini
21-
events=PROCESS_STATE_EXITED
22-
......
23-
```
24-
25-
## 配置文件, 默认读取`/etc/supervisor-event-listener.ini`
26-
27-
```ini
28-
[default]
29-
# 通知类型 mail,slack,webhook 只能选择一种
30-
notify_type = mail
31-
32-
# 邮件服务器配置
33-
mail.server.user = [email protected]
34-
mail.server.password = 123456
35-
mail.server.host = smtp.163.com
36-
mail.server.port = 25
37-
38-
# 邮件收件人配置, 多个收件人, 逗号分隔
39-
mail.user = [email protected]
40-
41-
# Slack配置
42-
slack.webhook_url = https://hooks.slack.com/services/xxxx/xxx/xxxx
43-
slack.channel = exception
44-
45-
# WebHook通知URL配置
46-
webhook_url = http://my.webhook.com
47-
48-
```
49-
50-
## 通知内容
51-
邮件、Slack
52-
```shell
53-
Process: process-name
54-
Host: ip(hostname)
55-
EXITED FROM state: RUNNING
56-
PID: 6152
57-
```
58-
WebHook, Post请求, 字段含义查看Supervisor文档
59-
```json
60-
{
61-
"Header": {
62-
"Ver": "3.0",
63-
"Server": "supervisor",
64-
"Serial": 11,
65-
"Pool": "supervisor-listener",
66-
"PoolSerial": 11,
67-
"EventName": "PROCESS_STATE_EXITED",
68-
"Len": 84
69-
},
70-
"Payload": {
71-
"Ip": "ip(hostname)",
72-
"ProcessName": "process-name",
73-
"GroupName": "group-name",
74-
"FromState": "RUNNING",
75-
"Expected": 0,
76-
"Pid": 6371
77-
}
78-
}
79-
```
1+
# Introduction
2+
A `eventlistener` for supervisor, it may listen and redirect events to e-mail, webhook, slack and so on.
3+
More details http://supervisord.org/events.html
4+
5+
# Features
6+
* support e-mail, webhook, slack
7+
* support bearychat, lack(feishu)
8+
9+
# Usage
10+
11+
1. setup supervisor-eventlistener
12+
```toml
13+
[mail]
14+
15+
server_user = "[email protected]"
16+
server_password = "123456"
17+
server_host = "smtp.163.com"
18+
server_port = 25
19+
20+
[slack]
21+
url = "https://hooks.slack.com/services/xxxx/xxx/xxxx"
22+
channel = "exception"
23+
timeout = 6
24+
25+
[webhook]
26+
url = "http://my.webhook.com"
27+
timeout = 6
28+
29+
[bearychat]
30+
url = "https://hook.bearychat.com/xxx/xxxx"
31+
channel = "alert"
32+
timeout = 6
33+
34+
[feishu]
35+
url = "https://hook.feishu.com/xxx/xxxx?signKey=it_is_optional"
36+
timeout = 6
37+
```
38+
39+
2. setup supervisor
40+
```ini
41+
[eventlistener:supervisor-event-listener]
42+
command=/usr/local/bin/supervisor-event-listener -c /etc/supervisor-event-listener.toml
43+
user=nobody
44+
group=nobody
45+
events=
46+
PROCESS_STATE_EXITED,
47+
PROCESS_STATE_FATAL,
48+
PROCESS_STATE_STOPPED,
49+
PROCESS_STATE_RUNNING
50+
```
51+
52+
3. start supervisor-eventlistener
53+
```bash
54+
supervisorctl start supervisor-event-listener
55+
```
56+
57+
That's all.

supervisor-event-listener.toml renamed to conf/config.toml

-4
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,20 @@ server_password = "123456"
55
server_host = "smtp.163.com"
66
server_port = 25
77

8-
98
[slack]
109
url = "https://hooks.slack.com/services/xxxx/xxx/xxxx"
1110
channel = "exception"
1211
timeout = 6
1312

14-
1513
[webhook]
1614
url = "http://my.webhook.com"
1715
timeout = 6
1816

19-
2017
[bearychat]
2118
url = "https://hook.bearychat.com/xxx/xxxx"
2219
channel = "alert"
2320
timeout = 6
2421

25-
2622
[feishu]
2723
url = "https://hook.feishu.com/xxx/xxxx?signKey=it_is_optional"
2824
timeout = 6
File renamed without changes.

0 commit comments

Comments
 (0)