You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2018/11/09 15:25:14 UTC

[incubator-skywalking] branch backend-init created (now 3ab9297)

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

wusheng pushed a change to branch backend-init
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git.


      at 3ab9297  Support init mode and document with it.

This branch includes the following new commits:

     new 3ab9297  Support init mode and document with it.

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.



[incubator-skywalking] 01/01: Support init mode and document with it.

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

wusheng pushed a commit to branch backend-init
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git

commit 3ab9297c7500b3ec8397aec08179d151eff43365
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Fri Nov 9 23:25:04 2018 +0800

    Support init mode and document with it.
---
 apm-dist/bin/oapServiceInit.bat                    | 37 ++++++++++++++++
 apm-dist/bin/oapServiceInit.sh                     | 50 ++++++++++++++++++++++
 docs/en/setup/backend/backend-init-mode.md         | 20 +++++++++
 docs/en/setup/backend/backend-setup.md             |  2 +
 .../oap/server/starter/OAPServerStartUp.java       |  6 +++
 5 files changed, 115 insertions(+)

diff --git a/apm-dist/bin/oapServiceInit.bat b/apm-dist/bin/oapServiceInit.bat
new file mode 100644
index 0000000..69e453e
--- /dev/null
+++ b/apm-dist/bin/oapServiceInit.bat
@@ -0,0 +1,37 @@
+@REM
+@REM  Licensed to the Apache Software Foundation (ASF) under one or more
+@REM  contributor license agreements.  See the NOTICE file distributed with
+@REM  this work for additional information regarding copyright ownership.
+@REM  The ASF licenses this file to You under the Apache License, Version 2.0
+@REM  (the "License"); you may not use this file except in compliance with
+@REM  the License.  You may obtain a copy of the License at
+@REM
+@REM      http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM  Unless required by applicable law or agreed to in writing, software
+@REM  distributed under the License is distributed on an "AS IS" BASIS,
+@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@REM  See the License for the specific language governing permissions and
+@REM  limitations under the License.
+
+@echo off
+
+setlocal
+set OAP_PROCESS_TITLE=Skywalking-Collector
+set OAP_HOME=%~dp0%..
+set OAP_OPTS="-Xms256M -Xmx512M -Doap.logDir=%OAP_HOME%\logs"
+
+set CLASSPATH=%OAP_HOME%\config;.;
+set CLASSPATH=%OAP_HOME%\oap-libs\*;%CLASSPATH%
+
+if defined JAVA_HOME (
+ set _EXECJAVA="%JAVA_HOME%\bin\java"
+)
+
+if not defined JAVA_HOME (
+ echo "JAVA_HOME not set."
+ set _EXECJAVA=java
+)
+
+start "%OAP_PROCESS_TITLE%" %_EXECJAVA% "%OAP_OPTS%" -cp "%CLASSPATH%" -Dmode=init org.apache.skywalking.oap.server.starter.OAPServerStartUp
+endlocal
diff --git a/apm-dist/bin/oapServiceInit.sh b/apm-dist/bin/oapServiceInit.sh
new file mode 100644
index 0000000..816c287
--- /dev/null
+++ b/apm-dist/bin/oapServiceInit.sh
@@ -0,0 +1,50 @@
+# 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.
+
+#!/usr/bin/env sh
+
+PRG="$0"
+PRGDIR=`dirname "$PRG"`
+[ -z "$OAP_HOME" ] && OAP_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
+
+OAP_LOG_DIR="${OAP_HOME}/logs"
+JAVA_OPTS=" -Xms256M -Xmx512M"
+
+if [ ! -d "${OAP_HOME}/logs" ]; then
+    mkdir -p "${OAP_LOG_DIR}"
+fi
+
+_RUNJAVA=${JAVA_HOME}/bin/java
+[ -z "$JAVA_HOME" ] && _RUNJAVA=java
+
+CLASSPATH="$OAP_HOME/config:$CLASSPATH"
+for i in "$OAP_HOME"/oap-libs/*.jar
+do
+    CLASSPATH="$i:$CLASSPATH"
+done
+
+OAP_OPTIONS=" -Doap.logDir=${OAP_LOG_DIR}"
+
+eval exec "\"$_RUNJAVA\" ${JAVA_OPTS} ${OAP_OPTIONS} -classpath $CLASSPATH -Dmode=init org.apache.skywalking.oap.server.starter.OAPServerStartUp \
+        2>${OAP_LOG_DIR}/oap.log 1> /dev/null &"
+
+if [ $? -eq 0 ]; then
+    sleep 1
+	echo "SkyWalking OAP started successfully!"
+else
+	echo "SkyWalking OAP started failure!"
+	exit 1
+fi
diff --git a/docs/en/setup/backend/backend-init-mode.md b/docs/en/setup/backend/backend-init-mode.md
new file mode 100644
index 0000000..177ed3aae
--- /dev/null
+++ b/docs/en/setup/backend/backend-init-mode.md
@@ -0,0 +1,20 @@
+# Init mode
+SkyWalking backend supports multiple storage implementors. Most of them could initialize the storage, 
+such as Elastic Search, Database automatically when the backend startup in first place.
+
+But there are some unexpected happens based on the storage, such as
+`When create Elastic Search indexes concurrently, because of several backend instances startup at the same time.`,
+there is a change, the APIs of Elastic Search would be blocked without any exception.
+And this has more chances happen in container management platform, like k8s.
+
+That is where you need **Init mode** startup.
+
+## Solution
+Only one single instance should run in **Init mode** before other instances start up.
+And this instance will exit graciously after all initialization steps are done.
+
+Use `oapServiceInit.sh`/`oapServiceInit.bat` to start up backend. You should see the following logs
+> 2018-11-09 23:04:39,465 - org.apache.skywalking.oap.server.starter.OAPServerStartUp -2214 [main] INFO  [] - OAP starts up in init mode successfully, exit now...
+
+## Kubernetes
+Initialization in this mode would be included in our Kubernetes scripts and Helm.
\ No newline at end of file
diff --git a/docs/en/setup/backend/backend-setup.md b/docs/en/setup/backend/backend-setup.md
index fa07927..bb4f612 100644
--- a/docs/en/setup/backend/backend-setup.md
+++ b/docs/en/setup/backend/backend-setup.md
@@ -54,6 +54,8 @@ We recommend you to read the feature documents in our following order.
 
 1. [Overriding settings](backend-setting-override.md) in application.yml is supported
 1. [IP and port setting](backend-ip-port.md). Introduce how IP and port set and be used.
+1. [Backend init mode startup](backend-init-mode.md). How to init the environment and exit graciously.
+Read this before you try to initial a new cluster.
 1. [Cluster management](backend-cluster.md). Guide you to set backend server in cluster mode.
 1. [Deploy in kubernetes](backend-k8s.md). Guide you to build and use SkyWalking image, and deploy in k8s.
 1. [Choose storage](backend-storage.md). As we know, in default quick start, backend is running with H2
diff --git a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerStartUp.java b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerStartUp.java
index f1e4219..8caf80b 100644
--- a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerStartUp.java
+++ b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerStartUp.java
@@ -36,6 +36,12 @@ public class OAPServerStartUp {
         try {
             ApplicationConfiguration applicationConfiguration = configLoader.load();
             manager.init(applicationConfiguration);
+
+            String mode = System.getProperty("mode");
+            if ("init".equals(mode)) {
+                logger.info("OAP starts up in init mode successfully, exit now...");
+                System.exit(0);
+            }
         } catch (ConfigFileNotFoundException | ModuleNotFoundException | ProviderNotFoundException | ServiceNotProvidedException | ModuleConfigException | ModuleStartException e) {
             logger.error(e.getMessage(), e);
             System.exit(1);