作者 yangfu

build shell

#!/usr/bin/env bash
##部署脚本/文件路径
deploy_shell_path="/home/tiptok/test/ability.tar"
go build -o ability main.go
chmod +x ability
tar -zcvf ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh
... ...
#!/bin/bash
time=$(date +%Y%m%d_%H%m%s)
project_name="ability"
##部署脚本/文件路径
deploy_shell_path="/home/tiptok/test"
##部署路径
project_root_path="/home/tiptok/www"
project_path="${project_root_path}/${project_name}"
##备份路径
project_bak_path="/home/tiptok/www/bin_bak"
projcet_bak_file="${project_bak_path}/${time}_${project_name}.tar"
project_gzip_file="${deploy_shell_path}/${project_name}.tar"
echo "------begin deploy-------"
echo "ProjectName: ${project_name}"
echo "ProjectPath: ${project_path}"
echo "ProjectBakFile : ${projcet_bak_file}"
echo "ProjectGzipFile : ${project_gzip_file}"
if [ ! -d ${project_bak_path} ];then
mkdir -p ${project_bak_path}
echo "mkdir ${project_bak_path}"
fi
if [ ! -d ${project_path} ];then
mkdir -p ${project_path}
echo "mkdir ${project_path}"
else
echo "backup : ${projcet_bak_file}"
cd $project_path && tar -zcf ${projcet_bak_file} * ||(echo "backup failed"; exit 1)
rm -fr "${project_path}/" *
fi
echo "------begin tar-------"
if [ ! -e ${project_path} ];then
mkdir -p ${project_path}
echo "mkdir ${project_path}"
fi
if [ -f ${project_gzip_file} ];then
tar -xzf ${project_gzip_file} -C "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
rm -fr ${project_gzip_file}
else
echo "project_gzip_file not exists! please upload zip file ..."
exit 0
fi
echo "------begin start-------"
cd ${project_path} && ./start.sh ${project_name}
... ...
... ... @@ -34,6 +34,7 @@ func init() {
//panic(err)
}
orm.NewBeeormEngine(config.Mysql{
AliasName:"default",
DataSource: beego.AppConfig.String("data_source"),
MaxIdle: 100,
MaxOpen: 100,
... ...
#!/bin/bash
pwd=`pwd`
target=`basename $pwd`
# Kill running program
pid=`ps -C ${target} -o pid=`
if [ -n "$pid" ]; then
echo "Stopping old version, PID: ${pid}"
if [ "$1" = "-f" ]; then
# force shutdown
echo "Force shutdown..."
kill $(ps -C ${target} -o pid=)
else
kill -s 2 $(ps -C ${target} -o pid=)
fi
# wait for program to stop
pid=`ps -C ${target} -o pid=`
while [ -n "$pid" ]; do
sleep 1
done
fi
# Rollback
if [ -f "${target}-backup" ]; then
echo "Rolling back..."
if [ -f "${target}" ]; then
rm "${target}"
fi
mv ${target}-backup ${target}
echo "Rollback Complete"
fi
# run
echo "Starting..."
./run.sh ${target}
echo "Done"
\ No newline at end of file
... ... @@ -17,6 +17,7 @@ if [ -n "$pid" ]; then
pid=`ps -C ${target} -o pid=`
while [ -n "$pid" ]; do
sleep 1
pid=`ps -C ${target} -o pid=`
done
fi
... ...