Skip to content

Commit

Permalink
[SUBMARINE-192] Submarine workbench server daemon shell script
Browse files Browse the repository at this point in the history
### What is this PR for?
Increase the Submarine workbench server daemon script,
Support to start, stop, restart the submarine workbench server through `submarine-daemon.sh`

```
./bin/workbench-daemon.sh [start|stop|restart]
```

### What type of PR is it?
[Feature]

### What is the Jira issue?
* https://issues.apache.org/jira/browse/SUBMARINE-192

### How should this be tested?
* [CI Pass](https://travis-ci.org/liuxunorg/hadoop-submarine/builds/590699956)

### Screenshots (if appropriate)

![workbench-daemon-sh](https://user-images.githubusercontent.com/3677382/65811462-2d97d480-e1eb-11e9-87fc-80a7fadab209.gif)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? Yes

Author: Xun Liu <liuxun@apache.org>

Closes #20 from liuxunorg/SUBMARINE-192 and squashes the following commits:

07d33e0 [Xun Liu] fixed shell script error.
d48d8ad [Xun Liu] [SUBMARINE-192] Submarine server daemon shell script
  • Loading branch information
xunliu authored and tangzhankun committed Sep 29, 2019
1 parent 54c2d5c commit 5053e66
Show file tree
Hide file tree
Showing 15 changed files with 509 additions and 110 deletions.
76 changes: 76 additions & 0 deletions bin/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
#
# 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.
#

if [[ -L ${BASH_SOURCE-$0} ]]; then
FWDIR=$(dirname $(readlink "${BASH_SOURCE-$0}"))
else
FWDIR=$(dirname "${BASH_SOURCE-$0}")
fi

if [[ -z "${SUBMARINE_HOME}" ]]; then
# Make SUBMARINE_HOME look cleaner in logs by getting rid of the
# extra ../
export SUBMARINE_HOME="$(cd "${FWDIR}/.."; pwd)"
fi

if [[ -z "${SUBMARINE_CONF_DIR}" ]]; then
export SUBMARINE_CONF_DIR="${SUBMARINE_HOME}/conf"
fi

if [[ -z "${SUBMARINE_LOG_DIR}" ]]; then
export SUBMARINE_LOG_DIR="${SUBMARINE_HOME}/logs"
fi

if [[ -f "${SUBMARINE_CONF_DIR}/submarine-env.sh" ]]; then
. "${SUBMARINE_CONF_DIR}/submarine-env.sh"
fi

WORKBENCH_CLASSPATH+=":${SUBMARINE_CONF_DIR}"

function add_each_jar_in_dir(){
if [[ -d "${1}" ]]; then
for jar in $(find -L "${1}" -maxdepth 1 -name '*jar'); do
WORKBENCH_CLASSPATH="$jar:$WORKBENCH_CLASSPATH"
done
fi
}

function add_each_jar_in_dir_recursive(){
if [[ -d "${1}" ]]; then
for jar in $(find -L "${1}" -type f -name '*jar'); do
WORKBENCH_CLASSPATH="$jar:$WORKBENCH_CLASSPATH"
done
fi
}

function add_jar_in_dir(){
if [[ -d "${1}" ]]; then
WORKBENCH_CLASSPATH="${1}/*:${WORKBENCH_CLASSPATH}"
fi
}

JAVA_OPTS+=" ${WORKBENCH_JAVA_OPTS} -Dfile.encoding=UTF-8 ${WORKBENCH_MEM}"
JAVA_OPTS+=" -Dlog4j.configuration=file://${SUBMARINE_CONF_DIR}/log4j.properties"
export JAVA_OPTS

if [[ -n "${JAVA_HOME}" ]]; then
JAVA_RUNNER="${JAVA_HOME}/bin/java"
else
JAVA_RUNNER=java
fi
export JAVA_RUNNER
160 changes: 160 additions & 0 deletions bin/workbench-daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash
#
# 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.
#
# description: Start and stop daemon script for.
#

USAGE="-e Usage: workbench-daemon.sh {start|stop|restart|status}"

if [ -L ${BASH_SOURCE-$0} ]; then
BIN=$(dirname $(readlink "${BASH_SOURCE-$0}"))
else
BIN=$(dirname ${BASH_SOURCE-$0})
fi
BIN=$(cd "${BIN}">/dev/null; pwd)

. "${BIN}/common.sh"

WORKBENCH_NAME="Submarine Workbench"
WORKBENCH_LOGFILE="${SUBMARINE_LOG_DIR}/workbench.log"
WORKBENCH_MAIN=org.apache.submarine.server.WorkbenchServer
JAVA_OPTS+=" -Dworkbench.log.file=${WORKBENCH_LOGFILE}"

add_jar_in_dir "${BIN}/../workbench"
add_jar_in_dir "${BIN}/../workbench/lib"

function initialize_default_directories() {
if [[ ! -d "${SUBMARINE_LOG_DIR}" ]]; then
echo "Log dir doesn't exist, create ${SUBMARINE_LOG_DIR}"
$(mkdir -p "${SUBMARINE_LOG_DIR}")
fi
}

function found_workbench_server_pid() {
process='WorkbenchServer';
RUNNING_PIDS=$(ps x | grep ${process} | grep -v grep | awk '{print $1}');

if [[ -z "${RUNNING_PIDS}" ]]; then
return
fi

if ! kill -0 ${RUNNING_PIDS} > /dev/null 2>&1; then
echo "${WORKBENCH_NAME} running but process is dead"
fi

echo "${RUNNING_PIDS}"
}

function wait_for_workbench_to_die() {
local pid
local count

pid=`found_workbench_server_pid`
timeout=10
count=0
timeoutTime=$(date "+%s")
let "timeoutTime+=$timeout"
currentTime=$(date "+%s")
forceKill=1

while [[ $currentTime -lt $timeoutTime ]]; do
$(kill ${pid} > /dev/null 2> /dev/null)
if kill -0 ${pid} > /dev/null 2>&1; then
sleep 3
else
forceKill=0
break
fi
currentTime=$(date "+%s")
done

if [[ forceKill -ne 0 ]]; then
$(kill -9 ${pid} > /dev/null 2> /dev/null)
fi
}

function start() {
local pid

pid=`found_workbench_server_pid`
if [[ ! -z "$pid" && "$pid" != 0 ]]; then
echo "${WORKBENCH_NAME}:${pid} is already running"
return 0;
fi

initialize_default_directories

echo "WORKBENCH_CLASSPATH: ${WORKBENCH_CLASSPATH}" >> "${WORKBENCH_LOGFILE}"

nohup $JAVA_RUNNER $JAVA_OPTS -cp $WORKBENCH_CLASSPATH $WORKBENCH_MAIN >> "${WORKBENCH_LOGFILE}" 2>&1 < /dev/null &
pid=$!
if [[ ! -z "${pid}" ]]; then
echo "${WORKBENCH_NAME} start"
return 1;
fi
}

function stop() {
local pid
pid=`found_workbench_server_pid`

if [[ -z "$pid" ]]; then
echo "${WORKBENCH_NAME} is not running"
return 0;
else
# submarine workbench daemon kill
wait_for_workbench_to_die
echo "${WORKBENCH_NAME} stop"
fi
}

function find_workbench_process() {
local pid
pid=`found_workbench_server_pid`

if [[ -z "$pid" ]]; then
if ! kill -0 ${pid} > /dev/null 2>&1; then
echo "${WORKBENCH_NAME} running but process is dead"
return 1
else
echo "${WORKBENCH_NAME} is running"
fi
else
echo "${WORKBENCH_NAME} is not running"
return 1
fi
}

case "${1}" in
start)
start
;;
stop)
stop
;;
restart)
echo "${WORKBENCH_NAME} is restarting" >> "${WORKBENCH_LOGFILE}"
stop
start
;;
status)
find_workbench_process
;;
*)
echo ${USAGE}
esac
22 changes: 22 additions & 0 deletions conf/submarine-env.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
#
# 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.
#

