This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.13 by this push:
new 8c3e49188a [To rel/0.13][IOTDB-4230] add -p pid, -v version feature
into start-server.sh (#7150)
8c3e49188a is described below
commit 8c3e49188a05d58d4ec2c828afb8eaecf3eaf5a6
Author: Xiangdong Huang <[email protected]>
AuthorDate: Mon Oct 31 21:16:01 2022 +0800
[To rel/0.13][IOTDB-4230] add -p pid, -v version feature into
start-server.sh (#7150)
---
.../src/assembly/resources/conf/logback-tool.xml | 16 +-
cli/src/assembly/resources/sbin/start-cli.sh | 111 +++++++---
cli/src/assembly/resources/tools/export-csv.sh | 8 +
cli/src/assembly/resources/tools/import-csv.sh | 9 +
docs/UserGuide/QuickStart/QuickStart.md | 30 ++-
docs/zh/UserGuide/QuickStart/QuickStart.md | 29 ++-
hive-connector/pom.xml | 6 +
pom.xml | 6 -
server/src/assembly/resources/conf/iotdb-env.bat | 7 +
server/src/assembly/resources/conf/iotdb-env.sh | 10 +
.../src/assembly/resources/conf/logback-tool.xml | 16 +-
.../src/assembly/resources/sbin/start-server.bat | 77 ++++---
server/src/assembly/resources/sbin/start-server.sh | 227 +++++++++++++++++----
server/src/assembly/resources/sbin/stop-server.bat | 3 +
server/src/assembly/resources/sbin/stop-server.sh | 4 +-
.../java/org/apache/iotdb/db/conf/IoTDBConfig.java | 62 +++---
.../org/apache/iotdb/db/conf/IoTDBConstant.java | 4 +
.../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 ++++
20 files changed, 566 insertions(+), 137 deletions(-)
diff --git a/server/src/assembly/resources/conf/logback-tool.xml
b/cli/src/assembly/resources/conf/logback-tool.xml
similarity index 62%
copy from server/src/assembly/resources/conf/logback-tool.xml
copy to cli/src/assembly/resources/conf/logback-tool.xml
index 98f3f9d5c0..7b0e9b8295 100644
--- a/server/src/assembly/resources/conf/logback-tool.xml
+++ b/cli/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/cli/src/assembly/resources/sbin/start-cli.sh
b/cli/src/assembly/resources/sbin/start-cli.sh
old mode 100644
new mode 100755
index 00742eb82e..aac56f2ca9
--- a/cli/src/assembly/resources/sbin/start-cli.sh
+++ b/cli/src/assembly/resources/sbin/start-cli.sh
@@ -18,11 +18,91 @@
# under the License.
#
+# this function is for parsing the variables like "A=B" in `start-server.sh
-D A=B`
+# The command just parse IOTDB-prefixed variables and ignore all other
variables
+checkEnvVaribles()
+{
+ string="$1"
+ array=$(echo $string | tr '=' ' ')
+ eval set -- "$array"
+ case "$1" in
+ IOTDB_INCLUDE)
+ IOTDB_INCLUDE="$2"
+ ;;
+ IOTDB_CLI_CONF)
+ IOTDB_CLI_CONF="$2"
+ ;;
+ *)
+ #do nothing
+ ;;
+ esac
+}
+
# You can put your env variable here
# export JAVA_HOME=$JAVA_HOME
+PARAMETERS=""
+
+# if [ $# -eq 0 ]
+# then
+# PARAMETERS="-h 127.0.0.1 -p 6667 -u root -pw root"
+# fi
+
+# Added parameters when default parameters are missing
+user_param="-u root"
+passwd_param="-pw root"
+host_param="-h 127.0.0.1"
+port_param="-p 6667"
+
+while true; do
+ case "$1" in
+ -u)
+ user_param="-u $2"
+ shift 2
+ ;;
+ -pw)
+ passwd_param="-pw $2"
+ shift 2
+ ;;
+ -h)
+ host_param="-h $2"
+ shift 2
+ ;;
+ -p)
+ port_param="-p $2"
+ shift 2
+ ;;
+ -D)
+ checkEnvVaribles $2
+ shift 2
+ ;;
+ --help)
+ echo "Usage: $0 [-h <ip>] [-p <port>] [-u <username>] [-pw
<password>] [-D <name=value>] [-c] [-e sql] [-maxPRC <PRC size>]"
+ exit 0
+ ;;
+ "")
+ #if we do not use getopt, we then have to process the case that
there is no argument.
+ #in some systems, when there is no argument, shift command may
throw error, so we skip directly
+ break
+ ;;
+ *)
+ PARAMETERS="$PARAMETERS $1"
+ shift
+ ;;
+ esac
+done
+
+PARAMETERS="$host_param $port_param $user_param $passwd_param $PARAMETERS"
+
+if [ -z "${IOTDB_INCLUDE}" ]; then
+ #do nothing
+ :
+elif [ -r "$IOTDB_INCLUDE" ]; then
+ . "$IOTDB_INCLUDE"
+fi
+
if [ -z "${IOTDB_HOME}" ]; then
- export IOTDB_HOME="$(cd "`dirname "$0"`"/..; pwd)"
+ export IOTDB_HOME="`dirname "$0"`/.."
fi
if [ -z "${IOTDB_CLI_CONF}" ]; then
@@ -49,37 +129,10 @@ else
JAVA=java
fi
-PARAMETERS="$@"
-
-# if [ $# -eq 0 ]
-# then
-# PARAMETERS="-h 127.0.0.1 -p 6667 -u root -pw root"
-# fi
-
-# Added parameters when default parameters are missing
-# sh version
-case "$PARAMETERS" in
-*"-pw "*) PARAMETERS=$PARAMETERS ;;
-* ) PARAMETERS="-pw root $PARAMETERS" ;;
-esac
-case "$PARAMETERS" in
-*"-u "*) PARAMETERS=$PARAMETERS ;;
-* ) PARAMETERS="-u root $PARAMETERS" ;;
-esac
-case "$PARAMETERS" in
-*"-p "*) PARAMETERS=$PARAMETERS ;;
-* ) PARAMETERS="-p 6667 $PARAMETERS" ;;
-esac
-case "$PARAMETERS" in
-*"-h "*) PARAMETERS=$PARAMETERS ;;
-* ) PARAMETERS="-h 127.0.0.1 $PARAMETERS" ;;
-esac
-
-# echo $PARAMETERS
set -o noglob
-iotdb_cli_params="-Dlogback.configurationFile=${IOTDB_CLI_CONF}/logback-cli.xml"
+iotdb_cli_params="-Dlogback.configurationFile=${IOTDB_CLI_CONF}/logback-tool.xml"
exec "$JAVA" $iotdb_cli_params -cp "$CLASSPATH" "$MAIN_CLASS" $PARAMETERS
exit $?
diff --git a/cli/src/assembly/resources/tools/export-csv.sh
b/cli/src/assembly/resources/tools/export-csv.sh
index 607a43ac2d..c010601b2a 100644
--- a/cli/src/assembly/resources/tools/export-csv.sh
+++ b/cli/src/assembly/resources/tools/export-csv.sh
@@ -22,6 +22,14 @@ echo ------------------------------------------
echo Starting IoTDB Client Export Script
echo ------------------------------------------
+
+if [ -z "${IOTDB_INCLUDE}" ]; then
+ #do nothing
+ :
+elif [ -r "$IOTDB_INCLUDE" ]; then
+ . "$IOTDB_INCLUDE"
+fi
+
if [ -z "${IOTDB_HOME}" ]; then
export IOTDB_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
diff --git a/cli/src/assembly/resources/tools/import-csv.sh
b/cli/src/assembly/resources/tools/import-csv.sh
index 6389816fdc..10fbe9c8aa 100644
--- a/cli/src/assembly/resources/tools/import-csv.sh
+++ b/cli/src/assembly/resources/tools/import-csv.sh
@@ -22,6 +22,15 @@ echo ------------------------------------------
echo Starting IoTDB Client Import Script
echo ------------------------------------------
+
+
+if [ -z "${IOTDB_INCLUDE}" ]; then
+ #do nothing
+ :
+elif [ -r "$IOTDB_INCLUDE" ]; then
+ . "$IOTDB_INCLUDE"
+fi
+
if [ -z "${IOTDB_HOME}" ]; then
export IOTDB_HOME="$(cd "`dirname "$0"`"/..; pwd)"
fi
diff --git a/docs/UserGuide/QuickStart/QuickStart.md
b/docs/UserGuide/QuickStart/QuickStart.md
index 7aba06e0fd..13e440d8e4 100644
--- a/docs/UserGuide/QuickStart/QuickStart.md
+++ b/docs/UserGuide/QuickStart/QuickStart.md
@@ -64,21 +64,39 @@ Users can start IoTDB by the start-server script under the
sbin folder.
```
# Unix/OS X
+> nohup sbin/start-server.sh -b
+```
+or
+```shell
> nohup sbin/start-server.sh >/dev/null 2>&1 &
-or
-> nohup sbin/start-server.sh -c <conf_path> >/dev/null 2>&1 &
+```
+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 (by default
before v0.14)
+- "-b": run iotdb in the background which does not 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.
+- "-H \<filePath\> save heap dump file to \<filePath\> (only works when iotdb
memory <16GB)"
+- "-E <\filePath\> save error file of JVM to \<filePath\>"
+- "-X \<command\> equal to -XX:\<command\>"
+
+```
# Windows
> sbin\start-server.bat -c <conf_path>
```
-- "-c" is optional.
-- option "-c" specifies the system configuration file directory.
+Notice that Windows OS only support -v, -c, -f and -b.
-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 d82f3063e6..6999d6c26e 100644
--- a/docs/zh/UserGuide/QuickStart/QuickStart.md
+++ b/docs/zh/UserGuide/QuickStart/QuickStart.md
@@ -57,18 +57,33 @@ IoTDB 支持多种安装途径。用户可以使用三种方式对 IoTDB 进行
Linux 系统与 MacOS 系统启动命令如下:
```
-> nohup sbin/start-server.sh >/dev/null 2>&1 &
+> nohup sbin/start-server.sh -f >/dev/null 2>&1 &
or
-> nohup sbin/start-server.sh -c <conf_path> >/dev/null 2>&1 &
-```
-
+> nohup sbin/start-server.sh -b
+```
+可选参数:
+- 默认不含任何参数时, iotdb 将在后台启动,并且不在控制台打印日志
+- "-v": 查看iotdb版本
+- "-f": 在控制台前台启动iotdb (v0.14前是默认设置)
+- "-b": 在后台启动iotdb,控制台不打印日志
+- "-p \<pidfile\>": 将pid保存到指定的文件中
+- "-h": 查看帮助
+- "printgc"(必须是最后一个参数): 打印GC日志 (从v0.14起,该参数将被-g取代)
+- "-g": 打印GC日志
+- "-c \<config folder\>": 设置IOTDB_CONF变量的值,从而修改配置文件所在文件夹
+- "-D <a=b>": 设置Java的系统环境变量或其他参数
+- "-H \<filePath\> 当OOM异常时存储堆快照到\<filePath\> (仅 Linux/Mac生效, 且要求iotdb内存小于16GB)"
+- "-E <\filePath\> save error file of JVM to \<filePath\> (仅 Linux/Mac生效)"
+- "-X \<command\> 等价于JVM中 -XX:\<command\>"
+-
Windows 系统启动命令如下:
```
-> sbin\start-server.bat -c <conf_path>
+> sbin\start-server.bat
```
-- "-c"是可选的。
-- 选项 "-c" 指定了配置文件所在的文件夹。
+
+Windows 系统支持 -c, -v, -f, -b 四个参数。
+
#### 使用 Cli 工具
diff --git a/hive-connector/pom.xml b/hive-connector/pom.xml
index 223fe99e2a..13ba80afc4 100644
--- a/hive-connector/pom.xml
+++ b/hive-connector/pom.xml
@@ -169,6 +169,12 @@
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
+ <!-- for hive connector-->
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>11.0.6</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<profiles>
diff --git a/pom.xml b/pom.xml
index 71b12d6108..82ba74b53e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -540,12 +540,6 @@
<artifactId>httpcore</artifactId>
<version>${httpcore.version}</version>
</dependency>
- <!-- for hive connector-->
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- <version>11.0.6</version>
- </dependency>
</dependencies>
</dependencyManagement>
<dependencies>
diff --git a/server/src/assembly/resources/conf/iotdb-env.bat
b/server/src/assembly/resources/conf/iotdb-env.bat
index df6b0d6a95..306e42d512 100644
--- a/server/src/assembly/resources/conf/iotdb-env.bat
+++ b/server/src/assembly/resources/conf/iotdb-env.bat
@@ -77,6 +77,13 @@ if %desired_yg_in_mb% GTR %max_sensible_yg_in_mb% (
set HEAP_NEWSIZE=%max_sensible_yg_in_mb%M
) else set HEAP_NEWSIZE=%desired_yg_in_mb%M
+@REM if the heap size is larger than 16GB, we will forbid writing the heap
dump file
+if %desired_yg_in_mb% GTR 16384 (
+ set IOTDB_ALLOW_HEAP_DUMP="false"
+) else set IOTDB_ALLOW_HEAP_DUMP="true"
+
+
+
@REM Maximum heap size
@REM set MAX_HEAP_SIZE="2G"
@REM Minimum heap size
diff --git a/server/src/assembly/resources/conf/iotdb-env.sh
b/server/src/assembly/resources/conf/iotdb-env.sh
index 8b0e016079..17e70e9fd3 100755
--- a/server/src/assembly/resources/conf/iotdb-env.sh
+++ b/server/src/assembly/resources/conf/iotdb-env.sh
@@ -57,6 +57,9 @@ case "$(uname)" in
;;
esac
+# whether we allow enable heap dump files
+IOTDB_ALLOW_HEAP_DUMP="true"
+
calculate_heap_sizes()
{
case "`uname`" in
@@ -115,6 +118,13 @@ calculate_heap_sizes()
fi
MAX_HEAP_SIZE="${max_heap_size_in_mb}M"
+ # if the heap size is larger than 16GB, we will forbid writing the heap
dump file
+ if [ "$max_heap_size_in_mb" -gt "16384" ]
+ then
+ echo "IoTDB memory is too large ($max_heap_size_in_mb MB), will forbid
writing heap dump file"
+ IOTDB_ALLOW_HEAP_DUMP="false"
+ fi
+
# Young gen: min(max_sensible_per_modern_cpu_core * num_cores, 1/4 * heap
size)
max_sensible_yg_per_core_in_mb="100"
max_sensible_yg_in_mb=`expr $max_sensible_yg_per_core_in_mb "*"
$system_cpu_cores`
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.bat
b/server/src/assembly/resources/sbin/start-server.bat
old mode 100755
new mode 100644
index 2a2d3d0f44..6defe77b9b
--- a/server/src/assembly/resources/sbin/start-server.bat
+++ b/server/src/assembly/resources/sbin/start-server.bat
@@ -18,17 +18,14 @@
@REM
@echo off
-echo ````````````````````````
-echo Starting IoTDB
-echo ````````````````````````
-
+@REM
-----------------------------------------------------------------------------
+@REM SET JAVA
set PATH="%JAVA_HOME%\bin\";%PATH%
set "FULL_VERSION="
set "MAJOR_VERSION="
set "MINOR_VERSION="
-
for /f tokens^=2-5^ delims^=.-_+^" %%j in ('java -fullversion 2^>^&1') do (
set "FULL_VERSION=%%j-%%k-%%l-%%m"
IF "%%j" == "1" (
@@ -52,12 +49,13 @@ IF "%JAVA_VERSION%" == "7" (
goto finally
)
+@REM
-----------------------------------------------------------------------------
+@REM SET DIR
if "%OS%" == "Windows_NT" setlocal
pushd %~dp0..
if NOT DEFINED IOTDB_HOME set IOTDB_HOME=%cd%
popd
-
set IOTDB_CONF=%IOTDB_HOME%\conf
set IOTDB_LOGS=%IOTDB_HOME%\logs
@@ -74,15 +72,6 @@ for %%i in (%*) do (
)
)
-IF EXIST "%IOTDB_CONF%\iotdb-env.bat" (
- CALL "%IOTDB_CONF%\iotdb-env.bat" %1
- ) ELSE (
- echo "can't find %IOTDB_CONF%\iotdb-env.bat"
- )
-
-if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.service.IoTDB
-if NOT DEFINED JAVA_HOME goto :err
-
@REM
-----------------------------------------------------------------------------
@REM JVM Opts we'll use in legacy run or installation
set JAVA_OPTS=-ea^
@@ -94,7 +83,9 @@ set JAVA_OPTS=-ea^
-DIOTDB_LOG_DIR="%IOTDB_LOGS%"^
-Dsun.jnu.encoding=UTF-8^
-Dfile.encoding=UTF-8
+@REM -Dlogback.configurationFile="%IOTDB_CONF%/logback-tool.xml"^
+@REM
----------------------------------------------------------------------------
@REM ***** CLASSPATH library setting *****
@REM Ensure that any user defined CLASSPATH variables are not used on startup
set CLASSPATH="%IOTDB_HOME%\lib\*"
@@ -106,22 +97,62 @@ set CLASSPATH=%CLASSPATH%;%1
goto :eof
-@REM
-----------------------------------------------------------------------------
:okClasspath
-
rem echo CLASSPATH: %CLASSPATH%
-"%JAVA_HOME%\bin\java" %ILLEGAL_ACCESS_PARAMS% %JAVA_OPTS% %IOTDB_HEAP_OPTS%
-cp %CLASSPATH% %IOTDB_JMX_OPTS% %MAIN_CLASS% %CONF_PARAMS%
+@REM
----------------------------------------------------------------------------
+@REM SET PARA
+
+@REM Before v0.14, iotdb-server runs in foreground by default
+@REM set foreground=0
+set foreground=yes
+
+:checkPara
+set COMMANSLINE=%*
+@REM setlocal ENABLEDELAYEDEXPANSION
+:STR_VISTOR
+for /f "tokens=1* delims= " %%a in ("%COMMANSLINE%") do (
+@REM -----more para-----
+for /f "tokens=1* delims==" %%1 in ("%%a") do (
+@REM echo 1=%%1 "|||" 2=%%2
+if "%%1"=="-v" ( java %JAVA_OPTS%
-Dlogback.configurationFile="%IOTDB_CONF%/logback-tool.xml" -cp %CLASSPATH%
org.apache.iotdb.db.service.GetVersion & goto finally )
+if "%%1"=="-f" ( set foreground=yes)
+if "%%1"=="-b" ( set foreground=0)
+)
+set COMMANSLINE=%%b
+goto STR_VISTOR
+)
+
+@REM SETLOCAL DISABLEDELAYEDEXPANSION
+
+echo ````````````````````````
+echo Starting IoTDB
+echo ````````````````````````
+
+@REM
----------------------------------------------------------------------------
+@REM SOURCE iotdb-env.bat
+IF EXIST "%IOTDB_CONF%\iotdb-env.bat" (
+ CALL "%IOTDB_CONF%\iotdb-env.bat" %1
+ ) ELSE (
+ echo "can't find %IOTDB_CONF%\iotdb-env.bat"
+ )
+if NOT DEFINED MAIN_CLASS set MAIN_CLASS=org.apache.iotdb.db.service.IoTDB
+if NOT DEFINED JAVA_HOME goto :err
+
+@REM
----------------------------------------------------------------------------
+@REM START
+:start
+if %foreground%==yes (
+ java %ILLEGAL_ACCESS_PARAMS% %JAVA_OPTS% %IOTDB_HEAP_OPTS% -cp
%CLASSPATH% %IOTDB_JMX_OPTS% %MAIN_CLASS% %CONF_PARAMS%
+ ) ELSE (
+ start javaw %ILLEGAL_ACCESS_PARAMS% %JAVA_OPTS% %IOTDB_HEAP_OPTS% -cp
%CLASSPATH% %IOTDB_JMX_OPTS% %MAIN_CLASS% %CONF_PARAMS%
+ )
goto finally
:err
echo JAVA_HOME environment variable must be set!
pause
-
-@REM
-----------------------------------------------------------------------------
:finally
-
+@ENDLOCAL
pause
-
-ENDLOCAL
diff --git a/server/src/assembly/resources/sbin/start-server.sh
b/server/src/assembly/resources/sbin/start-server.sh
index e840f42eb4..e964dde653 100755
--- a/server/src/assembly/resources/sbin/start-server.sh
+++ b/server/src/assembly/resources/sbin/start-server.sh
@@ -18,34 +18,135 @@
# under the License.
#
+# this function is for parsing the variables like "A=B" in `start-server.sh
-D A=B`
+# The command just parse IOTDB-prefixed variables and ignore all other
variables
+checkEnvVaribles()
+{
+ string="$1"
+ array=$(echo $string | tr '=' ' ')
+ eval set -- "$array"
+ case "$1" in
+ IOTDB_INCLUDE)
+ IOTDB_INCLUDE="$2"
+ echo "iotdb include is $IOTDB_INCLUDE"
+ ;;
+ IOTDB_HOME)
+ IOTDB_HOME="$2"
+ ;;
+ IOTDB_DATA_HOME)
+ IOTDB_DATA_HOME="$2"
+ ;;
+ IOTDB_CONF)
+ IOTDB_CONF="$2"
+ ;;
+ IOTDB_LOG_DIR)
+ IOTDB_LOG_DIR="$2"
+ ;;
+ IOTDB_LOG_CONFIG)
+ IOTDB_LOG_CONFIG="$2"
+ ;;
+ *)
+ #do nothing
+ ;;
+ esac
+}
-echo ---------------------
-echo Starting IoTDB
-echo ---------------------
+# before, iotdb server runs on foreground by default
+foreground="yes"
+
+IOTDB_HEAP_DUMP_COMMAND=""
+# Parse any command line options.
+#args=`getopt gvRfbhp:c:bD::H:E: "$@"`
+#eval set -- "$args"
-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" \
- "$HOME/.iotdb.in.sh" \
- /usr/share/iotdb/iotdb.in.sh \
- /etc/iotdb/iotdb.in.sh \
- /opt/iotdb/iotdb.in.sh; do
- if [ -r "$include" ]; then
- . "$include"
+while true; do
+ case "$1" in
+ -c)
+ IOTDB_CONF="$2"
+ shift 2
+ ;;
+ -p)
+ pidfile="$2"
+ shift 2
+ ;;
+ -f)
+ foreground="yes"
+ shift
+ ;;
+ -b)
+ foreground=""
+ shift
+ ;;
+ -g)
+ PRINT_GC="yes"
+ shift
+ ;;
+ -H)
+ IOTDB_HEAP_DUMP_COMMAND="$IOTDB_HEAP_DUMP_COMMAND
-XX:+HeapDumpOnOutOfMemoryError -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"
+ echo "check....$1 and $2"
+ checkEnvVaribles $2
+ shift 2
+ ;;
+ -X)
+ IOTDB_JVM_OPTS="$IOTDB_JVM_OPTS -XX:$2"
+ shift 2
+ ;;
+ -h)
+ echo "Usage: $0 [-v] [-f] [-b] [-h] [-p pidfile] [-c configFolder]
[-H HeapDumpPath] [-E JvmErrorFile] [printgc]"
+ exit 0
+ ;;
+ -v)
+ SHOW_VERSION="yes"
break
- fi
- done
-# ...otherwise, source the specified include.
+ ;;
+ printgc)
+ PRINT_GC="yes"
+ shift
+ ;;
+ --)
+ shift
+ #all others are args to the program
+ PARAMS=$*
+ break
+ ;;
+ "")
+ #if we do not use getopt, we then have to process the case that there
is no argument.
+ #in some systems, when there is no argument, shift command may throw
error, so we skip directly
+ #all others are args to the program
+ PARAMS=$*
+ break
+ ;;
+ *)
+ echo "Error parsing arguments! Unknown argument \"$1\"" >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "${IOTDB_INCLUDE}" ]; then
+ #do nothing
+ :
elif [ -r "$IOTDB_INCLUDE" ]; then
. "$IOTDB_INCLUDE"
fi
-
if [ -z "${IOTDB_HOME}" ]; then
export IOTDB_HOME="`dirname "$0"`/.."
fi
+if [ -z "${IOTDB_DATA_HOME}" ]; then
+ export IOTDB_DATA_HOME=${IOTDB_HOME}
+fi
+
if [ -z "${IOTDB_CONF}" ]; then
export IOTDB_CONF=${IOTDB_HOME}/conf
fi
@@ -54,26 +155,45 @@ if [ -z "${IOTDB_LOG_DIR}" ]; then
export IOTDB_LOG_DIR=${IOTDB_HOME}/logs
fi
+if [ -z "${IOTDB_LOG_CONFIG}" ]; then
+ export 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"
+
+
+
+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 ---------------------
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,26 +202,55 @@ 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
+# check whether we can enable heap dump when oom
+if [ "x$IOTDB_ALLOW_HEAP_DUMP" == "xtrue" ]; then
+ IOTDB_JVM_OPTS="$IOTDB_JVM_OPTS $IOTDB_HEAP_DUMP_COMMAND"
+fi
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 -DIOTDB_DATA_HOME=${IOTDB_DATA_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=${IOTDB_LOG_DIR}"
+
+ if [ "x$pidfile" != "x" ]; then
+ iotdb_parms="$iotdb_parms -Diotdb-pidfile=$pidfile"
+ 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" == "xyes" ]; then
+ iotdb_parms="$iotdb_parms -Diotdb-foreground=yes"
+ if [ "x$JVM_ON_OUT_OF_MEMORY_ERROR_OPT" != "x" ]; then
+ [ ! -z "$pidfile" ] && printf "%d" $! > "$pidfile"
+ 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
+ [ ! -z "$pidfile" ] && printf "%d" $! > "$pidfile"
+ 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 $?
}
+
# Start up the service
launch_service "$classname"
-exit $?
+exit $?
\ No newline at end of file
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/IoTDBConfig.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 50d9486a3e..b6b9efa343 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -305,11 +305,11 @@ public class IoTDBConfig {
/**
* If we enable the memory-control mechanism during index building , {@code
indexBufferSize}
* refers to the byte-size of memory buffer threshold. For each index
processor, all indexes in
- * one {@linkplain org.apache.iotdb.db.index.IndexFileProcessor
IndexFileProcessor} share a total
- * common buffer size. With the memory-control mechanism, the occupied
memory of all raw data and
- * index structures will be counted. If the memory buffer size reaches this
threshold, the indexes
- * will be flushed to the disk file. As a result, data in one series may be
divided into more than
- * one part and indexed separately. Unit: byte
+ * one {@linkplain org.apache.iotdb.db.index} share a total common buffer
size. With the
+ * memory-control mechanism, the occupied memory of all raw data and index
structures will be
+ * counted. If the memory buffer size reaches this threshold, the indexes
will be flushed to the
+ * disk file. As a result, data in one series may be divided into more than
one part and indexed
+ * separately. Unit: byte
*/
private long indexBufferSize = 128 * 1024 * 1024L;
@@ -1005,18 +1005,19 @@ public class IoTDBConfig {
confirmMultiDirStrategy();
}
- /** if the folders are relative paths, add IOTDB_HOME as the path prefix */
+ /** if the folders are relative paths, add IOTDB_DATA_HOME as the path
prefix */
private void formulateFolders() {
- systemDir = addHomeDir(systemDir);
- schemaDir = addHomeDir(schemaDir);
- syncDir = addHomeDir(syncDir);
- tracingDir = addHomeDir(tracingDir);
- walDir = addHomeDir(walDir);
- indexRootFolder = addHomeDir(indexRootFolder);
- extDir = addHomeDir(extDir);
- udfDir = addHomeDir(udfDir);
- triggerDir = addHomeDir(triggerDir);
- operationSyncLogDir = addHomeDir(operationSyncLogDir);
+
+ systemDir = addDataHomeDir(systemDir);
+ schemaDir = addDataHomeDir(schemaDir);
+ syncDir = addDataHomeDir(syncDir);
+ tracingDir = addDataHomeDir(tracingDir);
+ walDir = addDataHomeDir(walDir);
+ indexRootFolder = addDataHomeDir(indexRootFolder);
+ extDir = addDataHomeDir(extDir);
+ udfDir = addDataHomeDir(udfDir);
+ triggerDir = addDataHomeDir(triggerDir);
+ operationSyncLogDir = addDataHomeDir(operationSyncLogDir);
if
(TSFileDescriptor.getInstance().getConfig().getTSFileStorageFs().equals(FSType.HDFS))
{
String hdfsDir = getHdfsDir();
@@ -1025,9 +1026,9 @@ public class IoTDBConfig {
dataDirs[i] = hdfsDir + File.separatorChar + dataDirs[i];
}
} else {
- queryDir = addHomeDir(queryDir);
+ queryDir = addDataHomeDir(queryDir);
for (int i = 0; i < dataDirs.length; i++) {
- dataDirs[i] = addHomeDir(dataDirs[i]);
+ dataDirs[i] = addDataHomeDir(dataDirs[i]);
}
}
}
@@ -1040,7 +1041,7 @@ public class IoTDBConfig {
}
} else {
for (int i = 0; i < dataDirs.length; i++) {
- dataDirs[i] = addHomeDir(dataDirs[i]);
+ dataDirs[i] = addDataHomeDir(dataDirs[i]);
}
}
this.dataDirs = dataDirs;
@@ -1048,12 +1049,25 @@ public class IoTDBConfig {
}
private String addHomeDir(String dir) {
- String homeDir = System.getProperty(IoTDBConstant.IOTDB_HOME, null);
- if (!new File(dir).isAbsolute() && homeDir != null && homeDir.length() >
0) {
- if (!homeDir.endsWith(File.separator)) {
- dir = homeDir + File.separatorChar + dir;
+ return addDirPrefix(System.getProperty(IoTDBConstant.IOTDB_HOME, null),
dir);
+ }
+
+ // if IOTDB_DATA_HOME is not set, then we keep dataHomeDir prefix being the
same with IOTDB_HOME
+ // In this way, we can keep consistent with v0.13.0~2.
+ private String addDataHomeDir(String dir) {
+ String dataHomeDir = System.getProperty(IoTDBConstant.IOTDB_DATA_HOME,
null);
+ if (dataHomeDir == null) {
+ dataHomeDir = System.getProperty(IoTDBConstant.IOTDB_HOME, null);
+ }
+ return addDirPrefix(dataHomeDir, dir);
+ }
+
+ private String addDirPrefix(String prefix, String dir) {
+ if (!new File(dir).isAbsolute() && prefix != null && prefix.length() > 0) {
+ if (!prefix.endsWith(File.separator)) {
+ dir = prefix + File.separatorChar + dir;
} else {
- dir = homeDir + dir;
+ dir = prefix + dir;
}
}
return dir;
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 ee506130cd..6d09cb4ac6 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
@@ -52,6 +52,7 @@ public class IoTDBConstant {
public static final long KB = 1024L;
public static final String IOTDB_HOME = "IOTDB_HOME";
+ public static final String IOTDB_DATA_HOME = "IOTDB_DATA_HOME";
public static final String SEQFILE_LOG_NODE_SUFFIX = "-seq";
public static final String UNSEQFILE_LOG_NODE_SUFFIX = "-unseq";
@@ -64,6 +65,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 db237b904e..ebfd4487f9 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
@@ -52,6 +52,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;
public class IoTDB implements IoTDBMBean {
@@ -130,9 +131,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();
+ }
+}