maven带时间戳打包和脚本

        <finalName>${project.artifactId}_${project.version}_${current.time}</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>timestamp-property</id>
                        <goals>
                            <goal>timestamp-property</goal>
                        </goals>
                        <configuration>
                            <name>current.time</name>
                            <pattern>yyyyMMdd-HHmmss</pattern>
                            <timeZone>GMT+8</timeZone>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

run.sh

#!/bin/bash
# set APP name prefix
APP_PREFIX="real-people-parent"

# set path to Java binary
export JAVA_HOME=/data1/zulujdk17/bin/
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

# set logs directory
LOGS_DIR=./logs

# get PID file name
PID_FILE=./app.pid

# check if PID file exists
if [ -f "$PID_FILE" ]; then
    # read the PID from the file
    PID=$(cat "$PID_FILE")
else
    # set the PID to 0 if the file does not exist
    PID=0
fi

# check if the app is already running
is_running() {
    if [ "$PID" -ne 0 ] && [ -d "/proc/$PID" ]; then
        return 0
    else
        return 1
    fi
}

# find the latest JAR file
find_latest_jar() {
    latest_jar=$(ls -Art | grep "^$APP_PREFIX" | tail -n 1)
    echo $latest_jar
}

# start the app
start() {
    is_running
    if [ $? -eq 0 ]; then
        echo "App is already running with PID $PID"
        exit 1
    else
        # find the latest JAR file
        latest_jar=$(find_latest_jar)
        if [ -z "$latest_jar" ]; then
            echo "No JAR file found with prefix $APP_PREFIX"
            exit 1
        fi

        # start the app
        nohup "${JAVA_HOME}/java" -jar "$latest_jar" > "${LOGS_DIR}/log-nohup.out" 2>&1 &
        PID=$!
        echo "App started with PID $PID"
        # write the PID to the PID file
        echo "$PID" > "$PID_FILE"
    fi
}

# stop the app
stop() {
    is_running
    if [ $? -eq 0 ]; then
        kill "$PID"
        echo "App stopped with PID $PID"
        # remove the PID file
        rm "$PID_FILE"
    else
        echo "App is not running"
    fi
}

# restart the app
restart() {
    is_running
    if [ $? -eq 0 ]; then
        stop
        sleep 5
    fi
    start
}

# display the status of the app
status() {
    is_running
    if [ $? -eq 0 ]; then
        echo "App is running with PID $PID"
    else
        echo "App is not running"
    fi
}

# print usage information
usage() {
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
}

# check for the correct number of arguments
if [ $# -ne 1 ]; then
    usage
fi

#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
  "start")
    start
    ;;
  "stop")
    stop
    ;;
  "status")
    status
    ;;
  "restart")
    restart
    ;;
  *)
    usage
    ;;
esac

#日志轮转,7天之前的日志进行压缩备份
if [ ! -d "$LOGS_DIR" ]; then
    mkdir "$LOGS_DIR"
fi
cat > /etc/logrotate.d/app << EOF
${LOGS_DIR}/log-nohup.out {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create
}
EOF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

航迹者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值