You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2022/08/28 15:37:45 UTC

[iotdb] branch 4230-2-0.13 updated (2d125a4ddf -> 84a49f89f0)

This is an automated email from the ASF dual-hosted git repository.

hxd pushed a change to branch 4230-2-0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


 discard 2d125a4ddf add -p pid, -v version feature
     new 84a49f89f0 add -p pid, -v version feature

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (2d125a4ddf)
            \
             N -- N -- N   refs/heads/4230-2-0.13 (84a49f89f0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/UserGuide/QuickStart/QuickStart.md            | 24 +++---
 docs/zh/UserGuide/QuickStart/QuickStart.md         | 16 +++-
 .../src/assembly/resources/conf/logback-tool.xml   | 16 +++-
 server/src/assembly/resources/sbin/start-server.sh | 91 ++++++++++++----------
 4 files changed, 91 insertions(+), 56 deletions(-)


[iotdb] 01/01: add -p pid, -v version feature

Posted by hx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch 4230-2-0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 84a49f89f0f9f582b85ea62c34774e3b62452688
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Sun Aug 28 19:15:18 2022 +0800

    add -p pid, -v version feature
---
 docs/UserGuide/QuickStart/QuickStart.md            |  24 ++--
 docs/zh/UserGuide/QuickStart/QuickStart.md         |  16 ++-
 .../src/assembly/resources/conf/logback-tool.xml   |  16 ++-
 server/src/assembly/resources/sbin/start-server.sh | 150 ++++++++++++++++-----
 server/src/assembly/resources/sbin/stop-server.bat |   3 +
 server/src/assembly/resources/sbin/stop-server.sh  |   4 +-
 .../org/apache/iotdb/db/conf/IoTDBConstant.java    |   3 +
 .../org/apache/iotdb/db/service/GetVersion.java    |  27 ++++
 .../java/org/apache/iotdb/db/service/IoTDB.java    |  10 ++
 .../org/apache/iotdb/db/service/DaemonTest.java    |  41 ++++++
 10 files changed, 250 insertions(+), 44 deletions(-)

diff --git a/docs/UserGuide/QuickStart/QuickStart.md b/docs/UserGuide/QuickStart/QuickStart.md
index 103587bd06..1a51764128 100644
--- a/docs/UserGuide/QuickStart/QuickStart.md
+++ b/docs/UserGuide/QuickStart/QuickStart.md
@@ -64,23 +64,29 @@ Users can start IoTDB by the start-server script under the sbin folder.
 
 ```
 # Unix/OS X
-> nohup sbin/start-server.sh >/dev/null 2>&1 &
+> nohup sbin/start-server.sh -f
 or
-> nohup sbin/start-server.sh -c <conf_path> -rpc_port <rpc_port> >/dev/null 2>&1 &
+> nohup sbin/start-server.sh 
 
 # Windows
-> sbin\start-server.bat -c <conf_path> -rpc_port <rpc_port>
+> sbin\start-server.bat 
 ```
 
-- "-c" and "-rpc_port" are optional.
-- option "-c" specifies the system configuration file directory.
-- option "-rpc_port" specifies the rpc port.
-- if both option specified, the *rpc_port* will overrides the rpc_port in *conf_path*.
+parameters:
+- by default, iotdb will run in the background
+- "-v": show iotdb version
+- "-f": run iotdb on the foreground and print logs on the console
+- "-p \<pidfile\>": save the pid into target pidfile
+- "-h": help
+- "printgc"(must be at the end of the command): print the GC log (deprecated from v0.14 on)
+- "-g": print the GC log
+- "-c \<config folder\>": set IOTDB_CONF parameter
+- "-D <a=b>": set system variables to IoTDB program.
 
-if you want to use JMX to connect IOTDB, you may need to add 
+if you want to use JMX to connect IOTDB, you may need to add/modify 
 
 ```
--Dcom.sun.management.jmxremote.rmi.port=PORT -Djava.rmi.server.hostname=IP 
+-Dcom.sun.management.jmxremote.rmi.port=<PORT> -Djava.rmi.server.hostname=<IP> 
 ```
 to $IOTDB_JMX_OPTS in iotdb-env.sh. or iotdb-env.bat
 
diff --git a/docs/zh/UserGuide/QuickStart/QuickStart.md b/docs/zh/UserGuide/QuickStart/QuickStart.md
index 983766d6da..6d39c45180 100644
--- a/docs/zh/UserGuide/QuickStart/QuickStart.md
+++ b/docs/zh/UserGuide/QuickStart/QuickStart.md
@@ -57,10 +57,20 @@ IoTDB 支持多种安装途径。用户可以使用三种方式对 IoTDB 进行
 Linux 系统与 MacOS 系统启动命令如下:
 
 ```
-> nohup sbin/start-server.sh >/dev/null 2>&1 &
+> nohup sbin/start-server.sh -f
 or
-> nohup sbin/start-server.sh -c <conf_path> -rpc_port <rpc_port> >/dev/null 2>&1 &
-```
+> nohup sbin/start-server.sh
+```
+可选参数:
+- 默认不含任何参数时, iotdb 将在后台启动,并且不在控制台打印日志
+- "-v": 查看iotdb版本
+- "-f": 在控制台前台启动iotdb
+- "-p \<pidfile\>": 将pid保存到指定的文件中
+- "-h": 查看帮助
+- "printgc"(必须是最后一个参数): 打印GC日志 (从v0.14起,该参数将被-g取代)
+- "-g": 打印GC日志
+- "-c \<config folder\>": 设置IOTDB_CONF变量的值,从而修改配置文件所在文件夹
+- "-D <a=b>": 设置Java的系统环境变量或其他参数
 
 Windows 系统启动命令如下:
 
diff --git a/server/src/assembly/resources/conf/logback-tool.xml b/server/src/assembly/resources/conf/logback-tool.xml
index 98f3f9d5c0..7b0e9b8295 100644
--- a/server/src/assembly/resources/conf/logback-tool.xml
+++ b/server/src/assembly/resources/conf/logback-tool.xml
@@ -19,4 +19,18 @@
     under the License.
 
 -->
-<configuration/>
+<configuration scan="true" scanPeriod="60 seconds">
+    <appender class="ch.qos.logback.core.ConsoleAppender" name="stdout">
+        <Target>System.out</Target>
+        <encoder>
+            <pattern>%d [%t] %-5p %C{25}:%L - %m %n</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <level>ERROR</level>
+        </filter>
+    </appender>
+    <root level="error">
+        <appender-ref ref="stdout"/>
+    </root>
+</configuration>
diff --git a/server/src/assembly/resources/sbin/start-server.sh b/server/src/assembly/resources/sbin/start-server.sh
index e840f42eb4..e73de6c160 100755
--- a/server/src/assembly/resources/sbin/start-server.sh
+++ b/server/src/assembly/resources/sbin/start-server.sh
@@ -18,12 +18,6 @@
 # under the License.
 #
 
-
-echo ---------------------
-echo Starting IoTDB
-echo ---------------------
-
-
 if [ "x$IOTDB_INCLUDE" = "x" ]; then
     # Locations (in order) to use when searching for an include file.
     for include in "`dirname "$0"`/iotdb.in.sh" \
@@ -41,7 +35,6 @@ elif [ -r "$IOTDB_INCLUDE" ]; then
     . "$IOTDB_INCLUDE"
 fi
 
-
 if [ -z "${IOTDB_HOME}" ]; then
   export IOTDB_HOME="`dirname "$0"`/.."
 fi
@@ -54,26 +47,103 @@ if [ -z "${IOTDB_LOG_DIR}" ]; then
   export IOTDB_LOG_DIR=${IOTDB_HOME}/logs
 fi
 
+if [ -z "${configurationFile}" ]; then
+  IOTDB_LOG_CONFIG="${IOTDB_CONF}/logback.xml"
+fi
 
-is_conf_path=false
-for arg do
-  shift
-  if [ "$arg" == "-c" ]; then
-    is_conf_path=true
-    continue
-  fi
-  if [ $is_conf_path == true ]; then
-    IOTDB_CONF=$arg
-    is_conf_path=false
-    continue
-  fi
-  set -- "$@" "$arg"
+# Parse any command line options.
+args=`getopt gvRfhp:c:bD::H:E: "$@"`
+eval set -- "$args"
+
+while true; do
+    case "$1" in
+        -c)
+            IOTDB_CONF="$2"
+            shift 2
+            ;;
+        -p)
+            pidfile="$2"
+            shift 2
+        ;;
+        -f)
+            foreground="yes"
+            shift
+        ;;
+        -g)
+            PRINT_GC="yes"
+            shift
+        ;;
+        -H)
+            IOTDB_JVM_OPTS="$IOTDB_JVM_OPTS -XX:HeapDumpPath=$2"
+            shift 2
+        ;;
+        -E)
+            IOTDB_JVM_OPTS="$IOTDB_JVM_OPTS -XX:ErrorFile=$2"
+            shift 2
+        ;;
+        -D)
+            IOTDB_JVM_OPTS="$IOTDB_JVM_OPTS -D$2"
+            shift 2
+        ;;
+        -h)
+            echo "Usage: $0 [-v] [-f] [-h] [-p pidfile] [-c configFolder] [-H HeapDumpPath] [-E JvmErrorFile] [printgc]"
+            exit 0
+        ;;
+        -v)
+            SHOW_VERSION="yes"
+            break
+        ;;
+        --)
+            shift
+            #all others are args to the program
+            PARAMS=$*
+            break
+        ;;
+        *)
+            echo "Error parsing arguments! Unknown argument \"$1\"" >&2
+            exit 1
+        ;;
+    esac
+done
+
+CLASSPATH=""
+for f in ${IOTDB_HOME}/lib/*.jar; do
+  CLASSPATH=${CLASSPATH}":"$f
 done
 
-CONF_PARAMS=$*
+classname=org.apache.iotdb.db.service.IoTDB
+
+if [ "x$SHOW_VERSION" != "x" ]; then
+    classname=org.apache.iotdb.db.service.GetVersion
+    IOTDB_LOG_CONFIG="${IOTDB_CONF}/logback-tool.xml"
+    # find java in JAVA_HOME
+    if [ -n "$JAVA_HOME" ]; then
+        for java in "$JAVA_HOME"/bin/amd64/java "$JAVA_HOME"/bin/java; do
+            if [ -x "$java" ]; then
+                JAVA="$java"
+                break
+            fi
+        done
+    else
+        JAVA=java
+    fi
+    exec "$JAVA" -cp "$CLASSPATH" $IOTDB_JVM_OPTS "-Dlogback.configurationFile=${IOTDB_LOG_CONFIG}" "$classname"
+    exit 0
+fi
+
+echo ---------------------
+echo Starting IoTDB
+echo ---------------------
+
+## this is for being compatibile with v0.13, can be removed from v0.14 on.
+data=($*)
+if [ "x${data[0]}" == "xprintgc" ]; then
+  PRINT_GC="yes"
+fi
+## end
 
 if [ -f "$IOTDB_CONF/iotdb-env.sh" ]; then
-    if [ "$#" -ge "1" -a "$1" == "printgc" ]; then
+    if [ "x$PRINT_GC" != "x" ]; then
       . "$IOTDB_CONF/iotdb-env.sh" "printgc"
     else
         . "$IOTDB_CONF/iotdb-env.sh"
@@ -82,22 +152,42 @@ else
     echo "can't find $IOTDB_CONF/iotdb-env.sh"
 fi
 
-CLASSPATH=""
-for f in ${IOTDB_HOME}/lib/*.jar; do
-  CLASSPATH=${CLASSPATH}":"$f
-done
-classname=org.apache.iotdb.db.service.IoTDB
-
 launch_service()
 {
 	class="$1"
-	iotdb_parms="-Dlogback.configurationFile=${IOTDB_CONF}/logback.xml"
+	iotdb_parms="-Dlogback.configurationFile=${IOTDB_LOG_CONFIG}"
 	iotdb_parms="$iotdb_parms -DIOTDB_HOME=${IOTDB_HOME}"
 	iotdb_parms="$iotdb_parms -DTSFILE_HOME=${IOTDB_HOME}"
 	iotdb_parms="$iotdb_parms -DIOTDB_CONF=${IOTDB_CONF}"
 	iotdb_parms="$iotdb_parms -DTSFILE_CONF=${IOTDB_CONF}"
 	iotdb_parms="$iotdb_parms -Dname=iotdb\.IoTDB"
-	exec "$JAVA" $illegal_access_params $iotdb_parms $IOTDB_JMX_OPTS -cp "$CLASSPATH" "$class" $CONF_PARAMS
+	iotdb_parms="$iotdb_parms -DIOTDB_LOG_DIR=${DIOTDB_LOG_DIR}"
+
+  if [ "x$pidpath" != "x" ]; then
+     iotdb_parms="$iotdb_parms -Diotdb-pidfile=$pidpath"
+  fi
+
+  # The iotdb-foreground option will tell IoTDB not to close stdout/stderr, but it's up to us not to background.
+  if [ "x$foreground" != "x" ]; then
+      iotdb_parms="$iotdb_parms -Diotdb-foreground=yes"
+      if [ "x$JVM_ON_OUT_OF_MEMORY_ERROR_OPT" != "x" ]; then
+          exec $NUMACTL "$JAVA" $JVM_OPTS "$JVM_ON_OUT_OF_MEMORY_ERROR_OPT" $illegal_access_params $iotdb_parms $IOTDB_JMX_OPTS -cp "$CLASSPATH" $IOTDB_JVM_OPTS "$class" $PARAMS
+      else
+          exec $NUMACTL "$JAVA" $JVM_OPTS $illegal_access_params $iotdb_parms $IOTDB_JMX_OPTS -cp "$CLASSPATH" $IOTDB_JVM_OPTS "$class" $PARAMS
+      fi
+  # Startup IoTDB, background it, and write the pid.
+  else
+      if [ "x$JVM_ON_OUT_OF_MEMORY_ERROR_OPT" != "x" ]; then
+            exec $NUMACTL "$JAVA" $JVM_OPTS "$JVM_ON_OUT_OF_MEMORY_ERROR_OPT" $illegal_access_params $iotdb_parms $IOTDB_JMX_OPTS -cp "$CLASSPATH" $IOTDB_JVM_OPTS "$class" $PARAMS 2>&1 > /dev/null  <&- &
+            [ ! -z "$pidfile" ] && printf "%d" $! > "$pidfile"
+            true
+      else
+            exec $NUMACTL "$JAVA" $JVM_OPTS $illegal_access_params $iotdb_parms $IOTDB_JMX_OPTS -cp "$CLASSPATH" $IOTDB_JVM_OPTS "$class" $PARAMS 2>&1 > /dev/null <&- &
+            [ ! -z "$pidfile" ] && printf "%d" $! > "$pidfile"
+            true
+      fi
+  fi
+
 	return $?
 }
 
diff --git a/server/src/assembly/resources/sbin/stop-server.bat b/server/src/assembly/resources/sbin/stop-server.bat
index a2f85581fa..4944e7449f 100755
--- a/server/src/assembly/resources/sbin/stop-server.bat
+++ b/server/src/assembly/resources/sbin/stop-server.bat
@@ -27,6 +27,8 @@ for /f  "eol=; tokens=2,2 delims==" %%i in ('findstr /i "^rpc_port"
   set rpc_port=%%i
 )
 
+echo "check whether the rpc_port is used..., port is " %rpc_port%
+
 for /f  "eol=; tokens=2,2 delims==" %%i in ('findstr /i "rpc_address"
 %superior_dir%\conf\iotdb-engine.properties') do (
   set rpc_address=%%i
@@ -34,5 +36,6 @@ for /f  "eol=; tokens=2,2 delims==" %%i in ('findstr /i "rpc_address"
 
 for /f "tokens=5" %%a in ('netstat /ano ^| findstr %rpc_address%:%rpc_port%') do (
   taskkill /f /pid %%a
+  echo "close IoTDB, PID:" %%a
 )
 rem ps ax | grep -i 'iotdb.IoTDB' | grep -v grep | awk '{print $1}' | xargs kill -SIGTERM
diff --git a/server/src/assembly/resources/sbin/stop-server.sh b/server/src/assembly/resources/sbin/stop-server.sh
index 0cd069a8fb..92f4c4428f 100755
--- a/server/src/assembly/resources/sbin/stop-server.sh
+++ b/server/src/assembly/resources/sbin/stop-server.sh
@@ -22,6 +22,8 @@
 IOTDB_CONF="`dirname "$0"`/../conf"
 rpc_port=`sed '/^rpc_port=/!d;s/.*=//' ${IOTDB_CONF}/iotdb-engine.properties`
 
+echo "check whether the rpc_port is used..., port is" $rpc_port
+
 if  type lsof > /dev/null 2>&1 ; then
   PID=$(lsof -t -i:${rpc_port} -sTCP:LISTEN)
 elif type netstat > /dev/null 2>&1 ; then
@@ -38,5 +40,5 @@ if [ -z "$PID" ]; then
   exit 1
 else
   kill -s TERM $PID
-  echo "close IoTDB"
+  echo "close IoTDB, PID:" $PID
 fi
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
index 337a9e0a6e..7a406386ca 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
@@ -64,6 +64,9 @@ public class IoTDBConstant {
   public static final String LAST_VALUE = "last_value";
   public static final int MIN_SUPPORTED_JDK_VERSION = 8;
 
+  public static final String IOTDB_FOREGROUND = "iotdb-foreground";
+  public static final String IOTDB_PIDFILE = "iotdb-pidfile";
+
   // show info
   public static final String COLUMN_ITEM = "                             item";
   public static final String COLUMN_VALUE = "value";
diff --git a/server/src/main/java/org/apache/iotdb/db/service/GetVersion.java b/server/src/main/java/org/apache/iotdb/db/service/GetVersion.java
new file mode 100644
index 0000000000..8b49874460
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/service/GetVersion.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.service;
+
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+
+public class GetVersion {
+  public static void main(String[] args) {
+    System.out.println(IoTDBDescriptor.getInstance().getConfig().getIoTDBVersion());
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
index 66ffc23ac4..fb10ab2dd3 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/IoTDB.java
@@ -51,6 +51,7 @@ import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.IOException;
 
 import static org.apache.iotdb.db.utils.JarLoaderUtil.loadExternLib;
@@ -133,9 +134,18 @@ public class IoTDB implements IoTDBMBean {
     config.setEnablePartialInsert(prevIsEnablePartialInsert);
     activated = true;
 
+    processPid();
+
     logger.info("{} has started.", IoTDBConstant.GLOBAL_DB_NAME);
   }
 
+  void processPid() {
+    String pidFile = System.getProperty(IoTDBConstant.IOTDB_PIDFILE);
+    if (pidFile != null) {
+      new File(pidFile).deleteOnExit();
+    }
+  }
+
   private void setUp() throws StartupException, QueryProcessException {
     logger.info("Setting up IoTDB...");
 
diff --git a/server/src/test/java/org/apache/iotdb/db/service/DaemonTest.java b/server/src/test/java/org/apache/iotdb/db/service/DaemonTest.java
new file mode 100644
index 0000000000..5ea7c01104
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/service/DaemonTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.service;
+
+import org.apache.iotdb.db.conf.IoTDBConstant;
+
+import org.junit.Test;
+
+public class DaemonTest {
+
+  @Test
+  public void testPid() {
+    IoTDB ioTDB = IoTDB.getInstance();
+    // no pid set, so there is nothing happens
+    ioTDB.processPid();
+  }
+
+  @Test
+  public void testSetPid() {
+    IoTDB ioTDB = IoTDB.getInstance();
+    System.setProperty(IoTDBConstant.IOTDB_PIDFILE, "./iotdb.pid");
+    // no pid set, so there is nothing happens
+    ioTDB.processPid();
+  }
+}