Skip to content

Instantly share code, notes, and snippets.

@ktmud
Created November 12, 2012 11:59
Show Gist options
  • Save ktmud/4058979 to your computer and use it in GitHub Desktop.
Save ktmud/4058979 to your computer and use it in GitHub Desktop.
Git部署多个NodeJS应用
#... 加入你的启动脚本中
su www -c "/srv/nodejs/nogo.sh weixin halt reboot"
su www -c "/srv/nodejs/nogo.sh loudlaw halt reboot"
#!/bin/bash
function DEBUG()
{
[ "$_DEBUG" == "on" ] && $@
}
DEBUG set -x
DEBUG set -v
site=$1
old_rev=$2
new_rev=$3
if [[ -z $site ]]; then
echo "Must say what's app~"
exit 0
fi
export NODE_ENV="vps"
logfile="/srv/log/nodejs/$site.log"
pidfile="/srv/nodejs/run/$site.pid"
siteroot="/srv/nodejs/$site"
if [[ ! -d $siteroot ]]; then
echo "No such app."
exit 0
fi
echo "进入目录.."
cd $siteroot
echo "安装 npm 包.."
npm install --production
if [[ -z $old_rev ]]; then
old_rev='prev'
fi
[ -f "/srv/nodejs/run/" ] || mkdir -p /srv/nodejs/run/
pid=$(cat $pidfile 2>/dev/null)
if [[ -z $pid ]]; then
echo "尚未运行,正在启动"
Re=''
else
echo "正在重启: $pid"
kill $pid
Re='Re'
echo "
=============== End of ${old_rev} ============
" >> $logfile
fi
date=`date`
echo "
DATETIME: ${date}
============ ${Re}start: ${new_rev} ==========
" >> $logfile
node app.js >> $logfile 2>&1 &
sleep 1
if [[ $! -gt 0 && `ps $! | grep $!` ]]; then
echo "好了,现在 $site 运行在 $!"
echo $! > $pidfile
else
echo "[可耻地失败了!]"
fi
#vim: ft=bash
#!/bin/bash
read old_rev new_rev ref_name
echo $ref_name
siteroot=/srv/nodejs/THE_APP
GIT_WORK_TREE=$siteroot git checkout -f
/srv/nodejs/nogo THE_APP $old_rev $new_rev
#vim: ft=bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment