Skip to content

Commit fc80b09

Browse files
committed
service manager
1 parent a3f9c8f commit fc80b09

File tree

19 files changed

+471
-83
lines changed

19 files changed

+471
-83
lines changed

bin/v-list-sys-services

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ get_srv_state() {
3939
# Get pid date
4040
if [ ! -z $pid ] && [ -e "/proc/$pid/cmdline" ]; then
4141
mtime=$(stat -c "%Y" /proc/$pid/cmdline)
42-
ptime=$(date -d @$mtime +%T)
43-
pdate=$(date -d @$mtime +%F)
42+
rtime=$((ctime - mtime))
43+
rtime=$((rtime / 60))
4444
fi
4545
else
4646
# Service is stopped
4747
state='stopped'
4848
mem=0
4949
cpu=0
50-
ptime="$TIME"
51-
pdate="$DATE"
50+
rtime="0"
5251
fi
5352
}
5453

@@ -59,139 +58,123 @@ get_srv_state() {
5958

6059
# Save current proccess list
6160
tmp_file=$(mktemp)
62-
ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file
61+
if [ "$format" = 'json' ]; then
62+
ps aux | awk '{print $2" "$3}' | tr -d '.' > $tmp_file
63+
else
64+
ps aux | awk '{print $2" "$3}' | cut -f 1 -d '.' > $tmp_file
65+
fi
66+
67+
# Get current time
68+
ctime=$(date +%s)
6369

6470
# Proxy
6571
service=$PROXY_SYSTEM
66-
spnd='yes'
6772
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
68-
spnd='no'
6973
get_srv_state $service
74+
str="NAME='$service' SYSTEM='reverse proxy' STATE='$state' CPU='$cpu'"
75+
str="$str MEM='$mem' RTIME='$rtime'"
7076
fi
71-
str="NAME='$service' SYSTEM='proxy' STATE='$state' CPU='$cpu'"
72-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
7377

7478
# Web
7579
service=$WEB_SYSTEM
76-
spnd='yes'
7780
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
78-
spnd='no'
7981
if [ "$service" == 'apache' ]; then
8082
service='httpd'
8183
fi
8284
get_srv_state $service
85+
str="$str\nNAME='$service' SYSTEM='web server' STATE='$state' CPU='$cpu'"
86+
str="$str MEM='$mem' RTIME='$rtime'"
87+
8388
fi
84-
str="$str\nNAME='$service' SYSTEM='web' STATE='$state' CPU='$cpu'"
85-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
8689

8790
# DNS
8891
service=$DNS_SYSTEM
89-
spnd='yes'
9092
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
91-
spnd='no'
9293
if [ "$service" == 'bind' ]; then
9394
service='named'
9495
fi
9596
get_srv_state $service
97+
str="$str\nNAME='$service' SYSTEM='dns server' STATE='$state' CPU='$cpu'"
98+
str="$str MEM='$mem' RTIME='$rtime'"
9699
fi
97-
str="$str\nNAME='$service' SYSTEM='dns' STATE='$state' CPU='$cpu'"
98-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
99100

100101
# MAIL
101102
service=$MAIL_SYSTEM
102-
spnd='yes'
103103
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
104-
spnd='no'
105104
get_srv_state $service
105+
str="$str\nNAME='$service' SYSTEM='mail server' STATE='$state' CPU='$cpu'"
106+
str="$str MEM='$mem' RTIME='$rtime'"
106107
fi
107-
str="$str\nNAME='$service' SYSTEM='mail' STATE='$state' CPU='$cpu'"
108-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
109108

110109
# IMAP
111110
service=$IMAP_SYSTEM
112-
spnd='yes'
113111
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
114-
spnd='no'
115112
get_srv_state $service
113+
str="$str\nNAME='$service' SYSTEM='pop/imap server' STATE='$state'"
114+
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
116115
fi
117-
str="$str\nNAME='$service' SYSTEM='imap' STATE='$state' CPU='$cpu'"
118-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
119116

120117
# ANTIVIRUS
121118
service=$ANTIVIRUS_SYSTEM
122-
spnd='yes'
123119
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
124-
spnd='no'
125120
if [ "$ANTIVIRUS_SYSTEM" = 'clamav' ]; then
126121
service='clamd'
127122
fi
128123
get_srv_state $service
124+
str="$str\nNAME='$service' SYSTEM='email antivirus' STATE='$state'"
125+
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
129126
fi
130-
str="$str\nNAME='$service' SYSTEM='antivirus' STATE='$state' CPU='$cpu'"
131-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
132127

133128
# ANTISPAM
134129
service=$ANTISPAM_SYSTEM
135-
spnd='yes'
136130
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
137-
spnd='no'
138131
get_srv_state $service spamd
132+
str="$str\nNAME='$service' SYSTEM='email antispam' STATE='$state'"
133+
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
139134
fi
140-
str="$str\nNAME='$service' SYSTEM='antispam' STATE='$state' CPU='$cpu'"
141-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
142135

143136
# DB
144137
service=$DB_SYSTEM
145-
spnd='yes'
146138
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
147-
spnd='no'
148139
for db in ${DB_SYSTEM//,/ }; do
149140
service="$db"
150141
if [ "$service" == 'mysql' ] && [ ! -e "/etc/init.d/$service" ]; then
151142
service='mysqld'
152143
fi
153144
get_srv_state $service
154-
str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu'"
155-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
145+
str="$str\nNAME='$service' SYSTEM='database server' STATE='$state'"
146+
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
156147
done
157-
else
158-
str="$str\nNAME='$service' SYSTEM='db' STATE='$state' CPU='$cpu''"
159-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
160148
fi
161149

162150
# FTP
163151
service=$FTP_SYSTEM
164-
spnd='yes'
165152
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
166-
spnd='no'
167153
get_srv_state $service
154+
str="$str\nNAME='$service' SYSTEM='ftp server' STATE='$state' CPU='$cpu'"
155+
str="$str MEM='$mem' RTIME='$rtime'"
168156
fi
169-
str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'"
170-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
171157

172158
# CRON
173159
service=$CRON_SYSTEM
174-
spnd='yes'
175160
if [ ! -z "$service" ] && [ "$service" != 'no' ]; then
176-
spnd='no'
177161
get_srv_state $service
162+
str="$str\nNAME='$service' SYSTEM='job scheduler' STATE='$state'"
163+
str="$str CPU='$cpu' MEM='$mem' RTIME='$rtime'"
178164
fi
179-
str="$str\nNAME='$service' SYSTEM='ftp' STATE='$state' CPU='$cpu'"
180-
str="$str MEM='$mem' SUSPENDED='$spnd' TIME='$ptime' DATE='$pdate'"
181165

182166
# Defining config
183-
184167
echo -e "$str" > $tmp_file
185168
conf=$tmp_file
186169

187170
# Defining fileds to select
188-
fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$SUSPENDED \$TIME \$DATE"
171+
fields="\$NAME \$SYSTEM \$STATE \$CPU \$MEM \$RTIME"
189172

190173
# Listing services
191174
case $format in
192175
json) json_list ;;
193176
plain) nohead=1; shell_list ;;
194-
shell) fields='$NAME $STATE $CPU $MEM $SUSPENDED $TIME $DATE'
177+
shell) fields='$NAME $STATE $CPU $MEM $RTIME'
195178
shell_list | column -t ;;
196179
*) check_args '1' '0' 'USER [FORMAT]'
197180
esac

