django runserver 데몬 start / stop 스크립트를 작성해보았다.

참고하여 데몬 start / stop 관리 스크립트를 작성하면 도움이 되겠다.

start * stop 데몬에서 함께 참조해야하는 변수들이 필요하여 아래와 같이 variables.sh 파일을 따로 생성해주었다.

 

 

 

1. variables.sh

#!/bin/bash
  
########### You need to change only this part ###########
start_dir="/django_service/saja_site" #ex. "/django_test/test_site"
port="8080"        # Not recommand 8000
#########################################################

log_dir=$start_dir"/logs"
log_file="django_"
file_type="log.txt"
log_file_with_date=$log_dir/$log_file$date_front$file_type

 

 

 

2. start_djangoserver_ver1.0.0.sh

#!/bin/bash
source ./variables.sh
date_front=`date |awk '{print$1$2$3}'`

if [ ! -f $start_dir/manage.py ];then
    echo "[Warning] You have to change this script with your setting!"
else
    if [ ! -d $log_dir ];then
        mkdir $log_dir
        echo "[INFO] Success to make dir : logs" >> $log_file_with_date
    fi
    echo "#####################################" >> $log_file_with_date
    echo "########## Starting now... ##########" >> $log_file_with_date
    echo "#####################################" >> $log_file_with_date
    nohup python $start_dir/manage.py runserver 0:$port >> $log_file_with_date &
    echo "#########################################################" >> $log_file_with_date
    echo "Success to start! You can check logs in ./logs/$log_file" >> $log_file_with_date
    echo "#########################################################" >> $log_file_with_date
    echo "########## Starting now... ##########"
    echo "[INFO] Success to start! You can check logs in ./logs/$log_file"
    echo "[INFO] Please press Enter Key and Do your job."
fi

 

 

 

3. stop_stop_djangoserver_ver1.0.0.sh

#!/bin/bash
source ./variables.sh
date_front=`date |awk '{print$1$2$3}'`

echo "###############" >> $log_file_with_date
echo "Stopping now..." >> $log_file_with_date
echo "###############" >> $log_file_with_date
echo "[INFO] Stopping now..."

arr_stop_target_list_full_info=$(ps -ef |grep "$start_dir/manage.py runserver 0:$port" |grep -v "grep $start_dir/manage.py runserver 0:$port")
arr_stop_target_list=$(ps -ef |grep "$start_dir/manage.py runserver 0:$port" |grep -v "grep $start_dir/manage.py runserver 0:$port" |awk '{print $2}')
for target_stop in ${arr_stop_target_list};do
        kill -9 $target_stop
done

echo "###############" >> $log_file_with_date
echo "Success to stop" >> $log_file_with_date
echo "###############" >> $log_file_with_date
echo "[INFO] Success to stop!"

 

 

 

4. 위 파일들을 프로젝트 디렉토리에 (ex. saja_site/) 넣어두고 사용할 것을 권장, 또한 tar.gz 파일로 압축하여 첨부해두었으니 그 파일을 참조하여 확인할 수 있다.

django_manager_ver1.0.0.tar.gz
0.01MB

+ Recent posts