mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-21 05:44:07 -07:00
list system services
This commit is contained in:
parent
c9dca4e2cf
commit
1e2732c978
1 changed files with 205 additions and 0 deletions
205
bin/v-list-sys-services
Executable file
205
bin/v-list-sys-services
Executable file
|
@ -0,0 +1,205 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# info: list system config
|
||||||
|
# options: [FORMAT]
|
||||||
|
#
|
||||||
|
# The function for obtaining the list of system parameters.
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Variable&Function #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Argument defenition
|
||||||
|
format=${1-shell}
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
source $VESTA/conf/vesta.conf
|
||||||
|
source $VESTA/func/main.sh
|
||||||
|
|
||||||
|
get_srv_state() {
|
||||||
|
srv=$1
|
||||||
|
proc_name=${2-$1}
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
/etc/init.d/$srv status > /dev/null 2>&1
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
state='running'
|
||||||
|
|
||||||
|
# Calculate cpu and memory usage
|
||||||
|
cpu=0
|
||||||
|
mem=0
|
||||||
|
for pid in $(/sbin/pidof $proc_name); do
|
||||||
|
pid_mem=$(pmap -x $pid | tail -n1 | awk '{print $3}')
|
||||||
|
pid_cpu=$(grep "^$pid " $tmp_file | cut -f 2 -d ' ')
|
||||||
|
cpu=$((cpu + pid_cpu))
|
||||||
|
mem=$((mem + pid_mem))
|
||||||
|
done
|
||||||
|
mem=$((mem / 1024))
|
||||||
|
|
||||||
|
# Get pid date
|
||||||
|
if [ ! -z $pid ] && [ -e "/proc/$pid/cmdline" ]; then
|
||||||
|
mtime=$(stat -c "%Y" /proc/$pid/cmdline)
|
||||||
|
ptime=$(date -d @$mtime +%T)
|
||||||
|
pdate=$(date -d @$mtime +%F)
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Service is stopped
|
||||||
|
state='stopped'
|
||||||
|
mem=0
|
||||||
|
cpu=0
|
||||||
|
ptime="$TIME"
|
||||||
|
pdate="$DATE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Action #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Save current proccess list
|
||||||
|
tmp_file=$(mktemp)
|
||||||
|
ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file
|
||||||
|
|
||||||
|
# Proxy
|
||||||
|
service=$PROXY_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="NAME='$service' SYSTEM='proxy' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# Web
|
||||||
|
service=$WEB_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
if [ "$service" == 'apache' ]; then
|
||||||
|
service='httpd'
|
||||||
|
fi
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='web' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# DNS
|
||||||
|
service=$DNS_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
if [ "$service" == 'bind' ]; then
|
||||||
|
service='named'
|
||||||
|
fi
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='dns' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# MAIL
|
||||||
|
service=$MAIL_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='mail' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# IMAP
|
||||||
|
service=$IMAP_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='imap' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# ANTIVIRUS
|
||||||
|
service=$ANTIVIRUS_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
if [ "$ANTIVIRUS_SYSTEM" = 'clamav' ]; then
|
||||||
|
service='clamd'
|
||||||
|
fi
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='antivirus' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# ANTISPAM
|
||||||
|
service=$ANTISPAM_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service spamd
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='antispam' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# DB
|
||||||
|
service=$DB_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
for db in ${DB_SYSTEM//,/ }; do
|
||||||
|
service="$db"
|
||||||
|
if [ "$service" == 'mysql' ] && [ ! -e "/etc/init.d/$service" ]; then
|
||||||
|
service='mysqld'
|
||||||
|
fi
|
||||||
|
get_srv_state $service
|
||||||
|
str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu''"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# FTP
|
||||||
|
service=$FTP_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# CRON
|
||||||
|
service=$CRON_SYSTEM
|
||||||
|
spnd='yes'
|
||||||
|
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
|
||||||
|
spnd='no'
|
||||||
|
get_srv_state $service
|
||||||
|
fi
|
||||||
|
str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'"
|
||||||
|
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
|
||||||
|
|
||||||
|
# Defining config
|
||||||
|
|
||||||
|
echo -e "$str" > $tmp_file
|
||||||
|
conf=$tmp_file
|
||||||
|
|
||||||
|
# Defining fileds to select
|
||||||
|
fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$SUSPENDED \$TIME \$DATE"
|
||||||
|
|
||||||
|
# Listing services
|
||||||
|
case $format in
|
||||||
|
json) json_list ;;
|
||||||
|
plain) nohead=1; shell_list ;;
|
||||||
|
shell) fields='$NAME $STATE $CPU $MEM $SUSPENDED $TIME $DATE'
|
||||||
|
shell_list | column -t ;;
|
||||||
|
*) check_args '1' '0' 'USER [FORMAT]'
|
||||||
|
esac
|
||||||
|
|
||||||
|
rm -f $tmp_file
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Vesta #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
exit
|
Loading…
Add table
Add a link
Reference in a new issue