Skip to content

Commit

Permalink
Fix bootstrap (#154)
Browse files Browse the repository at this point in the history
* refine output & fix bug the check-1400-port

* minor
  • Loading branch information
ZhengshuaiPENG authored Apr 27, 2022
1 parent 0484c9a commit 00fe14a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 41 deletions.
44 changes: 16 additions & 28 deletions build/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
source $(cd -P -- "$(dirname -- "$0")" && pwd -P)/header.sh

function clearCrontab() {
if ! isCrontabUseable;then
Expand Down Expand Up @@ -59,34 +60,15 @@ function recordStartOrStop() {

function prepareEnv {
export NOTEBOOK_CONFIG_FILE="${NOTEBOOK_HOME}/conf/notebook.properties"
mkdir -p ${NOTEBOOK_HOME}/logs

echo ""
echo "NOTEBOOK_HOME is:${NOTEBOOK_HOME}"
echo "NOTEBOOK_CONFIG_FILE is:${NOTEBOOK_CONFIG_FILE}"

mkdir -p ${NOTEBOOK_HOME}/logs
echo "Create the log directory for the notebook:${NOTEBOOK_HOME}/logs ."
echo "NOTEBOOK_LOG_FOLDER is:${NOTEBOOK_HOME}/logs ."
echo ""
}

function checkRestPort() {
echo "Start to check the port of rest..."
used=false
if [[ "$MACHINE_OS" == "Linux" ]]; then
if [[ -n $(netstat -tpln | grep "\<$port\>" | awk '{print $7}' | sed "s/\// /g") ]]; then
used=true
fi
fi

if [[ "$MACHINE_OS" == "Mac" ]]; then
if [[ -n $(lsof -nP -iTCP:$port -sTCP:LISTEN | grep $port | awk '{print $2}') ]]; then
used=true
fi
fi

if [[ "$used" == true ]]; then
echo "<$used> already listen on $port"
exit 1
fi
}

function checkIfStopUserSameAsStartUser() {
startUser=`ps -p $1 -o user=`
Expand Down Expand Up @@ -134,10 +116,12 @@ function start(){
setLogRotate
clearRedundantProcess

# check $NOTEBOOK_HOME
[[ -z ${NOTEBOOK_HOME} ]] && quit "{NOTEBOOK_HOME} is not set, exit"
if [ -f "${NOTEBOOK_HOME}/pid" ]; then
PID=`cat ${NOTEBOOK_HOME}/pid`
if ps -p $PID > /dev/null; then
quit "Notebook is already running, stop it first, PID is $PID"
quit "Byzer Notebook is already running, stop it first, PID is $PID"
fi
fi

Expand All @@ -149,12 +133,14 @@ function start(){

prepareEnv

port=`$NOTEBOOK_HOME/bin/get-properties.sh notebook.port`
if [[ -f ${NOTEBOOK_HOME}/bin/check-env-bypass ]]; then
checkRestPort
${NOTEBOOK_HOME}/bin/check-1400-ports.sh >> ${NOTEBOOK_HOME}/logs/check-env.out 2>&1
[[ $? == 0 ]] || quit "ERROR: Port ${NOTEBOOK_PORT} is in use, another Byzer Notebook is running?"
fi

echo "${START_TIME} Start Byzer Notebook..."
nohup java -DNOTEBOOK_HOME=${NOTEBOOK_HOME} -Dspring.config.name=application,notebook -Dspring.config.location=classpath:/,file:${NOTEBOOK_HOME}/conf/ -jar ${NOTEBOOK_HOME}/lib/notebook-console.jar >> ${NOTEBOOK_HOME}/logs/notebook.out 2>&1 & echo $! >> ${NOTEBOOK_HOME}/pid &

sleep 3
clearRedundantProcess

Expand All @@ -164,7 +150,9 @@ function start(){
CUR_DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo $CUR_DATE" new Byzer Notebook process pid is "$PID >> ${NOTEBOOK_HOME}/logs/notebook.log

echo "Byzer Notebook is starting. It may take a while. For status, please visit http://`hostname`:$port."
echo ""
echo $(setColor 33 "Byzer Notebook is starting. It may take a while. For status, please visit http://$BYZER_NOTEBOOK_IP:$NOTEBOOK_PORT.")
echo ""
echo "You may also check status via: PID:`cat ${NOTEBOOK_HOME}/pid`, or Log: ${NOTEBOOK_HOME}/logs/notebook.log."
recordStartOrStop "start success" "${START_TIME}"
}
Expand All @@ -179,7 +167,6 @@ function stop(){

checkIfStopUserSameAsStartUser $PID

echo `date '+%Y-%m-%d %H:%M:%S '`"Stopping Byzer Notebook: $PID"
kill $PID
for i in {1..10}; do
sleep 3
Expand All @@ -196,6 +183,7 @@ function stop(){
rm ${NOTEBOOK_HOME}/pid

recordStartOrStop "stop" "${STOP_TIME}"
echo `date '+%Y-%m-%d %H:%M:%S '`"Byzer Notebook: $PID has been Stopped"
return 0
else
return 1
Expand Down
2 changes: 1 addition & 1 deletion build/check-1100-mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

#title=Checking Mysql Availability & Version
#title=Checking MySQL Availability & Version

source $(cd -P -- "$(dirname -- "$0")" && pwd -P)/header.sh

Expand Down
30 changes: 18 additions & 12 deletions build/check-1400-ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@

source $(cd -P -- "$(dirname -- "$0")" && pwd -P)/header.sh

notebook_port=`$NOTEBOOK_HOME/bin/get-properties.sh notebook.port`
if [[ -z ${notebook_port} ]]; then
notebook_port=9002
fi
if [[ $MACHINE_OS == "Linux" ]]; then
notebook_port_in_use=`netstat -anvp tcp | grep "\b${notebook_port}\b"`
fi
if [[ $MACHINE_OS == "Mac" ]]; then
notebook_port_in_use=`lsof -nP -iTCP:${notebook_port} -sTCP:LISTEN`
fi

[[ -z ${notebook_port_in_use} ]] || quit "ERROR: Port ${notebook_port} is in use, another Byzer Notebook is running?"
function checkRestPort() {
echo "Checking rest port on ${MACHINE_OS}"
if [[ $MACHINE_OS == "Linux" ]]; then
used=$(netstat -tpln | grep "$NOTEBOOK_PORT" | awk '{print $7}' | sed "s/\// /g")
elif [[ $MACHINE_OS == "Mac" ]]; then
used=$(lsof -nP -iTCP:$NOTEBOOK_PORT -sTCP:LISTEN | grep $NOTEBOOK_PORT | awk '{print $2}')
fi
if [ ! -z "$used" ]; then
quit "ERROR: Port ${NOTEBOOK_PORT} is in use, another Byzer Notebook is running?"
fi
echo "${NOTEBOOK_PORT} is available"
}



echo "Byzer Notebook port has been set as ${NOTEBOOK_PORT}"

checkRestPort ${NOTEBOOK_PORT}
14 changes: 14 additions & 0 deletions build/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ then
verbose "java is ${JAVA}"
fi

# set BYZER NOTEBOOK IP
if [ -z $BYZER_NOTEBOOK_IP ];then
export BYZER_NOTEBOOK_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1)
fi



# set BYZER NOTEBOOK PORT
export NOTEBOOK_PORT=$($NOTEBOOK_HOME/bin/get-properties.sh notebook.port)

if [[ -z ${NOTEBOOK_PORT} ]]; then
export NOTEBOOK_PORT=9002
fi

# check Machine
unameOut="$(uname -s)"
case "${unameOut}" in
Expand Down

0 comments on commit 00fe14a

Please sign in to comment.