# export JAVA_HOME=java

# export WORKBENCH_JAVA_OPTS
# export WORKBENCH_MEM="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m"
64 changes: 18 additions & 46 deletions dev-support/bin/submarine-site.xml → conf/submarine-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,113 +20,85 @@
<configuration>

<property>
<name>submarine.server.addr</name>
<name>workbench.server.addr</name>
<value>0.0.0.0</value>
<description>Server address</description>
</property>

<property>
<name>submarine.server.port</name>
<name>workbench.server.port</name>
<value>8080</value>
<description>Server port.</description>
</property>

<property>
<name>submarine.ssl</name>
<name>workbench.ssl</name>
<value>false</value>
<description>Should SSL be used by the servers?</description>
<description>Should SSL be used by the workbench servers?</description>
</property>

<property>
<name>submarine.server.ssl.port</name>
<name>workbench.server.ssl.port</name>
<value>8443</value>
<description>Server ssl port. (used when ssl property is set to true)</description>
</property>

<property>
<name>submarine.server.context.path</name>
<value>/</value>
<description>Context Path of the Web Application</description>
</property>

<property>
<name>submarine.war.tempdir</name>
<value>webapps</value>
<description>Location of jetty temporary directory</description>
</property>

<property>
<name>submarine.ssl.client.auth</name>
<name>workbench.ssl.client.auth</name>
<value>false</value>
<description>Should client authentication be used for SSL connections?</description>
</property>

