Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(dist): avoid script exit while restarting & clean script #2041

Merged
merged 4 commits into from
Dec 1, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ public final class ApiVersion {

/**
* The second parameter of Version.of() is for IDE running without JAR
* TODO: what shall we set for this version? (consider the basic compatibility)
*/
public static final Version VERSION = Version.of(ApiVersion.class, "0.69");

public static void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
// TODO: what shall we set for this version? (consider the basic compatibility)
VersionUtil.check(CoreVersion.VERSION, "1.0", "1.1", CoreVersion.NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class CoreVersion {

public static void check() {
// Check version of hugegraph-common
// TODO: why shall we check it? Update it if need
VersionUtil.check(CommonVersion.VERSION, "1.0", "1.1", CommonVersion.NAME);
}
}
69 changes: 21 additions & 48 deletions hugegraph-dist/src/assembly/static/bin/hugegraph
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,26 @@
# limitations under the License.
#

#
# hugegraph This shell script takes care of starting and stopping
# HugeGraphServer.
#
# chkconfig: - 58 74
# description: HugeGraphServer is graph database server. It provides graph \
# service by RESTful API consisted with graph, schema, gremlin and other APIs.

### BEGIN INIT INFO
# Provides: HugeGraphServer
# Required-Start: $java
# Required-Stop: $java
# Should-Start: -
# Should-Stop: -
# Short-Description: start and stop HugeGraphServer
# Description: HugeGraphServer is graph database server. It provides graph
# service by RESTful API consisted with graph, schema, gremlin
# and other APIs.
### END INIT INFO
# This script is used for starting and stopping HugeGraphServer easily.
# We could copy this file under '/usr/bin' to use it globally

# Variables
# it requires user to set a fixed abs path manually
# Note: user must set a absolute path below
INSTALL_DIR=
SERVER_PORT=

${INSTALL_DIR:?"Please set variables 'INSTALL_DIR'"}
${SERVER_PORT:?"Please set variables 'SERVER_PORT'"}
${INSTALL_DIR:?"Please open the script then set variable 'INSTALL_DIR' manually"}
${SERVER_PORT:?"Please open the script then set variable 'SERVER_PORT' manually"}

BIN_DIR=$INSTALL_DIR/bin
SERVER_URL="http://localhost:${SERVER_PORT}"
DETECT_URL="$SERVER_URL/versions"
EXIT=1

# Start the HugeGraphServer
start() {
echo "Starting HugeGraphServer..."
# Verify if the service is running
get_status
if [ $? -eq 0 ]; then
echo "The service is already running"
if get_status; then
echo "The graph server is already running"
exit 0
else
# Run the service
Expand All @@ -64,50 +45,41 @@ start() {
#sleep 10

# Verify if the service is running
get_status
if [ $? -eq 0 ]; then
echo "Service was successfully started"
if get_status; then
echo "Graph server was successfully started"
exit 0
else
echo "Failed to start service"
echo "Failed to start graph server"
exit 1
fi
fi
}

# Stop the MATH
stop() {
echo "Stopping HugeGraphServer..."
# Verify if the service is running
get_status
if [ $? -eq 0 ]; then
if get_status; then
# Stop the service
$BIN_DIR/stop-hugegraph.sh

# Sleep time before the service verification
#sleep 10

# Verify if the service is running
get_status
if [ $? -eq 0 ]; then
if get_status; then
echo "Failed to stop service"
exit 1
else
echo "Service was successfully stopped"
exit 0
fi
else
echo "The service is already stopped"
fi

if [[ $EXIT -eq 1 ]]; then
exit 0
fi
}

# Verify the status of HugeGraphServer
status() {
echo "Checking status of HugeGraphServer..."
# Verify if the HugeGraphServer is running
get_status
if [ $? -eq 0 ]; then
if get_status; then
echo "Service is running"
exit 0
else
Expand All @@ -119,7 +91,7 @@ status() {
# Get status of HugeGraphServer to ensure it is alive
get_status() {
HTTP_CODE=$(curl -I -s -w "%{http_code}" -o /dev/null $DETECT_URL)
if [ $HTTP_CODE = 200 ]; then
if [ "$HTTP_CODE" = 200 ]; then
return 0
else
return 1
Expand All @@ -137,12 +109,13 @@ case "$1" in
status)
status
;;
restart|reload)
restart|reload|rs)
EXIT=0
stop
start
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload}"
echo $"Usage: $0 {start, stop, status, restart|reload|rs}"
exit 1
esac
exit 0
14 changes: 6 additions & 8 deletions hugegraph-dist/src/assembly/static/bin/stop-hugegraph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,30 @@ abs_path() {
echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
}

BIN=`abs_path`
BIN=$(abs_path)
TOP="$(cd $BIN/../ && pwd)"

. $BIN/util.sh
. "$BIN"/util.sh

PID_FILE=$BIN/pid
SERVER_SHUTDOWN_TIMEOUT_S=10

if [ "$CLOSE_MONITOR" == "true" ]; then
$BIN/stop-monitor.sh
if [ $? -ne 0 ]; then
if ! "$BIN"/stop-monitor.sh; then
# TODO: If remove monitor failed, should continue kill process?
echo "Failed to close monitor, please stop it manually via crontab -e"
else
echo "The HugeGraphServer monitor has been closed"
fi
fi

if [ ! -f ${PID_FILE} ]; then
if [ ! -f "${PID_FILE}" ]; then
echo "The pid file $PID_FILE doesn't exist"
exit 1
fi

PID=`cat $PID_FILE`
kill_process_and_wait "HugeGraphServer" "$PID" "$SERVER_SHUTDOWN_TIMEOUT_S"
PID=$(cat $PID_FILE)

if [ $? -eq 0 ]; then
if kill_process_and_wait "HugeGraphServer" "$PID" "$SERVER_SHUTDOWN_TIMEOUT_S"; then
rm "$PID_FILE"
fi
Loading