Skip to content

Commit

Permalink
Merge pull request #2041 from skiffer-git/fix-bug-2039-3.6
Browse files Browse the repository at this point in the history
Error not handled
  • Loading branch information
withchao committed Mar 8, 2024
2 parents a534134 + ed45f6f commit fc94eed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 74 deletions.
2 changes: 2 additions & 0 deletions scripts/install/openim-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ function openim::tools::start_service() {
fi
openim::log::status "Starting binary ${binary_name}..."


${cmd}


local status=$?

if [ $status -eq 0 ]; then
Expand Down
61 changes: 0 additions & 61 deletions scripts/lib/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1808,68 +1808,7 @@ openim::util::stop_services_on_ports() {
# Usage:
# openim::util::stop_services_with_name nginx apache
# The function returns a status of 1 if any service couldn't be stopped.
openim::util::stop_services_with_name() {
# An array to collect names of processes that couldn't be stopped.
local not_stopped=()

# An array to collect information about processes that were stopped.
local stopped=()

echo "Stopping services with names: $*"
# Iterate over each given service name.
for server_name in "$@"; do
# Use the `pgrep` command to find process IDs related to the given service name.
local pids=$(pgrep -f "$server_name")

# If no process was found with the name, add it to the not_stopped list
if [[ -z $pids ]]; then
not_stopped+=("$server_name")
continue
fi
local stopped_this_time=false
for pid in $pids; do

# Exclude the PID of the current script
if [[ "$pid" == "$$" ]]; then
continue
fi

# If there's a Process ID, it means the service with the name is running.
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -10 $pid 2>/dev/null; then
stopped_this_time=true
fi
fi
done

if $stopped_this_time; then
stopped+=("$server_name")
else
not_stopped+=("$server_name")
fi
done

# Print information about services whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
echo "Services that couldn't be stopped:"
for name in "${not_stopped[@]}"; do
openim::log::status "Failed to stop the $name service."
done
fi

# Print information about services whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
echo "Stopped services:"
for name in "${stopped[@]}"; do
echo "Successfully stopped the $name service."
done
fi

openim::log::success "All specified services were stopped."
echo ""
}
# sleep 333333&
# sleep 444444&
# ps -ef | grep "sleep"
Expand Down
33 changes: 20 additions & 13 deletions tools/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,26 @@ func main() {
if !check.flag {
err = check.function(check.config)
if err != nil {
if errors.Is(err, errMinioNotEnabled) {
fmt.Println(err.Error())
checks[index].flag = true
}
if errors.Is(err, errSignEndPoint) {
fmt.Fprintf(os.Stderr, err.Error())
checks[index].flag = true

if check.name == "Minio" {
if errors.Is(err, errMinioNotEnabled) {
fmt.Println(err.Error(), " check ", check.name)
checks[index].flag = true
}
if errors.Is(err, errSignEndPoint) {
fmt.Fprintf(os.Stderr, err.Error(), " check ", check.name)
checks[index].flag = true
}
}


component.ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, errs.Unwrap(err).Error()))
if !strings.Contains(errs.Unwrap(err).Error(), "connection refused") &&
!strings.Contains(errs.Unwrap(err).Error(), "timeout waiting") {
component.ErrorPrint("Some components started failed!")
os.Exit(-1)
if strings.Contains(errs.Unwrap(err).Error(), "connection refused") ||
strings.Contains(errs.Unwrap(err).Error(), "timeout") ||
strings.Contains(errs.Unwrap(err).Error(), "context deadline exceeded") {
component.ErrorPrint(fmt.Sprintf("try check connection %s", check.name))
allSuccess = false
break
}
} else {
checks[index].flag = true
Expand Down Expand Up @@ -258,13 +265,13 @@ func checkKafka(config *config.GlobalConfig) error {
_, err = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{
KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
}, []string{config.Kafka.MsgToPush.Topic},
}, []string{config.Kafka.MsgToMongo.Topic},
config.Kafka.Addr, config.Kafka.ConsumerGroupID.MsgToMongo, tlsConfig)
if err != nil {
return err
}

kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{
_, err = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{
KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false,
}, []string{config.Kafka.MsgToPush.Topic}, config.Kafka.Addr,
Expand Down

0 comments on commit fc94eed

Please sign in to comment.