代码拉取完成,页面将自动刷新
同步操作将从 koogua/course-tencent-cloud-docker 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env bash
#基准目录
base_dir=~
#站点名称
site_name=ctc-docker
#ctc-docker目录
ctc_docker_dir=${base_dir}/${site_name}
#ctc-docker备份文件
ctc_docker_tar=${base_dir}/${site_name}.tar.gz
#成功信息输出
success_print() {
echo -e "\033[32m $1 \033[0m"
}
#失败信息输出
error_print() {
echo -e "\033[31m $1 \033[0m"
}
#系统判断
os_type() {
os=$(grep "^ID=" /etc/os-release)
if [[ ${os} =~ 'centos' ]]; then
echo 'centos'
elif [[ ${os} =~ 'ubuntu' ]]; then
echo 'ubuntu'
elif [[ ${os} =~ 'debian' ]]; then
echo 'debian'
else
echo 'other'
fi
}
#判断是否root用户
if [[ $EUID -ne 0 ]]; then
error_print "\n------ error: this script must be run as root ------\n" 1>&2
exit 1
fi
#安装git和curl
if [ "$(os_type)" = 'ubuntu' ] || [ "$(os_type)" = 'debian' ]; then
sudo apt-get update && apt-get install -y curl git
elif [ "$(os_type)" = 'centos' ]; then
sudo yum update && yum install -y curl git
else
error_print "\n------ we only support (ubuntu|debian|centos) currently ------\n"
exit 1
fi
if [ ! -e ${ctc_docker_tar} ]; then
error_print "\n------ error: ctc-docker.tar.gz not found ------\n"
exit 1
fi
#解压ctc-docker.tar.gz
cd ${base_dir} && tar -xzf ${site_name}.tar.gz
#安装docker
if [ -z "$(command -v docker)" ]; then
sudo curl -sSL https://get.daocloud.io/docker | sh
sudo systemctl enable docker
fi
if [ -z "$(command -v docker)" ]; then
error_print "\n------ error: docker command not found, please try again ------\n"
exit 1
fi
if [ ! -d '/etc/docker' ]; then
sudo mkdir -p '/etc/docker'
fi
#docker镜像加速
if [ ! -e '/etc/docker/daemon.json' ]; then
sudo echo '{"registry-mirrors": ["https://mirror.ccs.tencentyun.com"]}' | tee /etc/docker/daemon.json
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo chmod 666 /var/run/docker.sock
fi
#安装docker-composer
if [ -z "$(command -v docker-compose)" ]; then
sudo curl -L "https://get.daocloud.io/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
if [ -z "$(command -v docker-compose)" ]; then
error_print "\n------ error: docker-compose command not found, please try again ------\n"
exit 1
fi
#切换到基准目录
cd ${ctc_docker_dir} || exit
#启动容器
docker-compose up -d
docker_ps=$(docker ps)
if [[ "${docker_ps}" =~ 'nginx' ]]; then
success_print "nginx service ok\n"
else
error_print "nginx service failed\n"
fi
if [[ "${docker_ps}" =~ 'php' ]]; then
success_print "php service ok\n"
else
error_print "php service failed\n"
fi
if [[ "${docker_ps}" =~ 'mysql' ]]; then
success_print "mysql service ok\n"
else
error_print "mysql service failed\n"
fi
if [[ "${docker_ps}" =~ 'redis' ]]; then
success_print "redis service ok\n"
else
error_print "redis service failed\n"
fi
if [[ "${docker_ps}" =~ 'xunsearch' ]]; then
success_print "xunsearch service ok\n"
else
error_print "xunsearch service failed\n"
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。