function ok_msg() { echo -e "$1${BLACK}[${GREEN} OK ${BLACK}]" }
function failed_msg() { echo -e "$1${BLACK}[${RED}FAILED${BLACK}]" }
# 确定当前工作目录,并记录日志 if [[ ! -f $0 ]]; then echo "直接在 shell 中执行脚本"; work_dir=$(pwd) else echo "从文件中执行脚本: $0"; work_dir=$(dirname $0); work_dir=$(cd ${work_dir} && pwd) fi product_dir=$work_dir
# 检查并停止旧的服务 ok_msg "检查之前的安装" if [[ -f /etc/init.d/cusflo-server-moon ]]; then /etc/init.d/cusflo-server-moon status >/dev/null 2>&1 ret=$? if [[ 0 -eq $ret ]]; then failed_msg "必须先停止服务: sudo /etc/init.d/cusflo-server-moon stop"; exit 1; fi fi ok_msg "之前安装已检查"
# 备份旧版本 ok_msg "备份旧 cusflo-server-moon" install_root=$INSTALL install_bin=$install_root/ if [[ -d $install_root ]]; then backup_dir=${install_root}.`date "+%Y-%m-%d_%H-%M-%S"` ok_msg "备份安装目录" ok_msg "至 $backup_dir" mv $install_root $backup_dir 2>&1 ret=$? if [[ 0 -ne $ret ]]; then failed_msg "备份安装目录失败" exit $ret; fi ok_msg "备份安装目录成功" fi ok_msg "旧版本已备份"