123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #!/bin/bash
- # 公共函数集合
- yellow_echo () { echo -e "\033[31m `date +"%F %T"`: $1 \033[0m " ; }
- green_echo () { echo -e "\033[32m `date +"%F %T"`: $1 \033[0m " ; }
- blue_echo () { echo -e "\033[34m `date +"%F %T"`: $1 \033[0m " ; }
- red_echo () { echo -e "\033[33m `date +"%F %T"`: $1 \033[0m" ; }
- function get_platform() {
- uname=$(uname -s)
- if [ "$uname" == "Darwin" ] ;then
- platform="macosx"
- else
- platform="linux"
- fi
- echo $platform
- }
- function set_global() {
- # temp_path=$(dirname "$0")
- # cd $temp_path
- real_path=$(pwd)
- echo $real_path
- log_config_file="$real_path/run/etc/common.conf"
- config_file="$real_path/run/etc/machine.conf"
- [ ! -f $config_file ] && red_echo "配置文件 $config_file 不存在,退出脚本" && exit
- if [ "$1" != "nolog" ]; then
- echo "本脚本文件所在目录路径是:$real_path"
- fi
- }
- function is_debug() {
- real_path=$(pwd)
- value=public
- common_file="$real_path/run/etc/common.conf"
- if grep -q "mode = " $common_file ; then
- value=`grep "mode = " $common_file | head -n1 | cut -d= -f2`
- fi
- result=$(echo "$value" | grep debug)
- if [[ "$result" != "" ]] ; then
- echo true
- else
- echo false
- fi
- }
- # 检查当前模式是否为debug,不是直接退出
- function check_debug() {
- isDebug=`is_debug`
- if ! $isDebug ; then
- red_echo "当前不是DEBUG模式,不能使用kill关闭进程,请使用STOP命令,如果仍无法关闭进程,请直接使用【kill -9 进程号】强制关闭进程" && exit
- fi
- }
- function get_config() {
- arg1=$1
- grep -q "$arg1 = " $config_file || (red_echo "文件$config_file 中不存在$arg1 配置" && exit)
- value=`grep "$arg1 = " $config_file | head -n1 | cut -d= -f2`
- echo $value
- }
- # 日志
- function get_log_config() {
- arg1=$1
- grep -q "$arg1 = " $log_config_file || (red_echo "文件$log_config_file 中不存在$arg1 配置" && exit)
- value=`grep "$arg1 = " $log_config_file | head -n1 | cut -d= -f2 | cut -d\" -f2`
- echo $value
- }
- function get_config_no_log() {
- arg1=$1
- if grep -q "$arg1 = " $config_file ; then
- value=`grep "$arg1 = " $config_file | head -n1 | cut -d= -f2`
- echo $value
- fi
- }
- function get_process_list() {
- #获取配置
- plist=`get_config nodeList`
- echo $plist
- }
- # 获取节点名称
- function get_cluster_name() {
- arg1=$1
- # green_echo "node: ${arg1}"
- echo `echo ${arg1} | cut -d_ -f1`
- }
- function mk_log_dir() {
- log_dir=`get_log_config logpath`
- if [ ! -d $log_dir ]; then
- mkdir -p $log_dir
- echo "创建日志目录: $log_dir "
- fi
- }
- function mk_statistic_dir() {
- statistic_dir=`get_log_config statistic_path`
- if [ ! -d $statistic_dir ]; then
- mkdir -p $statistic_dir
- echo "创建埋点目录: $statistic_dir "
- fi
- zip_dir=`get_log_config zip_statistic_path`
- if [ ! -d $zip_dir ]; then
- mkdir -p $zip_dir
- echo "创建埋点打包目录: $zip_dir "
- fi
- }
|