|
@@ -0,0 +1,101 @@
|
|
|
+1.安装
|
|
|
+
|
|
|
+```
|
|
|
+yum install epel-release wget -y
|
|
|
+yum update
|
|
|
+yum install python-pip
|
|
|
+yum install supervisor
|
|
|
+pip install flask gunicorn pymysql sqlalchemy
|
|
|
+```
|
|
|
+
|
|
|
+2. 拷贝 webhooks 到 `/opt` 目录下
|
|
|
+
|
|
|
+3. 创建配置文件
|
|
|
+
|
|
|
+ ```
|
|
|
+ touch /etc/supervisord.d/webhook.ini
|
|
|
+ ```
|
|
|
+
|
|
|
+ 添加以下内容
|
|
|
+
|
|
|
+ ```
|
|
|
+ [program:webhooks]
|
|
|
+ command=gunicorn -w1 -b0.0.0.0:21332 --error-logfile /opt/webhooks/log/error.log --access-logfile /opt/webhooks/log/access.log webhooks:app ;应用入口
|
|
|
+ user=root
|
|
|
+ directory=/opt/webhooks ;web目录
|
|
|
+ startsecs=5 ;启动时间
|
|
|
+ stopwaitsecs=0 ;终止等待时间
|
|
|
+ startretries = 3
|
|
|
+ autostart=true ;是否自动启动
|
|
|
+ autorestart=true ;是否自动重启
|
|
|
+ redirect_stderr=true ;错误日志输出到标准日志
|
|
|
+ stdout_logfile=/dev/null ;标准日志不输出
|
|
|
+ stdout_logfile_maxbytes=10MB ;标准日志大小
|
|
|
+ environment=PYTHONPATH=$PYTHONPATH:/opt/webhooks
|
|
|
+ ```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+4. 导入数据库 修改密码
|
|
|
+
|
|
|
+ 数据库在 db 目录下的data.sql里面数据库配置在 config.py 里面
|
|
|
+
|
|
|
+ ```
|
|
|
+ SQLALCHEMY_DATABASE_SQLITE_URI = "mysql+pymysql://root:password@localhost:3306/webhook?charset=utf8"
|
|
|
+
|
|
|
+ ```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+5. 使 supervisor 自启动
|
|
|
+
|
|
|
+ ```
|
|
|
+ systemctl enable supervisord
|
|
|
+ ```
|
|
|
+
|
|
|
+ 测试
|
|
|
+
|
|
|
+ ```
|
|
|
+ curl -s http://localhost:21332/hookssync/38daa500-55a8-11e8-acd6-704d7b885ead
|
|
|
+ ```
|
|
|
+
|
|
|
+注意事项
|
|
|
+
|
|
|
+1.CentOS 防火墙记得放行21332端口或者直接关闭防火墙`systemctl stop firewalld;systemctl disable firewalld`
|
|
|
+
|
|
|
+2. 如果在除了
|
|
|
+
|
|
|
+ ```
|
|
|
+ PATH_WHITE_LIST = [
|
|
|
+ # 匹配所有
|
|
|
+ '.*',
|
|
|
+ # /app/web/test
|
|
|
+ '^/app/web/.*',
|
|
|
+ # /app/web/tests
|
|
|
+ '^/var/www/html/.*',
|
|
|
+ '/www/wwwroot/.*'
|
|
|
+ ]
|
|
|
+ ```
|
|
|
+
|
|
|
+ 目录同步代码需要修改 config.py 文件
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+如果在同步过程中需要执行其他命令需要添加规则
|
|
|
+
|
|
|
+```
|
|
|
+#允许在webhooks执行时执行的命令 使用正则表达式进行匹配
|
|
|
+EXEC_WHITE_LIST = [
|
|
|
+ # 匹配所有
|
|
|
+ '.*',
|
|
|
+ # git pull origin master
|
|
|
+ '^git pull \w+ \w+$',
|
|
|
+ # git fetch origin master && git reset --hard origin/master
|
|
|
+ '^git fetch \w+ \w+ && git reset --hard \w+/\w+$',
|
|
|
+ # git pull origin master && supervisorctl restart webhooks
|
|
|
+ '^git pull \w+ \w+ && supervisorctl restart \w+$',
|
|
|
+ # git fetch origin master && git reset --hard origin/master && supervisorctl restart webhooks
|
|
|
+ '^git fetch \w+ \w+ && git reset --hard \w+/\w+ && supervisorctl restart \w+$'
|
|
|
+]
|
|
|
+```
|
|
|
+
|