* start.sh
#!/bin/bash
SERVICE_NAME=**********
SERVICE_DIR=/home/*********
PID=$SERVICE_DIR/bin/app.pid
DATE=$(date --date=$1 +"%Y%m")
LOG=$SERVICE_DIR/logs/app.log.$DATE
ERROR=$SERVICE_DIR/logs/app-error.log
EXEC_FILE="${BASH_SOURCE[0]}"
BASE_NAME=`basename "$EXEC_FILE"`
if [ "$EXEC_FILE" = "./$BASE_NAME" ] || [ "$EXEC_FILE" = "$BASE_NAME" ]; then
TMP_FULL_PATH=`pwd`
cd ..
FULL_PATH=`pwd`
cd $TMP_FULL_PATH
else
FULL_PATH=`echo "$EXEC_FILE" | sed 's/'"${BASE_NAME}"'$//'`
cd "$FULL_PATH" > /dev/null 2>&1
TMP_FULL_PATH=`pwd`
cd ..
FULL_PATH=`pwd`
cd $TMP_FULL_PATH
fi
export CLASSPATH=.:$FULL_PATH/conf:$FULL_PATH/libs/*:$CLASSPATH
COMMAND="java -Dlog4j.configurationFile=$SERVICE_HOME/conf/log4j.xml -cp $CLASSPATH com.**********.collector.data.CollectorMain"
if [ $1 ]
then
$COMMAND $1 $2 $3
else
if [ -f $PID ]
then
echo
echo "Already started. PID: [$( cat $PID )]"
else
echo "====$SERVICE_NAME Start"
touch $PID
if nohup $COMMAND >>$LOG 2>&1 &
then echo $! >$PID
echo "Done."
echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
else echo "Error... "
/bin/rm $PID
fi
fi
fi
* Stop.sh
#!/bin/sh
# Get SyncManagerServer PID
PID=`ps -ef | grep SyncUser | grep java | awk '{print $2}'`
if [ -n "$PID" ]
then
echo "=====SyncUser is running at" $PID "Shutdown Client now"
kill -9 $PID
else
echo "=====SyncUser isn't running====="
# exit 1
fi
물론 아래 두개가 kill로 실행함으로 주의
'Develope > LINUX' 카테고리의 다른 글
[Linux] SSH port 설정 ConnectException: 연결이 거부됨 (Connection refused) (1) | 2018.02.27 |
---|---|
[shell script] 프로세스 실행 체크 스크립트 (0) | 2018.01.08 |
[Shell Script, Mysql] mysql -e 명령어 시 결과 억지로 출력하기 (wc -l / -Bse) (2) | 2017.11.22 |
[Linux] Cron 이 안될 때, 실행은 되는데 결과가 이상할 때, 실행도 안될 떄; (0) | 2017.11.16 |
[Mysql, ShellScript] Import Data sh 파일 (2) | 2017.11.07 |