bin/v-restart-cron

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# Includes
1313
source $VESTA/conf/vesta.conf
1414
source $VESTA/func/main.sh
15-
EVENT=${1-$EVENT}
1615

1716

1817
#----------------------------------------------------------#
@@ -21,11 +20,10 @@ EVENT=${1-$EVENT}
2120

2221
# Parsing config / or just source config
2322
if [ "$CRON_SYSTEM" = 'crond' ]; then
24-
/etc/init.d/crond 'reload' &>/dev/null
23+
/etc/init.d/crond 'reload' >/dev/null 2>&1
2524
if [ $? -ne 0 ]; then
26-
/etc/init.d/crond 'restart' &>/dev/null
25+
/etc/init.d/crond 'restart' >/dev/null 2>&1
2726
if [ $? -ne 0 ]; then
28-
log_event "$E_RESTART" "$EVENT"
2927
exit $E_RESTART
3028
fi
3129
fi

bin/v-restart-dns

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
# Includes
1313
source $VESTA/conf/vesta.conf
1414
source $VESTA/func/main.sh
15-
EVENT=${1-$EVENT}
15+
1616

1717
#----------------------------------------------------------#
1818
# Action #
1919
#----------------------------------------------------------#
2020

2121
if [ "$DNS_SYSTEM" = 'bind' ]; then
22-
/etc/init.d/named reload &>/dev/null
22+
/etc/init.d/named reload >/dev/null 2>&1
2323
if [ $? -ne 0 ]; then
24-
/etc/init.d/named restart &>/dev/null
24+
/etc/init.d/named restart >/dev/null 2>&1
2525
if [ $? -ne 0 ]; then
26-
log_event "$E_RESTART" "$EVENT"
2726
exit $E_RESTART
2827
fi
2928
fi

