安装配置git-webhook
安装mysql, redis
基础安装
创建数据库
CREATE DATABASE `git_webhook` /*!40100 DEFAULT CHARACTER SET dec8 */;
安装git-webhook
安装python2.7
pip安装
创建配置
初始化数据库结构
运行应用
pip install git-webhook
gitwebhook config
gitwebhook createdb
gitwebhook 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 running
check_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 0
if [[ ! -n "$s" ]] ; then
return 0
fi
# If somethig was returned by the ps command, this function returns the PID
return $s
}
# Starts the application
start() {
# At first checks if the application is already started calling the check_status
# function
pid=$(check_status)
if [[ "$pid" -eq "" ]]
then
pid=0
fi
if [ $pid -ne 0 ] ; then
echo "The application is already started"
return
fi
# If the application isn't running, starts it
echo -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 application
stop() {
# Like as the start function, checks the application status
pid=$(check_status)
if [[ "$pid" -eq "" ]]
then
pid=0
fi
if [ $pid -eq 0 ] ; then
echo "Application is already stopped"
return
fi
# Kills the application process
echo -n "Stopping application: "
kill -9 $pid &
echo "OK"
}
# Redeploys the application
redeploy() {
stop
currentDir=`pwd`
#echo $currentDir
cd $d
git pull
mvn clean install -DskipTests
cd $currentDir
#echo `pwd`
start
}
# Show the application status
status() {
# The check_status function, again...
pid=$(check_status)
# If the PID was returned means the application is running
if [ "$pid" -ne 0 ] ; then
echo "Application is started: $pid"
else
echo "Application is stopped"
fi
}
# global var
# a is short for application name
# b is short for basename
# d is short for directory
a=`find ~/$2 -name "$2*.jar"`
if [[ ! -n "$a" ]]; then
echo "Application not found"
exit 0
else
echo "Found application at $a"
fi
b=`basename $a`
d="$HOME/$2"
# Main logic, a simple case to call functions
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
redeploy)
redeploy
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status} appname"
exit 1
esac
exit 0