-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SUBMARINE-192] Submarine workbench server daemon shell script
### 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
1 parent
54c2d5c
commit 5053e66
Showing
15 changed files
with
509 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.