#!/bin/bashAPP_NAME=mm-wikiINSTALL_NAME=installROOT_DIR=$(cd "$(dirname "$0")";pwd)INSTALL_DIR=$(cd "$(dirname "$0")/install";pwd)APP_FILE=${ROOT_DIR}/${APP_NAME}INSTALL_FILE=${INSTALL_DIR}/${INSTALL_NAME}PID_FILE=${ROOT_DIR}/logs/${APP_NAME}.pidLOG_FILE=${ROOT_DIR}/logs/${APP_NAME}.logfunction install() {chmod +x ${INSTALL_FILE}${INSTALL_FILE}return 0}function check_pid() {if [[ -f ${PID_FILE} ]];thenpid=`cat ${PID_FILE}`if [[ -n ${pid} ]]; thenres=`ps -p ${pid}|grep -v "PID TTY" |wc -l`return `echo ${res}`fifireturn 0}function start() {check_pidrun_res=$?if [[ ${run_res} -gt 0 ]];thenecho -n "${APP_NAME} is running already, pid="cat ${PID_FILE}return 1fichmod +x ${APP_FILE}nohup ${APP_FILE} &> ${LOG_FILE} &echo $! > ${PID_FILE}echo "${APP_NAME} start running, pid=$!"}function stop() {pid=`cat ${PID_FILE}`kill ${pid}echo "${APP_NAME} stop."}function restart() {pid=`cat ${PID_FILE}`stopstart}function status() {check_pidrun_res=$?if [[ ${run_res} -gt 0 ]];thenecho "status: start"elseecho "status: stop"fi}function help() {echo "$0 install|start|stop|restart|status|pid"}function pid() {cat ${PID_FILE}}if [[ "$1" == "" ]]; thenhelpelif [[ "$1" == "install" ]];theninstallelif [[ "$1" == "stop" ]];thenstopelif [[ "$1" == "start" ]];thenstartelif [[ "$1" == "restart" ]];thenrestartelif [[ "$1" == "status" ]];thenstatuselif [[ "$1" == "pid" ]];thenpidelsehelpfi