function help(){
echo "Function: start\stop zabbix service and dependence, and check status"
echo "Usage: $0 {start|stop|status|help}"
}
function check_service_if_is_running(){
SERVICE=$1
service $SERVICE status >/dev/null 2>&1
REVAL=$?
if [[ $REVAL -eq 0 ]]; then
return 0
else
return 1
fi
}
function start_service_if_is_stoped(){
SERVICE=$1
service $SERVICE start >/dev/null 2>&1
check_service_if_is_running $SERVICE
REVAL=$?
if [[ $REVAL -eq 0 ]]; then
echo $SERVICE is running...
else
echo $SERVICE is not running, error code is $REVAL.
exit 1
fi
}
function stop_service_if_is_running(){
SERVICE=$1
service $SERVICE stop >/dev/null 2>&1
check_service_if_is_running $SERVICE
REVAL=$?
if [[ $REVAL -eq 1 ]]; then
echo $SERVICE is stoped...
fi
}
function status_service(){
SERVICE=$1
check_service_if_is_running $SERVICE
REVAL=$?
if [[ $REVAL -eq 0 ]]; then
echo $SERVICE is running...
else
echo $SERVICE is not running, error code is $REVAL.
exit 1
fi
}
function start(){
start_service_if_is_stoped $REQUIRED_SERVICE_1
start_service_if_is_stoped $REQUIRED_SERVICE_2
start_service_if_is_stoped $REQUIRED_SERVICE_3
}
function stop(){
stop_service_if_is_running $REQUIRED_SERVICE_3
stop_service_if_is_running $REQUIRED_SERVICE_2
stop_service_if_is_running $REQUIRED_SERVICE_1
}
function status(){
status_service $REQUIRED_SERVICE_1
status_service $REQUIRED_SERVICE_2
status_service $REQUIRED_SERVICE_3
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
help
exit 1
;;