Skip to content

Instantly share code, notes, and snippets.

@wvv8oo
Last active August 29, 2015 14:18
Show Gist options
  • Save wvv8oo/8c18167a1792db3f438f to your computer and use it in GitHub Desktop.
Save wvv8oo/8c18167a1792db3f438f to your computer and use it in GitHub Desktop.
git hook,部署项目,并重启forever
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
#执行pull
unset $(git rev-parse --local-env-vars)
BASEDIR=/data/www
REPOSDIR=/data/repos/cisotrade.git
BRANCH=develop
build()
{
UUID=$1
PORT=$2
WORKDIR="$BASEDIR/$UUID"
echo "UUID: $UUID WorkDir: $WORKDIR"
if [ ! -d $WORKDIR ]; then
git clone $REPOSDIR $WORKDIR
cd $WORKDIR
git checkout $BRANCH
npm install
else
cd $WORKDIR
#更新代码
git pull
git checkout $BRANCH
fi
#启动服务器
if [ "`forever list | grep "/$UUID/app.coffee"`" == "" ]; then
echo "应用程序不存在,启动新的应用"
#重启应用程序
NODE_ENV=production PORT=$PORT forever start --uid "$UUID" -a -c coffee $WORKDIR/app.coffee
else
echo "应用已经存在,重启"
forever restart $UUID
fi
}
build 'cisotrade' 8001
build 'test-cisotrade' 8002
exec git update-server-info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment