Browse Source

Added service exists or not check

old-stable
gau1991 11 years ago
parent
commit
33c8a84fb0
  1. 59
      src/lib/ee_lib_service.sh

59
src/lib/ee_lib_service.sh

@ -7,36 +7,39 @@
function ee_lib_service() function ee_lib_service()
{ {
for ee_service_name in ${@:1:$(($#-1))}; do for ee_service_name in ${@:1:$(($#-1))}; do
# Display message dpkg --get-selections | grep -v deinstall | grep $ee_service_name &>> $EE_COMMAND_LOG
ee_lib_echo "Executing service $ee_service_name ${@: -1}, please wait..." if [ $? -eq 0 ];then
# Display message
ee_lib_echo "Executing service $ee_service_name ${@: -1}, please wait..."
# Check nginx and php5-fpm test before start/stop/restart/reload # Check nginx and php5-fpm test before start/stop/restart/reload
if [ $ee_service_name = "nginx" ]; then if [ $ee_service_name = "nginx" ]; then
# Adjust nginx server_names_hash_bucket_size # Adjust nginx server_names_hash_bucket_size
$ee_service_name -t 2>&1 | grep server_names_hash_bucket_size &>> $EE_COMMAND_LOG $ee_service_name -t 2>&1 | grep server_names_hash_bucket_size &>> $EE_COMMAND_LOG
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
EE_NGINX_CALCULATION=$(echo "l($(ls /etc/nginx/sites-enabled/ | wc -c))/l(2)+2" | bc -l) EE_NGINX_CALCULATION=$(echo "l($(ls /etc/nginx/sites-enabled/ | wc -c))/l(2)+2" | bc -l)
EE_NGINX_SET_BUCKET=$(echo "2^$EE_NGINX_CALCULATION" | bc -l 2> /dev/null) EE_NGINX_SET_BUCKET=$(echo "2^$EE_NGINX_CALCULATION" | bc -l 2> /dev/null)
sed -i "s/.*server_names_hash_bucket_size.*/\tserver_names_hash_bucket_size $EE_NGINX_SET_BUCKET;/" /etc/nginx/nginx.conf sed -i "s/.*server_names_hash_bucket_size.*/\tserver_names_hash_bucket_size $EE_NGINX_SET_BUCKET;/" /etc/nginx/nginx.conf
fi
# Test and start/stop/restart/reload nginx service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "php5-fpm" ]; then
# Test and start/stop/restart/reload php5-fpm service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "dovecot" ]; then
# Test and start/stop/restart/reload Dovecot service
$ee_service_name -n &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
else
# start/stop/restart/reload services
service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
fi fi
# Test and start/stop/restart/reload nginx service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "php5-fpm" ]; then
# Test and start/stop/restart/reload php5-fpm service
$ee_service_name -t &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
elif [ $ee_service_name = "dovecot" ]; then
# Test and start/stop/restart/reload Dovecot service
$ee_service_name -n &>> $EE_COMMAND_LOG \
&& service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG\
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
else
# start/stop/restart/reload services
service $ee_service_name ${@: -1} &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to execute service $ee_service_name ${@: -1}, exit status = " $?
fi fi
done done
} }

Loading…
Cancel
Save