bin/v-restart-mail

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
# Includes
1313
source $VESTA/conf/vesta.conf
1414
source $VESTA/func/main.sh
15-
EVENT=${1-$EVENT}
15+
1616

1717
#----------------------------------------------------------#
1818
# Action #
1919
#----------------------------------------------------------#
2020

2121
if [ "$MAIL_SYSTEM" = 'exim' ]; then
22-
/etc/init.d/exim reload &>/dev/null
22+
/etc/init.d/exim reload >/dev/null 2>&1
2323
if [ $? -ne 0 ]; then
24-
/etc/init.d/exim restart &>/dev/null
24+
/etc/init.d/exim restart >/dev/null 2>&1
2525
if [ $? -ne 0 ]; then
26-
log_event "$E_RESTART" "$EVENT"
2726
exit $E_RESTART
2827
fi
2928
fi

bin/v-restart-service

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# info: restart service
3+
# options: service
4+
#
5+
# The function restarts system service.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
service=$1
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
19+
#----------------------------------------------------------#
20+
# Verifications #
21+
#----------------------------------------------------------#
22+
23+
check_args '1' "$#" 'SERVICE'
24+
25+
26+
#----------------------------------------------------------#
27+
# Action #
28+
#----------------------------------------------------------#
29+
30+
if [ -x "/etc/init.d/$service" ]; then
31+
/etc/init.d/$service restart >/dev/null 2>&1
32+
if [ $? -ne 0 ]; then
33+
exit $E_RESTART
34+
fi
35+
fi
36+
37+
38+
#----------------------------------------------------------#
39+
# Vesta #
40+
#----------------------------------------------------------#
41+
42+
exit

bin/v-restart-web

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
2-
# info: restart dns service
2+
# info: restart web services
33
# options: NONE
44
#
5-
# The function tells BIND service to reload dns zone files.
5+
# The function reloads web server configuration.
66

77

88
#----------------------------------------------------------#
@@ -12,41 +12,37 @@
1212
# Includes
1313
source $VESTA/conf/vesta.conf
1414
source $VESTA/func/main.sh
15-
EVENT=${1-$EVENT}
15+
1616

1717
#----------------------------------------------------------#
1818
# Action #
1919
#----------------------------------------------------------#
2020

2121
if [ "$WEB_SYSTEM" = 'apache' ]; then
22-
/etc/init.d/httpd status &>/dev/null
22+
/etc/init.d/httpd status >/dev/null 2>&1
2323
if [ $? -eq 0 ]; then
24-
/etc/init.d/httpd graceful &>/dev/null
24+
/etc/init.d/httpd graceful >/dev/null 2>&1
2525
if [ $? -ne 0 ]; then
26-
log_event "$E_RESTART" "$EVENT"
2726
exit $E_RESTART
2827
fi
2928
else
30-
/etc/init.d/httpd start &>/dev/null
29+
/etc/init.d/httpd start >/dev/null 2>&1
3130
if [ $? -ne 0 ]; then
32-
log_event "$E_RESTART" "$EVENT"
3331
exit $E_RESTART
3432
fi
3533
fi
3634
fi
3735

3836
if [ "$PROXY_SYSTEM" = 'nginx' ]; then
39-
/etc/init.d/nginx status &>/dev/null
37+
/etc/init.d/nginx status >/dev/null 2>&1
4038
if [ $? -eq 0 ]; then
41-
/etc/init.d/nginx reload &>/dev/null
39+
/etc/init.d/nginx reload >/dev/null 2>&1
4240
if [ $? -ne 0 ]; then
43-
log_event "$E_RESTART" "$EVENT"
4441
exit $E_RESTART
4542
fi
4643
else
47-
/etc/init.d/nginx start &>/dev/null
44+
/etc/init.d/nginx start >/dev/null 2>&1
4845
if [ $? -ne 0 ]; then
49-
log_event "$E_RESTART" "$EVENT"
5046
exit $E_RESTART
5147
fi
5248
fi

0 commit comments

Comments
 (0)