From 826525b8eb5102b90571b486e06bc151c0d90442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=88=B5=20nice?= Date: Sun, 7 Oct 2018 14:37:55 +0800 Subject: [PATCH] :bento: add tool scripts --- .gitignore | 1 + bin/tool | 155 ++++++++++++++++++ install.sh | 19 +++ package.xml | 10 +- .../resources/application-prod.properties | 1 + 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 bin/tool create mode 100644 install.sh create mode 100644 src/main/resources/application-prod.properties diff --git a/.gitignore b/.gitignore index d49d66cb..558b8e86 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ logs/ # database file # tale.db +pack.sh \ No newline at end of file diff --git a/bin/tool b/bin/tool new file mode 100644 index 00000000..bd1bcd83 --- /dev/null +++ b/bin/tool @@ -0,0 +1,155 @@ +#!/bin/sh + +APP_NAME="tale" +JAVA_OPTS="-Xms256m -Xmx256m -Dfile.encoding=UTF-8" +psid=0 + +checkpid() { + javaps=$(pgrep -f "tale-latest") + + if [ -n "$javaps" ]; then + psid=$javaps + else + psid=0 + fi +} + +start() { + checkpid + + if [ $psid -ne 0 ]; then + echo "================================" + echo "warn: $APP_NAME already started! (pid=$psid)" + echo "================================" + else + echo "Starting $APP_NAME ..." + nohup java $JAVA_OPTS -jar tale-latest.jar --app.env=prod >/dev/null 2>&1 & + sleep 1 + checkpid + if [ $psid -ne 0 ]; then + echo "(pid=$psid) [OK]" + else + echo "[Failed]" + fi + fi +} + +stop() { + checkpid + + if [ $psid -ne 0 ]; then + echo -n "Stopping $APP_NAME ...(pid=$psid) " + kill -9 $psid + + if [ $? -eq 0 ]; then + echo "[OK]" + else + echo "[Failed]" + fi + + checkpid + if [ $psid -ne 0 ]; then + stop + fi + else + echo "================================" + echo "warn: $APP_NAME is not running" + echo "================================" + fi +} + +status() { + checkpid + if [ $psid -ne 0 ]; then + echo "$APP_NAME is running! (pid=$psid)" + else + echo "$APP_NAME is not running" + fi +} + +showlog() { + tail -f logs/tale.log +} + +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + +REMOVE_LOCAL_THEME=1 + +upgrade(){ + echo "是否允许覆盖本地主题 (y/n)?" + read con + case $con in + y|yes|Y|YES) + REMOVE_THEME=1 + ;; + *) + break + ;; + esac + + # 备份当前目录 + TIME=`date +%Y%m%d_%H%m` + tar czvf back_$TIME.tar.gz * + echo '备份成功' + + echo '开始下载最新版本.' + + TAG_VERSION=$(get_latest_release "otale/tale") + wget -N --no-check-certificate https://github.com/otale/tale/releases/download/$TAG_VERSION/tale.tar.gz + + mkdir upgrade_tmp + tar -zxvf $APP_NAME.tar.gz -C upgrade_tmp + sh tool stop + rm -rf lib tale-latest.jar tool resources/static resources/templates/admin resources/templates/*.html resources/*.properties + + if [ "$REMOVE_LOCAL_THEME" -eq "1" ]; then + rm -rf resources/templates/themes + mv upgrade_tmp/resources/templates/themes resources/templates + fi + + mv upgrade_tmp/lib . + mv upgrade_tmp/tale-latest.jar . + mv upgrade_tmp/tool . + chmod +x tool + mv upgrade_tmp/resources/static ./resources + mv upgrade_tmp/resources/*.properties ./resources + mv upgrade_tmp/resources/templates/admin ./resources/templates + mv upgrade_tmp/resources/templates/*.html ./resources/templates + + echo '升级完毕' + + rm -rf upgrade_tmp + rm -rf tale.tar.gz + + start +} + +case "$1" in + 'start') + start + ;; + 'stop') + stop + ;; + 'restart') + stop + start + ;; + 'status') + status + ;; + 'log') + showlog + ;; + 'upgrade') + upgrade + ;; + *) + echo "Usage: $0 {start | stop | restart | status | upgrade | log}" + exit 1 +esac +exit 0 \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 00000000..d9219f53 --- /dev/null +++ b/install.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +APP_NAME="tale" +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + +TAG_VERSION=$(get_latest_release "otale/tale") + +wget -N --no-check-certificate https://github.com/otale/tale/releases/download/$TAG_VERSION/tale.tar.gz + +echo '下载完毕' + +mkdir $APP_NAME +tar -zxvf $APP_NAME.tar.gz -C $APP_NAME && cd $APP_NAME +chmod +x tool +sh tool start \ No newline at end of file diff --git a/package.xml b/package.xml index f1aafdcb..ca57edc1 100644 --- a/package.xml +++ b/package.xml @@ -2,10 +2,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> - customAssembly - + bin - dir + tar.gz + zip false @@ -19,6 +19,10 @@ src/main/plugins/ /plugins + + bin/ + / + diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 00000000..0ea3f19e --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1 @@ +app.devMode=false \ No newline at end of file