Development/Shell script
[Shell Script] 데몬 start 및 stop 스크립트 작성 예시
Best Junior
2020. 1. 8. 17:37
# vim start.sh
#!/bin/bash
date_year=`date |cut -d ' ' -f7`
date_month=`date |cut -d ' ' -f2`
date_day=`date |cut -d ' ' -f4`
full_date="$date_year"_"$date_month"_"$date_day"
# 사용 환경에 따라 실행 파일 부문이나 경로는 수정 필요
nohup /root/.pyenv/shims/python /api/runserver.py >> /api/server_log_"$full_date".txt &
# vim stop.sh
#!/bin/bash
# 사용 환경에 맞게 grep 대상은 변경 필요
stop_target=`ps -ef |grep python |grep "runserver.py" |awk '{print$2}'`
for each_target in $stop_target; do
kill -9 $each_target
done