combine ce rpm
This commit is contained in:
parent
d84a8b3e65
commit
21acb7b3ec
2
build.sh
2
build.sh
@ -146,7 +146,7 @@ function do_clean
|
||||
|
||||
function build_package
|
||||
{
|
||||
STATIC_LINK_LGPL_DEPS_OPTION=OFF
|
||||
STATIC_LINK_LGPL_DEPS_OPTION=ON
|
||||
ENABLE_BOLT_OPTION=OFF
|
||||
do_build "$@" -DOB_BUILD_PACKAGE=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOB_USE_LLD=$LLD_OPTION -DENABLE_FATAL_ERROR_HANG=OFF -DENABLE_AUTO_FDO=ON -DENABLE_THIN_LTO=ON -DENABLE_HOTFUNC=ON -DENABLE_BOLT=$ENABLE_BOLT_OPTION -DOB_STATIC_LINK_LGPL_DEPS=$STATIC_LINK_LGPL_DEPS_OPTION
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ set(CPACK_DEBIAN_PACKAGE_PRIORITY "Optional")
|
||||
# systemd define on deb
|
||||
if (OB_BUILD_OPENSOURCE)
|
||||
set(CPACK_DEBIAN_SERVER_PACKAGE_DEPENDS "oceanbase-ce-libs (= ${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE})")
|
||||
set(CPACK_DEBIAN_SERVER_PACKAGE_DEPENDS "${CPACK_DEBIAN_SERVER_PACKAGE_DEPENDS}, jq, systemd")
|
||||
set(CPACK_DEBIAN_SERVER_PACKAGE_DEPENDS "${CPACK_DEBIAN_SERVER_PACKAGE_DEPENDS}, systemd")
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/systemd/profile/pre_install.sh.template
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/systemd/profile/preinst
|
||||
|
@ -81,6 +81,7 @@ install(FILES
|
||||
tools/systemd/profile/oceanbase-pre.json
|
||||
tools/systemd/profile/oceanbase.service
|
||||
tools/systemd/profile/oceanbase-service.sh
|
||||
tools/systemd/profile/telemetry-pre.json
|
||||
tools/systemd/profile/telemetry.sh
|
||||
DESTINATION profile
|
||||
COMPONENT server)
|
||||
@ -359,8 +360,6 @@ if(OB_BUILD_OPENSOURCE)
|
||||
deps/3rd/usr/local/oceanbase/deps/devel/lib/libaio.so.1
|
||||
deps/3rd/usr/local/oceanbase/deps/devel/lib/libaio.so.1.0.1
|
||||
deps/3rd/usr/local/oceanbase/deps/devel/lib/libaio.so
|
||||
deps/3rd/usr/local/oceanbase/deps/devel/lib/mariadb/libmariadb.so
|
||||
deps/3rd/usr/local/oceanbase/deps/devel/lib/mariadb/libmariadb.so.3
|
||||
DESTINATION lib
|
||||
COMPONENT libs
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ set(CPACK_RPM_SPEC_MORE_DEFINE
|
||||
|
||||
# systemd define on rpm
|
||||
if (OB_BUILD_OPENSOURCE)
|
||||
set(CPACK_RPM_SERVER_PACKAGE_REQUIRES "oceanbase-ce-libs = ${CPACK_PACKAGE_VERSION}, jq, systemd")
|
||||
set(CPACK_RPM_SERVER_PACKAGE_REQUIRES "oceanbase-ce-libs = ${CPACK_PACKAGE_VERSION}, systemd")
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tools/systemd/profile/pre_install.sh.template
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/systemd/profile/pre_install.sh
|
||||
|
@ -10,14 +10,48 @@ unix_socket="$prefix/run/obshell.sock"
|
||||
obshell="$prefix/bin/obshell"
|
||||
etc_folder="$prefix/etc"
|
||||
current_user=`whoami`
|
||||
json_pre_file="$prefix/profile/oceanbase-pre.json"
|
||||
json_file="$prefix/profile/oceanbase.json"
|
||||
report=3
|
||||
|
||||
function get_json_body_by_key {
|
||||
local key=$1
|
||||
|
||||
json=$(cat "$json_file" | tr -d '[:space:]')
|
||||
|
||||
start_index=$(echo "$json" | awk -v a="$key" '{print index($0, a)}')
|
||||
if [ $start_index -eq 0 ]; then
|
||||
echo "'$key' not found in json string."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
length=${#key}
|
||||
substring="${json:start_index+$length+1}"
|
||||
result=""
|
||||
brace_count=0
|
||||
brace_flag=0
|
||||
|
||||
for (( i=0; i<${#substring}; i++ )); do
|
||||
char="${substring:i:1}"
|
||||
if [[ $char == "{" ]]; then
|
||||
brace_count=$((brace_count + 1))
|
||||
elif [[ $char == "}" ]]; then
|
||||
brace_count=$((brace_count - 1))
|
||||
fi
|
||||
result="$result$char"
|
||||
if [[ $brace_count -eq 0 ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
function prepare_config_json {
|
||||
json_pre_file="$prefix/profile/oceanbase-pre.json"
|
||||
json_file="$prefix/profile/oceanbase.json"
|
||||
rm -rf $json_file
|
||||
cp $json_pre_file $json_file
|
||||
local temp_file=$(mktemp)
|
||||
first_observer_configration=true
|
||||
|
||||
while IFS='=' read -r key value; do
|
||||
# delete empty and comment line
|
||||
@ -34,10 +68,17 @@ function prepare_config_json {
|
||||
port=$value
|
||||
elif [[ $key == *"root_pwd"* ]]; then
|
||||
key="rootPwd"
|
||||
jq --arg parent "oceanbase_ce" --arg child "cluster" --arg key "$key" --arg value "$value" '.[$parent][$child][$key] = $value' "$json_file" > "$temp_file"
|
||||
cluster_config_line=$(grep -n "cluster" $json_file | head -n 1 | cut -d: -f1)
|
||||
sed "$((cluster_config_line+1))i\\ \"$key\": \"$value\"," "$json_file" > "$temp_file"
|
||||
mv "$temp_file" "$json_file"
|
||||
else
|
||||
jq --arg parent "oceanbase_ce" --arg child "server" --arg grandchild "observerConfig" --arg key "$key" --arg value "$value" '.[$parent][$child][$grandchild][$key] = $value' "$json_file" > "$temp_file"
|
||||
if $first_observer_configration; then
|
||||
first_observer_configration=false
|
||||
sed "s/\"observerConfig\": {}/\"observerConfig\": {\n \"$key\": \"$value\"\n }/" "$json_file" > "$temp_file"
|
||||
else
|
||||
observer_config_line=$(grep -n "observerConfig" $json_file | head -n 1 | cut -d: -f1)
|
||||
sed "$((observer_config_line+1))i\\ \"$key\": \"$value\"," "$json_file" > "$temp_file"
|
||||
fi
|
||||
mv "$temp_file" "$json_file"
|
||||
fi
|
||||
fi
|
||||
@ -92,7 +133,7 @@ function check_obagent_process {
|
||||
|
||||
function check_response {
|
||||
local response=$1
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
@ -108,7 +149,7 @@ function check_trace {
|
||||
echo "the $content trace id is $dag_trace"
|
||||
while true; do
|
||||
response=$(curl --silent -XGET --unix-socket $unix_socket $url/api/v1/task/dag/$dag_trace)
|
||||
state=$(echo "$response" | jq -r '.data.state')
|
||||
state=$(echo "$response" | grep -o '"state":[^,]*' | head -1 | sed 's/"state"://' | tr -d '"')
|
||||
echo "the response state is $state"
|
||||
if [ "x$state" = "xSUCCEED" ]; then
|
||||
echo "$content request successfully"
|
||||
@ -138,49 +179,49 @@ function start_obshell {
|
||||
|
||||
function do_config_observer {
|
||||
# join agent
|
||||
obagent_configuration=`jq '.obshell' $json_file`
|
||||
obagent_configuration=$(get_json_body_by_key "obshell")
|
||||
obagent_cmd="curl --silent -H \"Content-Type: application/json\" -X POST -d '${obagent_configuration}' --unix-socket $unix_socket $url/api/v1/agent/join"
|
||||
response=$(eval "$obagent_cmd")
|
||||
echo $response
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "join agent" 3 3
|
||||
|
||||
# config cluster
|
||||
cluster_configuration=`jq '.oceanbase_ce.cluster' $json_file`
|
||||
cluster_configuration=$(get_json_body_by_key "cluster")
|
||||
cluster_cmd="curl --silent -H \"Content-Type: application/json\" -X PUT -d '${cluster_configuration}' --unix-socket $unix_socket $url/api/v1/obcluster/config"
|
||||
response=$(eval "$cluster_cmd")
|
||||
echo $response
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "config cluster" 3 3
|
||||
|
||||
# config observer
|
||||
observer_configuration=`jq '.oceanbase_ce.server' $json_file`
|
||||
observer_configuration=$(get_json_body_by_key "server")
|
||||
observer_cmd="curl --silent -H \"Content-Type: application/json\" -X PUT -d '${observer_configuration}' --unix-socket $unix_socket $url/api/v1/observer/config"
|
||||
response=$(eval "$observer_cmd")
|
||||
echo $response
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "config observer" 3 3
|
||||
}
|
||||
|
||||
function do_start_observer {
|
||||
# check observer status
|
||||
response=$(curl --silent -H "Content-Type: application/json" -X GET --unix-socket $unix_socket $url/api/v1/status)
|
||||
identity=$(echo "$response" | jq -r '.data.agent.identity')
|
||||
identity=$(echo "$response" | grep -o '"identity":[^,]*' | sed 's/"identity"://' | tr -d '"' | tr -d '}')
|
||||
if [ "x$identity" = "xCLUSTER AGENT" ]; then
|
||||
echo "The observer is already bootstrap, please start it immediately"
|
||||
response=$(curl --silent -H "Content-Type: application/json" -X POST -d '{
|
||||
@ -191,12 +232,12 @@ function do_start_observer {
|
||||
},
|
||||
"force": true
|
||||
}' --unix-socket $unix_socket $url/api/v1/ob/start)
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "start observer" 20 6
|
||||
if [ $? -eq 0 ]; then
|
||||
/bin/bash $prefix/profile/telemetry.sh $report "12" >/dev/null 2>&1
|
||||
@ -206,12 +247,12 @@ function do_start_observer {
|
||||
do_config_observer
|
||||
echo "The observer has not bootstrap, please init it firstly"
|
||||
response=$(curl --silent -X POST --unix-socket $unix_socket $url/api/v1/ob/init)
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "start observer" 40 6
|
||||
if [ $? -eq 0 ]; then
|
||||
/bin/bash $prefix/profile/telemetry.sh $report "11" >/dev/null 2>&1
|
||||
@ -230,7 +271,7 @@ function do_start_observer {
|
||||
|
||||
# check observer state
|
||||
response=$(curl --silent -H "Content-Type: application/json" -X GET --unix-socket $unix_socket $url/api/v1/status)
|
||||
ob_state=$(echo "$response" | jq -r '.data.obState')
|
||||
ob_state=$(echo "$response" | grep -o '"obState":[^,]*' | sed 's/"obState"://')
|
||||
if [ "x$ob_state" = "x1" ]; then
|
||||
echo "The agent dose not know the observer password"
|
||||
echo "1. Please set environment: export OB_ROOT_PASSWORD={root_passowrd}"
|
||||
@ -265,12 +306,12 @@ function stop_observer {
|
||||
},
|
||||
"force": true
|
||||
}' --unix-socket $unix_socket $url/api/v1/ob/stop)
|
||||
successful=$(echo "$response" | jq -r '.successful')
|
||||
successful=$(echo "$response" | grep -o '"successful":[^,]*' | sed 's/"successful"://')
|
||||
if [ "x$successful" = "xfalse" ]; then
|
||||
echo "send request failed"
|
||||
exit 1
|
||||
fi
|
||||
trace=$(echo "$response" | jq -r '.data.id')
|
||||
trace=$(echo "$response" | grep -o '"id":[^,]*' | sed 's/"id"://' | tr -d '"')
|
||||
check_trace $trace "stop observer" 20 6
|
||||
}
|
||||
|
||||
@ -297,6 +338,10 @@ elif [ "x$1" = "xdestroy" ]; then
|
||||
echo "stop obshell failed"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "x$1" = "xtest" ]; then
|
||||
echo "test at ${DATE}"
|
||||
result=$(get_json_body_by_key "obshell:")
|
||||
echo $result
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
14
tools/systemd/profile/telemetry-pre.json
Normal file
14
tools/systemd/profile/telemetry-pre.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"component": "ocs",
|
||||
"content": {
|
||||
"reporter": "#reporter#",
|
||||
"type": "#type#",
|
||||
"step": "#step#",
|
||||
"version": "#version#",
|
||||
"release": "#release#",
|
||||
"hostHash": "#hostHash#",
|
||||
"osName": "#osName#",
|
||||
"osRelease": "#osRelease#",
|
||||
"observerConfig": {}
|
||||
}
|
||||
}
|
@ -4,48 +4,57 @@ url="https://openwebapi.oceanbase.com/api/web/oceanbase/report"
|
||||
type=@CPACK_PACKAGE_NAME@
|
||||
version=@CPACK_PACKAGE_VERSION@
|
||||
release=@CPACK_RPM_PACKAGE_RELEASE@
|
||||
prefix=@CPACK_PACKAGING_INSTALL_PREFIX@
|
||||
ip=$(hostname -I | awk '/^[0-9]/ {print $1; exit}')
|
||||
hostHash=$(echo -n "$ip" | sha1sum | awk '{print $1}')
|
||||
osName=$(cat /etc/os-release | grep "^ID=" | cut -f2 -d=)
|
||||
osRelease=$(cat /etc/os-release | grep "^VERSION_ID=" | cut -f2 -d=)
|
||||
osName=$(cat /etc/os-release | grep "^ID=" | cut -f2 -d= | tr -d '"')
|
||||
osRelease=$(cat /etc/os-release | grep "^VERSION_ID=" | cut -f2 -d= | tr -d '"')
|
||||
cnf_file='/etc/oceanbase.cnf'
|
||||
json_pre_file="$prefix/profile/telemetry-pre.json"
|
||||
json_file="$prefix/profile/telemetry.json"
|
||||
|
||||
step='none'
|
||||
reporter='none'
|
||||
|
||||
jsonData=$(jq -n --arg reporter "$reporter" \
|
||||
--arg type "$type" \
|
||||
--arg step "$step" \
|
||||
--arg version "$version" \
|
||||
--arg release "$revision" \
|
||||
--arg hostHash "$hostHash" \
|
||||
--arg osName "$osName" \
|
||||
--arg osRelease "$osRelease" '{
|
||||
component: "ocs",
|
||||
content: {
|
||||
reporter: $reporter,
|
||||
type: $type,
|
||||
step: $step,
|
||||
version: $version,
|
||||
release: $release,
|
||||
hostHash: $hostHash,
|
||||
osName: $osName,
|
||||
osRelease: $osRelease,
|
||||
observerConfig: {}
|
||||
}
|
||||
}')
|
||||
|
||||
function add_observer_config {
|
||||
rm -rf $json_file
|
||||
cp $json_pre_file $json_file
|
||||
local temp_file=$(mktemp)
|
||||
first_observer_configration=true
|
||||
|
||||
while IFS='=' read -r key value; do
|
||||
# delete empty and comment line
|
||||
if [[ ! $key || $key =~ ^[[:space:]]*# ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
key=$(echo "$key" | awk '{$1=$1};1')
|
||||
value=$(echo "$value" | awk '{$1=$1};1')
|
||||
value=$(echo "$value" | sed 's/^"//' | sed 's/"$//')
|
||||
if [[ -n "$key" && ! "$key" =~ ^\; && $key != *"rootPwd"* ]]; then
|
||||
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg child "observerConfig" --arg key "$key" --arg value "$value" '.[$parent][$child][$key] = $value')
|
||||
if $first_observer_configration; then
|
||||
first_observer_configration=false
|
||||
sed "s/\"observerConfig\": {}/\"observerConfig\": {\n \"$key\": \"$value\"\n }/" "$json_file" > "$temp_file"
|
||||
else
|
||||
observer_config_line=$(grep -n "observerConfig" $json_file | head -n 1 | cut -d: -f1)
|
||||
sed "$((observer_config_line+1))i\\ \"$key\": \"$value\"," "$json_file" > "$temp_file"
|
||||
fi
|
||||
mv "$temp_file" "$json_file"
|
||||
fi
|
||||
done < "$cnf_file"
|
||||
}
|
||||
|
||||
function update_json {
|
||||
sed -i "s|#reporter#|${reporter}|g" $json_file
|
||||
sed -i "s|#type#|${type}|g" $json_file
|
||||
sed -i "s|#step#|${step}|g" $json_file
|
||||
sed -i "s|#version#|${version}|g" $json_file
|
||||
sed -i "s|#release#|${release}|g" $json_file
|
||||
sed -i "s|#hostHash#|${hostHash}|g" $json_file
|
||||
sed -i "s|#osName#|${osName}|g" $json_file
|
||||
sed -i "s|#osRelease#|${osRelease}|g" $json_file
|
||||
}
|
||||
|
||||
# Function Name: do_telemetry
|
||||
# Purpose: prepare the telemetry json data
|
||||
# Arguments: arg1 - 0 means rpm uninstall, 1 means rpm install, 2 means rpm upgrade, 3 means systemd deploy
|
||||
@ -73,12 +82,11 @@ function do_telemetry {
|
||||
reporter="systemd"
|
||||
add_observer_config
|
||||
fi
|
||||
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg key "reporter" --arg value "$reporter" '.[$parent][$key] = $value')
|
||||
jsonData=$(echo "$jsonData" | jq --arg parent "content" --arg key "step" --arg value "$step" '.[$parent][$key] = $value')
|
||||
update_json
|
||||
|
||||
nohup curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$jsonData" "$url" >/dev/null 2>&1 &
|
||||
-d @"$json_file" "$url" >/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
if [[ -z "$TELEMETRY_MODE" ]] || ( [[ "$TELEMETRY_MODE" =~ ^-?[0-9]+$ ]] && [[ "$TELEMETRY_MODE" -eq 1 ]] ); then
|
||||
|
Loading…
x
Reference in New Issue
Block a user