<property>
<name>submarine.ssl.keystore.path</name>
<name>workbench.ssl.keystore.path</name>
<value>keystore</value>
<description>Path to keystore relative to submarine configuration directory</description>
</property>

<property>
<name>submarine.ssl.keystore.type</name>
<name>workbench.ssl.keystore.type</name>
<value>JKS</value>
<description>The format of the given keystore (e.g. JKS or PKCS12)</description>
</property>

<property>
<name>submarine.ssl.keystore.password</name>
<name>workbench.ssl.keystore.password</name>
<value>change me</value>
<description>Keystore password. Can be obfuscated by the Jetty Password tool</description>
</property>

<!--
<property>
<name>submarine.ssl.key.manager.password</name>
<name>workbench.ssl.key.manager.password</name>
<value>change me</value>
<description>Key Manager password. Defaults to keystore password. Can be obfuscated.</description>
</property>
-->

<property>
<name>submarine.ssl.truststore.path</name>
<name>workbench.ssl.truststore.path</name>
<value>truststore</value>
<description>Path to truststore relative to submarine configuration directory. Defaults to the keystore path
</description>
<description>Path to truststore relative to submarine configuration directory. Defaults to the keystore path</description>
</property>

<property>
<name>submarine.ssl.truststore.type</name>
<name>workbench.ssl.truststore.type</name>
<value>JKS</value>
<description>The format of the given truststore (e.g. JKS or PKCS12). Defaults to the same type as the keystore
type
</description>
<description>The format of the given truststore (e.g. JKS or PKCS12). Defaults to the same type as the keystore type</description>
</property>

<!--
<property>
<name>submarine.ssl.truststore.password</name>
<name>workbench.ssl.truststore.password</name>
<value>change me</value>
<description>Truststore password. Can be obfuscated by the Jetty Password tool. Defaults to the keystore password</description>
</property>
-->

<property>
<name>submarine.websocket.max.text.message.size</name>
<value>1024000</value>
<description>Size in characters of the maximum text message to be received by websocket. Defaults to 1024000
</description>
</property>

<property>
<name>submarine.server.default.dir.allowed</name>
<value>false</value>
<description>Enable directory listings on server.</description>
</property>

<property>
<name>submarine.run.mode</name>
<value>auto</value>
<description>'auto|local|k8s|docker'</description>
<name>workbench.web.war</name>
<value>workbench/workbench-web.war</value>
<description>Submarine workbench web war file path.</description>
</property>

</configuration>
Loading

0 comments on commit 5053e66

Please sign in to comment.