|
|
|
@ -382,81 +382,76 @@ openim::util::check_ports() {
|
|
|
|
|
# User:
|
|
|
|
|
# openim::util::check_process_names nginx mysql redis
|
|
|
|
|
# The function returns a status of 1 if any of the processes is not running.
|
|
|
|
|
|
|
|
|
|
openim::util::check_process_names() {
|
|
|
|
|
# Function to get the port of a process
|
|
|
|
|
get_port() {
|
|
|
|
|
local pid=$1
|
|
|
|
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
|
|
|
# Linux
|
|
|
|
|
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
|
|
|
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
|
# macOS
|
|
|
|
|
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
|
|
|
|
else
|
|
|
|
|
echo "Unsupported OS"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
case "$OSTYPE" in
|
|
|
|
|
"linux-gnu"*)
|
|
|
|
|
# Linux
|
|
|
|
|
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
|
|
|
|
;;
|
|
|
|
|
"darwin"*)
|
|
|
|
|
# macOS
|
|
|
|
|
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Unsupported OS"
|
|
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Arrays to collect details of processes
|
|
|
|
|
|
|
|
|
|
# Arrays to collect process details
|
|
|
|
|
local not_started=()
|
|
|
|
|
local started=()
|
|
|
|
|
|
|
|
|
|
# Iterate over each given process name
|
|
|
|
|
# Iterate over each given process name
|
|
|
|
|
for process_name in "$@"; do
|
|
|
|
|
# Use `pgrep` to find process IDs related to the given process name
|
|
|
|
|
local pids=($(pgrep -f $process_name))
|
|
|
|
|
|
|
|
|
|
# Check if any process IDs were found
|
|
|
|
|
if [[ ${#pids[@]} -eq 0 ]]; then
|
|
|
|
|
not_started+=($process_name)
|
|
|
|
|
else
|
|
|
|
|
# If there are PIDs, loop through each one
|
|
|
|
|
for pid in "${pids[@]}"; do
|
|
|
|
|
local command=$(ps -p $pid -o cmd=)
|
|
|
|
|
local start_time=$(ps -p $pid -o lstart=)
|
|
|
|
|
local port=$(get_port $pid)
|
|
|
|
|
|
|
|
|
|
# Check if port information was found for the PID
|
|
|
|
|
if [[ -z $port ]]; then
|
|
|
|
|
port="N/A"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
local pids=($(pgrep -f "$process_name"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print information
|
|
|
|
|
if [[ ${#pids[@]} -eq 0 ]]; then
|
|
|
|
|
not_started+=("$process_name")
|
|
|
|
|
else
|
|
|
|
|
for pid in "${pids[@]}"; do
|
|
|
|
|
local command=$(ps -p $pid -o cmd=)
|
|
|
|
|
local start_time=$(ps -p $pid -o lstart=)
|
|
|
|
|
local port=$(get_port $pid)
|
|
|
|
|
port=${port:-N/A}
|
|
|
|
|
|
|
|
|
|
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Print not started processes
|
|
|
|
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
|
|
|
echo "Not started processes:"
|
|
|
|
|
for process_name in "${not_started[@]}"; do
|
|
|
|
|
echo "Process $process_name is not started."
|
|
|
|
|
echo " - Process $process_name is not started."
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print started processes
|
|
|
|
|
if [[ ${#started[@]} -ne 0 ]]; then
|
|
|
|
|
echo
|
|
|
|
|
echo "Started processes:"
|
|
|
|
|
echo -e "\nStarted processes:"
|
|
|
|
|
for info in "${started[@]}"; do
|
|
|
|
|
echo "$info"
|
|
|
|
|
echo " - $info"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Return status
|
|
|
|
|
|
|
|
|
|
# Return status based on whether any processes have not started
|
|
|
|
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
|
|
|
openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}"
|
|
|
|
|
openim::color::echo $COLOR_RED "OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
|
|
|
|
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
|
|
|
|
echo -e "\nSome processes have not started. Please check the logs for more information."
|
|
|
|
|
return 1
|
|
|
|
|
else
|
|
|
|
|
echo ""
|
|
|
|
|
openim::log::success "All processes are running."
|
|
|
|
|
echo -e "\nAll processes are running."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
openim::util::check_process_names_for_stop() {
|
|
|
|
|
# Function to get the port of a process
|
|
|
|
|
get_port() {
|
|
|
|
|