安装配置git-webhook
安装mysql, redis
基础安装
创建数据库
CREATE DATABASE `git_webhook` /*!40100 DEFAULT CHARACTER SET dec8 */;
安装git-webhook
安装python2.7
pip安装
创建配置
初始化数据库结构
运行应用
pip install git-webhookgitwebhook configgitwebhook createdbgitwebhook runserver & gitwebhook celery &
配置WebHook
在网页中获取WebHook的URL
在github中添加连接并测试(JSON格式)
git保存密码
git config —global credential.helper store
部署脚本
#!/bin/sh## service script# Check the application status## This function checks if the application is runningcheck_status() {# Running ps with some arguments to check if the PID exists# -C : specifies the command name# -o : determines how columns must be displayed# h : hides the data header# s=`ps -C 'java -jar ~/ushare/target/ushare-0.0.1-SNAPSHOT.jar' -o pid h`s=`ps -ef | grep -v 'grep' | grep $b | awk '{print $2}'`echo $s# In any another case, return 0if [[ ! -n "$s" ]] ; thenreturn 0fi# If somethig was returned by the ps command, this function returns the PIDreturn $s}# Starts the applicationstart() {# At first checks if the application is already started calling the check_status# functionpid=$(check_status)if [[ "$pid" -eq "" ]]thenpid=0fiif [ $pid -ne 0 ] ; thenecho "The application is already started"returnfi# If the application isn't running, starts itecho -n "Starting application: "# Redirects default and error output to a log file#java -jar /path/to/application.jar >> /path/to/logfile 2>&1 &java -jar $a >> ~/logs/console.log 2>&1 &echo "OK"}# Stops the applicationstop() {# Like as the start function, checks the application statuspid=$(check_status)if [[ "$pid" -eq "" ]]thenpid=0fiif [ $pid -eq 0 ] ; thenecho "Application is already stopped"returnfi# Kills the application processecho -n "Stopping application: "kill -9 $pid &echo "OK"}# Redeploys the applicationredeploy() {stopcurrentDir=`pwd`#echo $currentDircd $dgit pullmvn clean install -DskipTestscd $currentDir#echo `pwd`start}# Show the application statusstatus() {# The check_status function, again...pid=$(check_status)# If the PID was returned means the application is runningif [ "$pid" -ne 0 ] ; thenecho "Application is started: $pid"elseecho "Application is stopped"fi}# global var# a is short for application name# b is short for basename# d is short for directorya=`find ~/$2 -name "$2*.jar"`if [[ ! -n "$a" ]]; thenecho "Application not found"exit 0elseecho "Found application at $a"fib=`basename $a`d="$HOME/$2"# Main logic, a simple case to call functionscase "$1" instart)start;;stop)stop;;status)status;;redeploy)redeploy;;restart)stopstart;;*)echo "Usage: $0 {start|stop|restart|reload|status} appname"exit 1esacexit 0
