Support init mode and document with it. (#1900)

This commit is contained in:
吴晟 Wu Sheng 2018-11-15 21:50:00 +08:00 committed by GitHub
parent 4e3fa95562
commit 7188c9c776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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);