加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DbUtil.sh 4.17 KB
一键复制 编辑 原始数据 按行查看 历史
LSQ 提交于 2024-01-01 16:35 . update all utils file
#!/bin/bash
# *********************************************
# @author: lsq
# @date: 2021/07/20
# @modify: 2023/12/04
# @function: Operation Db easily by myself!
# *********************************************
MYSQL_PORT=16603
#MYSQL_PORT=16604
REDIS_PORT=16605
#REDIS_PORT=16606
function checkUser()
{
username=`whoami`
if [[ ! "${username}"x == "dbuser"x ]];then
echo "[ERROR] pls use dbuser to start|stop app!"
return 1
fi
}
function usage()
{
echo "usage: bash DbUtil.sh DBType ActionName"
echo "[login mysql] mysql -uroot -P16603 -h127.0.0.1"
echo "[login redis] /cloud/db/redis/redis_bin/bin/redis-cli -a redis2030 -p 16605"
}
function startMysql()
{
echo "Start Mysql now!"
mysqld_multi --defaults-file=/etc/my.cnf --log=/cloud/db/mysql/mysqld_multi.log start ${MYSQL_PORT}
sleep 3
lsof -i:${MYSQL_PORT} > /dev/null 2>&1
if [[ $? -eq 0 ]];then
echo "[INFO] Start mysql success!"
else
echo "[ERROR] Start mysql failed!"
fi
}
function startRedis()
{
echo "Start Redis now!"
}
function startPostgreSQL()
{
echo "Start PostgreSQL now!"
}
function startMongoDB()
{
echo "Start MongoDB now!"
}
function stopMysql()
{
echo "Stop Mysql now!"
mysqld_multi --defaults-file=/etc/my.cnf --log=/cloud/db/mysql/mysqld_multi.log stop ${MYSQL_PORT}
sleep 3
lsof -i:${MYSQL_PORT} > /dev/null 2>&1
if [[ $? -eq 0 ]];then
echo "[ERROR] Stop mysql failed!"
mysqlPid=`lsof -i:${MYSQL_PORT} | grep mysqld | awk '{print $2}'`
kill -9 ${mysqlPid}
lsof -i:${MYSQL_PORT} > /dev/null 2>&1
if [[ $? -eq 0 ]];then
echo "[ERROR] Stop mysql failed again!"
else
echo "[INFO] Stop mysql success!"
fi
else
echo "[INFO] Stop mysql success!"
fi
}
function stopRedis()
{
echo "Stop Mysql now!"
}
function stopPostgreSQL()
{
echo "Stop PostgreSQL now!"
}
function stopMongoDB()
{
echo "Stop MongoDB now!"
}
function statusMysql()
{
echo "Check Mysql status now!"
mysqld_multi --defaults-file=/etc/my.cnf report
}
function statusRedis()
{
echo "Check Redis status now!"
}
function statusPostgreSQL()
{
echo "Check PostgreSQL status now!"
}
function statusMongoDB()
{
echo "Check MongoDB status now!"
}
function fn_main()
{
if [[ ! $# -eq 2 ]];
then
usage
exit
fi
appName=$1
appAction=$2
checkUser || return $?
if [[ "${appName}"x == "redis"x ]];then
if [[ "${appAction}"x == "start"x ]];then
startRedis || return $?
elif [[ "${appAction}"x == "stop"x ]];then
stopRedis || return $?
elif [[ "${appAction}"x == "restart"x ]];then
restartRedis || return $?
elif [[ "${appAction}"x == "status"x ]];then
statusRedis || return $?
fi
fi
if [[ "${appName}"x == "mysql"x ]];then
if [[ "${appAction}"x == "start"x ]];then
startMysql || return $?
elif [[ "${appAction}"x == "stop"x ]];then
stopMysql || return $?
elif [[ "${appAction}"x == "restart"x ]];then
restartMysql || return $?
elif [[ "${appAction}"x == "status"x ]];then
statusMysql || return $?
fi
fi
if [[ "${appName}"x == "postgresql"x ]];then
if [[ "${appAction}"x == "start"x ]];then
startPostgreSQL || return $?
elif [[ "${appAction}"x == "stop"x ]];then
stopPostgreSQL || return $?
elif [[ "${appAction}"x == "restart"x ]];then
restartPostgreSQL || return $?
elif [[ "${appAction}"x == "status"x ]];then
statusPostgreSQL || return $?
fi
fi
if [[ "${appName}"x == "mongodb"x ]];then
if [[ "${appAction}"x == "start"x ]];then
startMongoDB || return $?
elif [[ "${appAction}"x == "stop"x ]];then
stopMongoDB || return $?
elif [[ "${appAction}"x == "restart"x ]];then
restartMongoDB || return $?
elif [[ "${appAction}"x == "status"x ]];then
statusMongoDB || return $?
fi
fi
}
fn_main "$@"
result=$?
if [[ "$result" -eq 0 ]]
then
echo "SUCCESS"
else
echo "FAILED"
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化