34. play 框架中如何使用start、stop、restart、status脚本化操作?

本文介绍了一个用于自动化启动、停止和更新PlayFramework项目的Shell脚本。脚本支持通过GIT进行项目更新,并能配置项目运行的端口、内存参数等。此外,还提供了修改后的脚本示例,包括对项目状态的检查、日志记录等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考了一个人写的: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.youkuaiyun.com/qq0719/article/details/86003435

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值