Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,30 @@ jobs:
run: |
mvn clean compile -U -Dmaven.javadoc.skip=true -ntp

- name: Run check_port unit tests
if: ${{ env.BACKEND == 'rocksdb' }}
run: |
# Validates ss/netstat//dev/tcp replacement for lsof
$TRAVIS_DIR/test-check-port.sh hugegraph-server/hugegraph-dist/src/assembly/static

- name: Check startup test prerequisites
id: server-preflight
if: ${{ env.BACKEND == 'rocksdb' }}
run: |
for tool in lsof crontab curl java; do
# Note: lsof removed from prerequisites (replaced with ss/netstat//dev/tcp in check_port).
# This job always runs on Linux (ubuntu-22.04), which uses fuser for port cleanup.
for tool in crontab curl java; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "can_run=false" >> "$GITHUB_OUTPUT"
echo "skip_reason=missing tool: $tool" >> "$GITHUB_OUTPUT"
exit 0
fi
done
if ! command -v fuser >/dev/null 2>&1; then
echo "can_run=false" >> "$GITHUB_OUTPUT"
echo "skip_reason=missing tool: fuser (required for Linux port cleanup)" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "can_run=true" >> "$GITHUB_OUTPUT"

- name: Run start-hugegraph.sh foreground mode tests
Expand Down Expand Up @@ -178,6 +191,11 @@ jobs:
run: |
mvn clean compile -pl hugegraph-server/hugegraph-test -am -U -Dmaven.javadoc.skip=true -ntp

- name: Run check_port unit tests
# Validates ss/netstat//dev/tcp replacement for lsof
run: |
$TRAVIS_DIR/test-check-port.sh hugegraph-server/hugegraph-dist/src/assembly/static

- name: Run RocksDB core test
run: |
$TRAVIS_DIR/run-core-test.sh $BACKEND
Expand Down
149 changes: 87 additions & 62 deletions hugegraph-pd/hg-pd-dist/src/assembly/static/bin/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@
# TODO: consider reuse it with server-dist module (almost same as it)
function command_available() {
local cmd=$1
if [ $(command -v $cmd >/dev/null 2>&1) ]; then
return 1
else
if command -v "$cmd" >/dev/null 2>&1; then
return 0
fi
return 1
}

# read a property from .properties file
function read_property() {
# file path
local file_name
local property_name
file_name=$1
# replace "." to "\."
property_name=$(echo $2 | sed 's/\./\\\./g')
cat $file_name | sed -n -e "s/^[ ]*//g;/^#/d;s/^$property_name=//p" | tail -1
property_name=$(echo "$2" | sed 's/\./\\\./g')
cat "$file_name" | sed -n -e "s/^[ ]*//g;/^#/d;s/^$property_name=//p" | tail -1
}

