southman avatar

프로그램 감시하다가 다운되면 다시 살리는 쉘 스크립트

south-man

Published: 30 May 2018 › Updated: 30 May 2018프로그램 감시하다가 다운되면 다시 살리는 쉘 스크립트

프로그램 감시하다가 다운되면 다시 살리는 쉘 스크립트

깃 허브에도 올라가 있는데, 이전에 소개드린 바이넨스 자동 매매 프로그램이 죽었을 때 다시 살리는 쉘 스크립트입니다.
https://github.com/llejo3/binance-trading/blob/master/tradingMonitor.sh

#!/bin/bash

log=./logs/monitor.log
SLEEP_SECONDS=300     # 대기 시간
BASIC_GAP_SECONDS=300 # 비교를 위한 기준 간격 시간

while [ 1 ] 
do
  # 로그가 1분정도마다 남기게 되어 있어서 INFO로 남긴 데이터 중에서 마지막 시간을 가져온다.
  last_date=`tail -200 ./logs/process.log | grep INFO | tail -1 | cut -c 2-20`
  diff_seconds=$(($(date -d now +%s) - $(date -d "$last_date" +%s)))        
  if [ $diff_seconds -gt $BASIC_GAP_SECONDS ]  # 로그가 없으면 다시 실행              
  then
    # process ID를 구한다음 프로세스를 종료시킨 다음 다시 시작한다.
    PROCESS=`ps -ef|grep process|grep -v grep | awk '{print $2}'`
    kill -9 $PROCESS
    wait
    now_date=`date '+%Y-%m-%d %H:%M:%S'`
    echo "$now_date : Process restarted." >> $log
    ./startProcess.sh
    wait
  fi
  sleep $SLEEP_SECONDS
done

Leave 프로그램 감시하다가 다운되면 다시 살리는 쉘 스크립트 to:

Written by

Read more #monitor posts


Best Posts From southman

We have not curated any of south-man's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From southman