From f2f21ca38acbb956b34138d5fde730104ede597c Mon Sep 17 00:00:00 2001 From: aimerforreimu Date: Sun, 1 Sep 2019 13:55:16 +0800 Subject: [PATCH] =?UTF-8?q?add=20manager.sh=20&=20fix=20Readme.md=20?= =?UTF-8?q?=F0=9F=91=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- manager.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 manager.sh diff --git a/README.md b/README.md index 91befc9..432d837 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ [![GitHub forks](https://img.shields.io/github/forks/aimerforreimu/AUXPI.svg)](https://github.com/aimerforreimu/AUXPI/network) [![GitHub stars](https://img.shields.io/github/stars/aimerforreimu/AUXPI.svg)](https://github.com/aimerforreimu/AUXPI/stargazers) [![GitHub license](https://img.shields.io/github/license/aimerforreimu/AUXPI.svg)](https://github.com/aimerforreimu/AUXPI) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Faimerforreimu%2Fauxpi.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Faimerforreimu%2Fauxpi?ref=badge_shield) + ![Snipaste_2019-05-12_22-16-26.png](https://i.loli.net/2019/05/12/5cd82ac5cd74d.png) @@ -27,7 +29,6 @@ ## 项目截图 ![首页](https://ws2.sinaimg.cn/large/007DFgJwgy1g10ecblh1dj31hc0nw770.jpg) -[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Faimerforreimu%2Fauxpi.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Faimerforreimu%2Fauxpi?ref=badge_shield) ![管理员后台](https://ws3.sinaimg.cn/large/007DFgJwgy1g10eavu2zqj31ha0obdii.jpg) diff --git a/manager.sh b/manager.sh new file mode 100644 index 0000000..a75771c --- /dev/null +++ b/manager.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +SERVER="auxpi" +BASE_DIR=$PWD +INSTALL_DIR="/root/auxpi" +INTERVAL=2 + +ARGS="" + +#color +INFO_FONT_PREFIX="\033[32m" +ERROR_FONT_PREFIX="\033[31m" +INFO_BACKGROUND_PREFIX="\033[42;37m" +ERROR_BACKGROUND_PREFIX="\033[41;37m" +FONT_SUFFIX="\033[0m" + + +#text block +INFO_BLOCK=${INFO_FONT_PREFIX}"[INFO]:"${FONT_SUFFIX} +ERROR_BLOCK=${ERROR_FONT_PREFIX}"[ERROR]:"${FONT_SUFFIX} + +function start() +{ + if [[ "`pgrep $SERVER -u $UID`" != "" ]];then + echo -e ${ERROR_BLOCK} "$SERVER already running" + exit 1 + fi + nohup ${BASE_DIR}/${SERVER} &> ${INSTALL_DIR}/auxpi.out & + + echo -e ${INFO_BLOCK} "sleeping & checking ..." && sleep ${INTERVAL} + + # check status + if [[ "`pgrep $SERVER -u $UID`" == "" ]];then + echo -e ${ERROR_BLOCK} "$SERVER start failed" + echo -e ${INFO_BLOCK} "start by install dir" + nohup ${INSTALL_DIR}/${SERVER} &> ${INSTALL_DIR}/auxpi.out & + exit 1 + else + echo -e ${INFO_BLOCK} "start success" + exit 1 + fi + + echo -e ${INFO_BLOCK} "sleeping & checking ......" && sleep ${INTERVAL} + + # check status + if [[ "`pgrep $SERVER -u $UID`" == "" ]];then + echo -e ${ERROR_BLOCK} "$SERVER start failed" + exit 1 + else + echo -e ${INFO_BLOCK} "start success" + fi + +} + +function status() +{ + if [[ "`pgrep $SERVER -u $UID`" != "" ]];then + echo -e ${ERROR_BLOCK} ${SERVER} is running + else + echo -e ${INFO_BLOCK} ${SERVER} is not running + fi +} + +function stop() +{ + + + if [[ "`pgrep $SERVER -u $UID`" != "" ]];then + kill -9 `pgrep ${SERVER} -u $UID` + else + echo -e ${ERROR_BLOCK} ${SERVER} has already stopped. + exit 1 + fi + + echo -e ${INFO_BLOCK} "sleeping & checking ......" && sleep ${INTERVAL} + + if [[ "`pgrep $SERVER -u $UID`" != "" ]];then + echo -e ${ERROR_BLOCK} "$SERVER stop failed" + exit 1 + else + echo -e ${INFO_BLOCK} "stop success" + fi +} + +case "$1" in + 'start') + start + ;; + 'stop') + stop + ;; + 'status') + status + ;; + 'restart') + stop && start + ;; + *) + echo "usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac