You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							88 lines
						
					
					
						
							2.4 KiB
						
					
					
				
			
		
		
	
	
							88 lines
						
					
					
						
							2.4 KiB
						
					
					
				#!/bin/bash
 | 
						|
# info: list db status
 | 
						|
# options:
 | 
						|
#
 | 
						|
# v-list-sys-db-status
 | 
						|
#
 | 
						|
# This function lists db server status
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                Variables & Functions                     #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Argument definition
 | 
						|
#format=${1-shell}
 | 
						|
 | 
						|
# Includes
 | 
						|
# shellcheck source=/etc/hestiacp/hestia.conf
 | 
						|
source /etc/hestiacp/hestia.conf
 | 
						|
# shellcheck source=/usr/local/hestia/func/main.sh
 | 
						|
source $HESTIA/func/main.sh
 | 
						|
# load config file
 | 
						|
source_conf "$HESTIA/conf/hestia.conf"
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Action                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
# Checking db system
 | 
						|
if [ -z "$DB_SYSTEM" ]; then
 | 
						|
	exit
 | 
						|
fi
 | 
						|
 | 
						|
# Checking supported database systems
 | 
						|
for db in $(echo $DB_SYSTEM | tr ',' '\n'); do
 | 
						|
	OLD_IFS="$IFS"
 | 
						|
	IFS=$'\n'
 | 
						|
 | 
						|
	# Checking database config
 | 
						|
	if [ -e "$HESTIA/conf/$db.conf" ]; then
 | 
						|
 | 
						|
		# Checking server status
 | 
						|
		for host_str in $(cat $HESTIA/conf/$db.conf); do
 | 
						|
			parse_object_kv_list "$host_str"
 | 
						|
 | 
						|
			# Checking MySQL
 | 
						|
			if [ "$db" = 'mysql' ]; then
 | 
						|
				mycnf="$HESTIA/conf/.mysql.$HOST"
 | 
						|
				if [ ! -e "$mycnf" ]; then
 | 
						|
					echo "[client]" > $mycnf
 | 
						|
					echo "host='$HOST'" >> $mycnf
 | 
						|
					echo "user='$USER'" >> $mycnf
 | 
						|
					echo "password='$PASSWORD'" >> $mycnf
 | 
						|
					chmod 600 $mycnf
 | 
						|
				else
 | 
						|
					mypw=$(grep password $mycnf | cut -f 2 -d \')
 | 
						|
					if [ "$mypw" != "$PASSWORD" ]; then
 | 
						|
						echo "[client]" > $mycnf
 | 
						|
						echo "host='$HOST'" >> $mycnf
 | 
						|
						echo "user='$USER'" >> $mycnf
 | 
						|
						echo "password='$PASSWORD'" >> $mycnf
 | 
						|
						chmod 660 $mycnf
 | 
						|
					fi
 | 
						|
				fi
 | 
						|
				echo "MySQL $HOST status"
 | 
						|
				mysqladmin --defaults-file=$mycnf status | sed -e "s/  /\n/g"
 | 
						|
				echo
 | 
						|
				mysqladmin --defaults-file=$mycnf processlist
 | 
						|
				echo -en "\n---------------------------------------------"
 | 
						|
				echo -en "---------------------------------------------\n\n"
 | 
						|
			fi
 | 
						|
 | 
						|
			# Checking PostgreSQL
 | 
						|
			if [ "$db" = 'pgsql' ] && [ ! -z "$(which psql)" ]; then
 | 
						|
				echo "PostgreSQL $HOST status"
 | 
						|
				export PGPASSWORD="$PASSWORD"
 | 
						|
				psql -h $HOST -U $USER -c "SELECT * FROM pg_stat_activity"
 | 
						|
			fi
 | 
						|
		done
 | 
						|
	fi
 | 
						|
	IFS="$OLD_IFS"
 | 
						|
done
 | 
						|
 | 
						|
#----------------------------------------------------------#
 | 
						|
#                       Hestia                             #
 | 
						|
#----------------------------------------------------------#
 | 
						|
 | 
						|
exit
 |