Skip to content

Commit 26c8b72

Browse files
committed
fix after merge
1 parent 7d32630 commit 26c8b72

File tree

1 file changed

+0
-191
lines changed

1 file changed

+0
-191
lines changed

bin/v-list-sys-services

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,193 +1,3 @@
1-
<<<<<<< HEAD
2-
#!/bin/bash
3-
# info: list system config
4-
# options: [FORMAT]
5-
#
6-
# The function for obtaining the list of system parameters.
7-
8-
9-
#----------------------------------------------------------#
10-
# Variable&Function #
11-
#----------------------------------------------------------#
12-
13-
# Argument defenition
14-
format=${1-shell}
15-
16-
# Includes
17-
source $VESTA/conf/vesta.conf
18-
source $VESTA/func/main.sh
19-
20-
get_srv_state() {
21-
srv=$1
22-
proc_name=${2-$1}
23-
24-
# Check service status
25-
/etc/init.d/$srv status > /dev/null 2>&1
26-
if [ $? -eq 0 ]; then
27-
state='running'
28-
29-
# Calculate cpu and memory usage
30-
cpu=0
31-
mem=0
32-
for pid in $(/sbin/pidof $proc_name); do
33-
pid_mem=$(pmap -x $pid | tail -n1 | awk '{print $3}')
34-
pid_cpu=$(grep "^$pid " $tmp_file | cut -f 2 -d ' ')
35-
cpu=$((cpu + pid_cpu))
36-
mem=$((mem + pid_mem))
37-
done
38-
mem=$((mem / 1024))
39-
40-
# Get pid date
41-
if [ ! -z $pid ] && [ -e "/proc/$pid/cmdline" ]; then
42-
mtime=$(stat -c "%Y" /proc/$pid/cmdline)
43-
rtime=$((ctime - mtime))
44-
rtime=$((rtime / 60))
45-
fi
46-
else
47-
# Service is stopped
48-
state='stopped'
49-
mem=0
50-
cpu=0
51-
rtime="0"
52-
fi
53-
}
54-
55-
56-
#----------------------------------------------------------#
57-
# Action #
58-
#----------------------------------------------------------#
59-
60-
# Save current proccess list
61-
tmp_file=$(mktemp)
62-
if [ "$format" = 'json' ]; then
63-
ps aux | awk '{print $2" "$3}' | tr -d '.' > $tmp_file
64-
else
65-
ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file
66-
fi
67-
68-
# Get current time
69-
ctime=$(date +%s)
70-
71-
# Proxy
72-
service=$PROXY_SYSTEM
73-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
74-
get_srv_state $service
75-
str="NAME='$service' SYSTEM='reverse proxy' STATE='$state' CPU='$cpu'"
76-
str="$str MEM='$mem' RTIME='$rtime'"
77-
fi
78-
79-
# Web
80-
service=$WEB_SYSTEM
81-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
82-
if [ "$service" == 'apache' ]; then
83-
service='httpd'
84-
fi
85-
get_srv_state $service
86-
str="$str\nNAME='$service' SYSTEM='web server' STATE='$state' CPU='$cpu'"
87-
str="$str MEM='$mem' RTIME='$rtime'"
88-
89-
fi
90-
91-
# DNS
92-
service=$DNS_SYSTEM
93-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
94-
if [ "$service" == 'bind' ]; then
95-
service='named'
96-
fi
97-
get_srv_state $service
98-
str="$str\nNAME='$service' SYSTEM='dns server' STATE='$state' CPU='$cpu'"
99-
str="$str MEM='$mem' RTIME='$rtime'"
100-
fi
101-
102-
# MAIL
103-
service=$MAIL_SYSTEM
104-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
105-
get_srv_state $service
106-
str="$str\nNAME='$service' SYSTEM='mail server' STATE='$state' CPU='$cpu'"
107-
str="$str MEM='$mem' RTIME='$rtime'"
108-
fi
109-
110-
# IMAP
111-
service=$IMAP_SYSTEM
112-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
113-
get_srv_state $service
114-
str="$str\nNAME='$service' SYSTEM='pop/imap server' STATE='$state'"
115-
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
116-
fi
117-
118-
# ANTIVIRUS
119-
service=$ANTIVIRUS_SYSTEM
120-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
121-
if [ "$ANTIVIRUS_SYSTEM" = 'clamav' ]; then
122-
service='clamd'
123-
fi
124-
get_srv_state $service
125-
str="$str\nNAME='$service' SYSTEM='email antivirus' STATE='$state'"
126-
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
127-
fi
128-
129-
# ANTISPAM
130-
service=$ANTISPAM_SYSTEM
131-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
132-
get_srv_state $service spamd
133-
str="$str\nNAME='$service' SYSTEM='email antispam' STATE='$state'"
134-
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
135-
fi
136-
137-
# DB
138-
service=$DB_SYSTEM
139-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
140-
for db in ${DB_SYSTEM//,/ }; do
141-
service="$db"
142-
if [ "$service" == 'mysql' ] && [ ! -e "/etc/init.d/$service" ]; then
143-
service='mysqld'
144-
fi
145-
get_srv_state $service
146-
str="$str\nNAME='$service' SYSTEM='database server' STATE='$state'"
147-
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
148-
done
149-
fi
150-
151-
# FTP
152-
service=$FTP_SYSTEM
153-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
154-
get_srv_state $service
155-
str="$str\nNAME='$service' SYSTEM='ftp server' STATE='$state' CPU='$cpu'"
156-
str="$str MEM='$mem' RTIME='$rtime'"
157-
fi
158-
159-
# CRON
160-
service=$CRON_SYSTEM
161-
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
162-
get_srv_state $service
163-
str="$str\nNAME='$service' SYSTEM='job scheduler' STATE='$state'"
164-
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
165-
fi
166-
167-
# Defining config
168-
echo -e "$str" > $tmp_file
169-
conf=$tmp_file
170-
171-
# Defining fileds to select
172-
fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$RTIME"
173-
174-
# Listing services
175-
case $format in
176-
json) json_list ;;
177-
plain) nohead=1; shell_list ;;
178-
shell) fields='$NAME $STATE $CPU $MEM $RTIME'
179-
shell_list | column -t ;;
180-
*) check_args '1' '0' 'USER [FORMAT]'
181-
esac
182-
183-
rm -f $tmp_file
184-
185-
#----------------------------------------------------------#
186-
# Vesta #
187-
#----------------------------------------------------------#
188-
189-
exit
190-
=======
1911
#!/bin/bash
1922
# info: list system services
1933
# options: [FORMAT]
@@ -376,4 +186,3 @@ rm -f $tmp_file
376186
#----------------------------------------------------------#
377187

378188
exit
379-
>>>>>>> 6bd00c9e5ea0ba53c998291dec65f9d20a9ce49b

0 commit comments

Comments
 (0)