shell script, centOS, nodeJS, forever 스케줄러 구현

$ vi /etc/crontab
---
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/node/bin
NODE_PATH=$NODE_PATH:/usr/local/node/lib/node_modules
*/12 * * * * root /root/script/detect_forever.sh scan
---

$ vi /root/script/detect_forever.sh
---
"#!/bin/bash

TIME=`date +""%Y-%m-%d %H:%M:%S""`
LOG=`date +""%Y%m%d""`

DIR='/root/.forever/'

HOME='/home/zeroweb/'

LOGFILES='/home/backup/log/detect_forever.log'

if [ $# -lt 1 ]; then
echo -e "" ""
echo -e "" usage: ./detect_forever.sh <process>""
echo -e "" e.g: ./detect_forever.sh scan""
exit 1;
else

PROCESS=${1}

if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s ""\n"") -eq 0 ]; then

forever start -o ${DIR}${PROCESS}_output_${LOG}.log -e ${DIR}${PROCESS}_error_${LOG}.log ${HOME}${PROCESS}Collect.js

echo -e ""\n""[${TIME}]""Start ""${PROCESS}""\n"" >> ${LOGFILES}
else
echo -e ""\n""[${TIME}]""Alive ""${PROCESS}""\n"" >> ${LOGFILES}
fi
fi"
---

$ tail -f scan_error_201605111805.log scan_output_201605111805.log

댓글