function write_property() {
Expand All @@ -56,7 +57,7 @@ function parse_yaml() {
local version=$2
local module=$3

cat $file | tr -d '\n {}'| awk -F',+|:' '''{
cat "$file" | tr -d '\n {}'| awk -F',+|:' '''{
pre="";
for(i=1; i<=NF; ) {
if(match($i, /version/)) {
Expand All @@ -72,27 +73,19 @@ function parse_yaml() {
}

function process_num() {
num=`ps -ef | grep $1 | grep -v grep | wc -l`
return $num
local num
num=$(ps -ef | grep "$1" | grep -v grep | wc -l)
if (( num > 0 )); then
return 1
fi
return 0
}

function process_id() {
pid=`ps -ef | grep $1 | grep -v grep | awk '{print $2}'`
return $pid
}

# check the port of rest server is occupied
function check_port() {
local port=$(echo "$1" | sed 's|.*:||' | sed 's|/.*||')
if ! command_available "lsof"; then
echo "Required lsof but it is unavailable"
exit 1
fi
lsof -i :$port >/dev/null
if [ $? -eq 0 ]; then
echo "The port $port has already been used"
exit 1
fi
local pid
pid=$(ps -ef | grep "$1" | grep -v grep | awk '{print $2}')
echo "$pid"
return 0
}

function crontab_append() {
Expand Down Expand Up @@ -130,28 +123,29 @@ function wait_for_startup() {
local server_url="$3"
local timeout_s="$4"

local now_s=`date '+%s'`
local stop_s=$(( $now_s + $timeout_s ))
local now_s
now_s=$(date '+%s')
local stop_s=$(( now_s + timeout_s ))

local status

echo -n "Connecting to $server_name ($server_url)"
while [ $now_s -le $stop_s ]; do
while [ "$now_s" -le "$stop_s" ]; do
echo -n .
process_status "$server_name" "$pid" >/dev/null
if [ $? -eq 1 ]; then
echo "Starting $server_name failed"
return 1
fi

status=`curl -o /dev/null -s -k -w %{http_code} $server_url`
if [[ $status -eq 200 || $status -eq 401 ]]; then
status=$(curl -o /dev/null -s -k -w '%{http_code}' "$server_url")
if [[ "$status" -eq 200 || "$status" -eq 401 ]]; then
echo "OK"
echo "Started [pid $pid]"
return 0
fi
sleep 2
now_s=`date '+%s'`
now_s=$(date '+%s')
done

echo "The operation timed out when attempting to connect to $server_url" >&2
Expand All @@ -160,22 +154,28 @@ function wait_for_startup() {

function free_memory() {
local free=""
local os=`uname`
local os=$(uname)
if [ "$os" == "Linux" ]; then
local mem_free=`cat /proc/meminfo | grep -w "MemFree" | awk '{print $2}'`
local mem_buffer=`cat /proc/meminfo | grep -w "Buffers" | awk '{print $2}'`
local mem_cached=`cat /proc/meminfo | grep -w "Cached" | awk '{print $2}'`
local mem_free=$(cat /proc/meminfo | grep -w "MemFree" | awk '{print $2}')
local mem_buffer=$(cat /proc/meminfo | grep -w "Buffers" | awk '{print $2}')
local mem_cached=$(cat /proc/meminfo | grep -w "Cached" | awk '{print $2}')
if [[ "$mem_free" == "" || "$mem_buffer" == "" || "$mem_cached" == "" ]]; then
echo "Failed to get free memory"
exit 1
fi
free=`expr $mem_free + $mem_buffer + $mem_cached`
free=`expr $free / 1024`
free=$(expr "$mem_free" + "$mem_buffer" + "$mem_cached")
free=$(expr "$free" / 1024)
elif [ "$os" == "Darwin" ]; then
local pages_free=`vm_stat | awk '/Pages free/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
local pages_inactive=`vm_stat | awk '/Pages inactive/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " "`
local pages_available=`expr $pages_free + $pages_inactive`
free=`expr $pages_available \* 4096 / 1024 / 1024`
local pages_free pages_inactive
pages_free=$(vm_stat | awk '/Pages free/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " ")
pages_inactive=$(vm_stat | awk '/Pages inactive/{print $0}' | awk -F'[:.]+' '{print $2}' | tr -d " ")
if [[ -z "$pages_free" || -z "$pages_inactive" ]]; then
echo "Failed to get free memory"
exit 1
fi
local pages_available
pages_available=$(expr "$pages_free" + "$pages_inactive")
free=$(expr "$pages_available" \* 4096 / 1024 / 1024)
else
echo "Unsupported operating system $os"
exit 1
Expand All @@ -187,8 +187,8 @@ function calc_xmx() {
local min_mem=$1
local max_mem=$2
# Get machine available memory
local free=`free_memory`
local half_free=$[free/2]
local free=$(free_memory)
local half_free=$((free/2))

local xmx=$min_mem
if [[ "$free" -lt "$min_mem" ]]; then
Expand Down Expand Up @@ -236,47 +236,74 @@ function ensure_path_writable() {
}

function get_ip() {
local os=`uname`
local os=$(uname)
local loopback="127.0.0.1"
local ip=""
case $os in
Linux)
if command_available "ifconfig"; then
ip=`ifconfig | grep 'inet addr:' | grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}'`
ip=$(ifconfig | grep 'inet addr:' | grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}')
elif command_available "ip"; then
ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}'`
ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}')
else
ip=$loopback
fi
;;
FreeBSD|OpenBSD|Darwin)
if command_available "ifconfig"; then
ip=`ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}'`
ip=$(ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}')
else
ip=$loopback
fi
;;
SunOS)
if command_available "ifconfig"; then
ip=`ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} '`
ip=$(ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} ')
else
ip=$loopback
fi
;;
*) ip=$loopback;;
esac
echo $ip
[[ -z "$ip" ]] && ip=$loopback
echo "$ip"
}

function download() {
local path=$1
local link_url=$2

if command_available "wget"; then
wget --help | grep -q '\--show-progress' && progress_opt="-q --show-progress" || progress_opt=""
wget ${link_url} -P ${path} $progress_opt
elif command_available "curl"; then
curl ${link_url} -o ${path}/${link_url}
if [ ! -d "$path" ]; then
mkdir -p "$path" || {
echo "Failed to create directory: $path"
exit 1
}
fi

local filename
filename=$(basename "${link_url%%[?#]*}")
local tmp="${path}/.${filename}.tmp.$$"
local dest="${path}/${filename}"

if command_available "curl"; then
# -o must appear before -- so it is parsed as an option, not an extra URL.
if curl -fL -o "$tmp" -- "${link_url}"; then
mv -f -- "$tmp" "$dest"
else
rm -f -- "$tmp"
return 1
fi
elif command_available "wget"; then
local -a progress_opt=()
if wget --help 2>&1 | grep -q -- '--show-progress'; then
progress_opt=(-q --show-progress)
fi
if wget ${progress_opt[@]+"${progress_opt[@]}"} -O "$tmp" -- "${link_url}"; then
mv -f -- "$tmp" "$dest"
else
rm -f -- "$tmp"
return 1
fi
else
echo "Required wget or curl but they are unavailable"
exit 1
Expand All @@ -289,19 +316,17 @@ function ensure_package_exist() {
local tar=$3
local link=$4

if [ ! -d ${path}/${dir} ]; then
if [ ! -f ${path}/${tar} ]; then
if [ ! -d "${path}/${dir}" ]; then
if [ ! -f "${path}/${tar}" ]; then
echo "Downloading the compressed package '${tar}'"
download ${path} ${link}
if [ $? -ne 0 ]; then
if ! download "${path}" "${link}"; then
echo "Failed to download, please ensure the network is available and link is valid"
exit 1
fi
echo "[OK] Finished download"
fi
echo "Unzip the compressed package '$tar'"
tar -zxvf ${path}/${tar} -C ${path} >/dev/null 2>&1
if [ $? -ne 0 ]; then
if ! tar -zxvf "${path}/${tar}" -C "${path}" >/dev/null 2>&1; then
echo "Failed to unzip, please check the compressed package"
exit 1
fi
Expand All @@ -316,7 +341,7 @@ function wait_for_shutdown() {
local pid="$2"
local timeout_s="$3"

local now_s=`date '+%s'`
local now_s=$(date '+%s')
local stop_s=$(( $now_s + $timeout_s ))

echo -n "Killing $process_name(pid $pid)" >&2
Expand All @@ -328,7 +353,7 @@ function wait_for_shutdown() {
return 0
fi
sleep 2
now_s=`date '+%s'`
now_s=$(date '+%s')
done
echo "$process_name shutdown timeout(exceeded $timeout_s seconds)" >&2
return 1
Expand Down Expand Up @@ -357,7 +382,7 @@ function kill_process() {
return 0
fi

case "`uname`" in
case "$(uname)" in
CYGWIN*) taskkill /F /PID "$pid" ;;
*) kill "$pid" ;;
esac
Expand Down
Loading
Loading