Skip to content

Commit 2251adf

Browse files
authored
refact(dist): fix "restart" script not work & clean for script (#2041)
- fix "restart" script not work - clean shell script to avoid error in high-version bash/sh
1 parent 927b673 commit 2251adf

File tree

5 files changed

+73
-105
lines changed

5 files changed

+73
-105
lines changed

hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ public final class ApiVersion {
120120

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

127126
public static void check() {
128127
// Check version of hugegraph-core. Firstly do check from version 0.3
129-
// TODO: what shall we set for this version? (consider the basic compatibility)
130128
VersionUtil.check(CoreVersion.VERSION, "1.0", "1.1", CoreVersion.NAME);
131129
}
132130
}

hugegraph-core/src/main/java/org/apache/hugegraph/version/CoreVersion.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class CoreVersion {
4040

4141
public static void check() {
4242
// Check version of hugegraph-common
43-
// TODO: why shall we check it? Update it if need
4443
VersionUtil.check(CommonVersion.VERSION, "1.0", "1.1", CommonVersion.NAME);
4544
}
4645
}

hugegraph-dist/src/assembly/static/bin/hugegraph

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,26 @@
1616
# limitations under the License.
1717
#
1818

19-
#
20-
# hugegraph This shell script takes care of starting and stopping
21-
# HugeGraphServer.
22-
#
23-
# chkconfig: - 58 74
24-
# description: HugeGraphServer is graph database server. It provides graph \
25-
# service by RESTful API consisted with graph, schema, gremlin and other APIs.
26-
27-
### BEGIN INIT INFO
28-
# Provides: HugeGraphServer
29-
# Required-Start: $java
30-
# Required-Stop: $java
31-
# Should-Start: -
32-
# Should-Stop: -
33-
# Short-Description: start and stop HugeGraphServer
34-
# Description: HugeGraphServer is graph database server. It provides graph
35-
# service by RESTful API consisted with graph, schema, gremlin
36-
# and other APIs.
37-
### END INIT INFO
19+
# This script is used for starting and stopping HugeGraphServer easily.
20+
# We could copy this file under '/usr/bin' to use it globally
3821

39-
# Variables
40-
# it requires user to set a fixed abs path manually
22+
# Note: user must set a absolute path below
4123
INSTALL_DIR=
4224
SERVER_PORT=
4325

44-
${INSTALL_DIR:?"Please set variables 'INSTALL_DIR'"}
45-
${SERVER_PORT:?"Please set variables 'SERVER_PORT'"}
26+
${INSTALL_DIR:?"Please open the script then set variable 'INSTALL_DIR' manually"}
27+
${SERVER_PORT:?"Please open the script then set variable 'SERVER_PORT' manually"}
4628

4729
BIN_DIR=$INSTALL_DIR/bin
4830
SERVER_URL="http://localhost:${SERVER_PORT}"
4931
DETECT_URL="$SERVER_URL/versions"
32+
EXIT=1
5033

5134
# Start the HugeGraphServer
5235
start() {
53-
echo "Starting HugeGraphServer..."
5436
# Verify if the service is running
55-
get_status
56-
if [ $? -eq 0 ]; then
57-
echo "The service is already running"
37+
if get_status; then
38+
echo "The graph server is already running"
5839
exit 0
5940
else
6041
# Run the service
@@ -64,50 +45,41 @@ start() {
6445
#sleep 10
6546

6647
# Verify if the service is running
67-
get_status
68-
if [ $? -eq 0 ]; then
69-
echo "Service was successfully started"
48+
if get_status; then
49+
echo "Graph server was successfully started"
7050
exit 0
7151
else
72-
echo "Failed to start service"
52+
echo "Failed to start graph server"
7353
exit 1
7454
fi
7555
fi
7656
}
7757

7858
# Stop the MATH
7959
stop() {
80-
echo "Stopping HugeGraphServer..."
8160
# Verify if the service is running
82-
get_status
83-
if [ $? -eq 0 ]; then
61+
if get_status; then
8462
# Stop the service
8563
$BIN_DIR/stop-hugegraph.sh
8664

87-
# Sleep time before the service verification
88-
#sleep 10
89-
9065
# Verify if the service is running
91-
get_status
92-
if [ $? -eq 0 ]; then
66+
if get_status; then
9367
echo "Failed to stop service"
94-
exit 1
9568
else
9669
echo "Service was successfully stopped"
97-
exit 0
9870
fi
9971
else
10072
echo "The service is already stopped"
73+
fi
74+
75+
if [[ $EXIT -eq 1 ]]; then
10176
exit 0
10277
fi
10378
}
10479

10580
# Verify the status of HugeGraphServer
10681
status() {
107-
echo "Checking status of HugeGraphServer..."
108-
# Verify if the HugeGraphServer is running
109-
get_status
110-
if [ $? -eq 0 ]; then
82+
if get_status; then
11183
echo "Service is running"
11284
exit 0
11385
else
@@ -119,7 +91,7 @@ status() {
11991
# Get status of HugeGraphServer to ensure it is alive
12092
get_status() {
12193
HTTP_CODE=$(curl -I -s -w "%{http_code}" -o /dev/null $DETECT_URL)
122-
if [ $HTTP_CODE = 200 ]; then
94+
if [ "$HTTP_CODE" = 200 ]; then
12395
return 0
12496
else
12597
return 1
@@ -137,12 +109,13 @@ case "$1" in
137109
status)
138110
status
139111
;;
140-
restart|reload)
112+
restart|reload|rs)
113+
EXIT=0
141114
stop
142115
start
143116
;;
144117
*)
145-
echo $"Usage: $0 {start|stop|status|restart|reload}"
118+
echo $"Usage: $0 {start, stop, status, restart|reload|rs}"
146119
exit 1
147120
esac
148121
exit 0

hugegraph-dist/src/assembly/static/bin/stop-hugegraph.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,30 @@ abs_path() {
3939
echo "$( cd -P "$( dirname "$SOURCE" )" && pwd )"
4040
}
4141

42-
BIN=`abs_path`
42+
BIN=$(abs_path)
4343
TOP="$(cd $BIN/../ && pwd)"
4444

45-
. $BIN/util.sh
45+
. "$BIN"/util.sh
4646

4747
PID_FILE=$BIN/pid
4848
SERVER_SHUTDOWN_TIMEOUT_S=10
4949

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

60-
if [ ! -f ${PID_FILE} ]; then
59+
if [ ! -f "${PID_FILE}" ]; then
6160
echo "The pid file $PID_FILE doesn't exist"
6261
exit 1
6362
fi
6463

65-
PID=`cat $PID_FILE`
66-
kill_process_and_wait "HugeGraphServer" "$PID" "$SERVER_SHUTDOWN_TIMEOUT_S"
64+
PID=$(cat $PID_FILE)
6765

68-
if [ $? -eq 0 ]; then
66+
if kill_process_and_wait "HugeGraphServer" "$PID" "$SERVER_SHUTDOWN_TIMEOUT_S"; then
6967
rm "$PID_FILE"
7068
fi

0 commit comments

Comments
 (0)