参考了一个人写的:https://gist.github.com/cnicodeme/6917319

#!/bin/bash
#
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 3.0 or above
# Copyright (C) 2005 ReFlectiv project.
# Feedback/comment/suggestions : http://www.reflectiv.net/
# -------------------------------------------------------------------------
#
# This scripts do the start/stop/restart of a PlayFramework project with GIT Support
#
 
### BEGIN vars
PORT=9100
BASE_DIR=/path/to/play/project/
CONF_PATH=/path/to/play/project/conf/application.conf
PLAY_VERSION=2.1.5 # We assume Play is in /opt/play/{version}, eg: /opt/play/2.1.5/
 
# Specific project configuration environment :
export _JAVA_OPTIONS="-Xms1024m -Xmx1024m -XX:PermSize=512m -XX:MaxPermSize=512m"
### END vars
 
# Exit immediately if a command exits with a nonzero exit status.
set -e
 
update() {
    echo "Updating"
 
    cd $BASE_DIR || exit
 
    unset GIT_DIR
    # Update repo
    git pull origin master
 
    cd $BASE_DIR
    # Creating new project (MUST BE ON THE GOOD DIR)
    /opt/play/$PLAY_VERSION/play clean compile stage
}
 
start() {
    echo "Starting server"
    eval $BASE_DIR$ENV"/target/start -Dhttp.port="$PORT" -Dconfig.file="$CONF_PATH" &"
}
 
stop() {
    echo "Stopping server"
    if [ -f $BASE_DIR"/RUNNING_PID" ];then
        kill `cat $BASE_DIR$ENV"/RUNNING_PID"`
    fi
}
 
case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
        stop
        start
    ;;
    update)
        update
    ;;
    force-restart)
        stop
        update
        start
    ;;
    *)
        echo $"Usage: $0 {start|force-restart|stop|restart|update}"
esac
 
exit 0

如下是我的修改后的脚本:

#!/bin/bash

### BEGIN vars
PORT="XXX"
BASE_DIR="XXXXX"
PLAY_NAME="XXXXXX"

PLAY_VERSION=2.7.3 
### END vars

# Exit immediately if a command exits with a nonzero exit status.
set -e

run() {
    apiPid=`ps -ef | grep $PLAY_NAME | grep -v grep|awk '{print $2}'`
    if [ -z "$apiPid" ]
    then
		    echo "Starting server"
		    rm -f ${BASE_DIR}/RUNNING_PID
		    nohup ${BASE_DIR}/bin/${PLAY_NAME} -Dplay.http.secret.key=XXXXXXXXXX -Dhttp.port=${PORT} > ${BASE_DIR}/logs/${PLAY_NAME}.logs 2>&1 &
    else
        echo "${PLAY_NAME} is already running....."
        netstat -nlp | grep "$apiPid"
    fi

}

stop() {
    rm -f ${BASE_DIR}/RUNNING_PID
    apiPid=`ps -ef | grep $PLAY_NAME | grep -v grep|awk '{print $2}'`
    if [ -z "$apiPid" ]
    then
        echo "$PLAY_NAME is Not running....."
    else
        echo "Stopping server"
        kill -s 9 `ps -ef | grep $PLAY_NAME | grep -v grep |awk '{print $2}'`
    fi    
}

status() {
    #echo "Status server"
    apiPid=`ps -ef | grep $PLAY_NAME | grep -v grep|awk '{print $2}'`
    if [ -z "$apiPid" ]
    then
        echo "$PLAY_NAME is Not running....."
    else
        echo "$PLAY_NAME is running....."
        netstat -nlp | grep "$apiPid"
    fi

}

case "$1" in
    run)
        run
    ;;
    stop)
        stop
    ;;
    restart)
        stop
        run
    ;;
    status)
        status
    ;;
    *)
        echo $"Usage: $0 {run|stop|restart|status}"
esac

exit 0

此贴来自汇总贴的子问题,只是为了方便查询。

总贴请看置顶帖:

pyspark及Spark报错问题汇总及某些函数用法。

https://blog.csdn.net/qq0719/article/details/86003435

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