#!/bin/bash SELF=$(readlink -f $0) DIR=$(dirname $SELF) LOG_FILE=${DIR}/log/command_server.log start() { local ARGS="" source ${DIR}/conf/command_server.conf if [ -z "${SERVER_PORT}" ]; then local SERVER_PORT=20001 fi if [ -z "$TOKEN" ]; then local TOKEN="snajkfbnakbefhsHshbfaKbsKJSbfskFBsfsSfllapkFkzaSBHJFVsBFHjsb" fi local ARGS="--port ${SERVER_PORT} --token ${TOKEN}" eval "${DIR}/bin/command_server ${ARGS} >> ${LOG_FILE} &" return $? } stop() { local PID=$(pgrep -f "${DIR}/bin/command_server .*") kill -9 ${PID} >/dev/null 2>&1 } restart() { stop sleep 1 start return $? } status() { local PID=$(pgrep -f "${DIR}/bin/command_server .*") if [ -z "$PID" ]; then echo "Command_server is not running." return 1 fi eval "ps -ef |grep '${DIR}/bin/command_server'|grep -v grep" echo "Command_server is running." return 0 } eval "$@" exit $?