๋ฌธ์ ์ํฉ
nohup node ./node_modules/@vue/cli-service/bin/vue-cli-service serve --port [PORT] &
nohup python manage.py runserver [IP]:[PORT] --settings=main.config.settings.debug
์์ ๋ช
๋ น์ผ๋ก ์ฌ์ดํธ๋ฅผ ์๋ฒ์ ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ์คํํ๊ณ ์๋ค๊ณ ์๊ฐํ๋๋ฐ..
๋๋๋ก ์น์ด ๋ด๋ ค๊ฐ๋ ์ด์๊ฐ ๋ฐ์ํ๋ค.
์์ธ
์๋ชป๋ ๋ช ๋ น์ด๋ก ์ธํด์ ์ฌ์ค ๋ฐฑ๊ทธ๋ผ์ด๋๋ก ์คํ์ด ์ ๋๊ณ ์๋๊ฒ ์๋๊น? ๋ผ๋ ์๊ฐ์ด ๋ค์ด์
์ ๊ทธ๋ฌ๋์ง ์คํํ ๋ ๋ช ๋ น์ ๋ค์ ์ดํด๋ดค๋๋
๋์ธ ๋ ์ฅ๊ณ ์คํ์ & ๋ฅผ ๋ถ์ด์ง ์๊ณ ์คํํด์ ํฐ๋ฏธ๋ ์ธ์ ์ ๋ซ์ผ๋ฉด ํ๋ก์ธ์ค๋ ๊ฐ์ด ์ข ๋ฃ๋์๋ ๊ฒ์ด์๋ค..
nohup python manage.py runserver [IP]:[PORT] --settings=main.config.settings.debug
ํด๊ฒฐ๋ฐฉ๋ฒ
1. ๋์ธ ๋ & ๋ฅผ ์์ง ๋ง์!
nohup python manage.py runserver [IP]:[PORT] --settings=main.config.settings.debug &
2. ํ๋ก์ธ์ค ๋ชจ๋ํฐ ํฌ๋ก ์ก ๋ฑ๋ก
์๋ฒ๊ฐ ์์ ์ฌ๋ถํ
๋๊ฑฐ๋ ๊ทธ๋ด ์๋ ์์ผ๋๊น
ํฌ๋ก ์ก์ผ๋ก 5๋ถ๋ง๋ค ํ๋ก์ธ์ค๊ฐ ๋ด๋ ค๊ฐ ์๋์ง ์ฒดํฌํ๊ณ ๋ด๋ ค๊ฐ ์์ผ๋ฉด ์๋์ผ๋ก ์ฌ๋ ค์ฃผ๋๋ก ์คํฌ๋ฆฝํธ๋ฅผ ๋ฑ๋กํ๋ค.
#!/usr/bin/env bash
# ๋ก๊ทธ ํ์ผ ์์น
LOG_DIRECTORY="/home1/irteamsu/cronjob/logs"
LOG_FILE="$LOG_DIRECTORY/logfile_$(date "+%Y%m%d_%H").log"
# ํ์ธํ ํ๋ก์ธ์ค
PYTHON_PROCESS="/home1/irteamsu/.pyenv/versions/py39/bin/python manage.py runserver [IP]:[PORT] --settings=main.config.settings.debug"
NODE_PROCESS="node ./node_modules/@vue/cli-service/bin/vue-cli-service serve --port [PORT]"
# ์คํํ ๋๋ ํ ๋ฆฌ
PROCESS_DIRECTORY="/home1/irteamsu/variable-comparison"
# ๋ก๊ทธ์ ๋จ๊ธธ ํ์ฌ์๊ฐ
log_current_time() {
current_time=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$current_time] $1" >> "$LOG_FILE"
}
# ํ์ฌ ์๊ฐ์ ์๊ฐ ๋จ์๋ก ๊ตฌํ๊ธฐ
current_hour=$(date "+%H")
# ์ด์ ์๊ฐ๋์ ๋ก๊ทธ ํ์ผ ์ ์ง, ๋๋จธ์ง ๋ก๊ทธ ํ์ผ ์ญ์
for ((hour=0; hour<current_hour; hour++)); do
if [ "$hour" -lt 10 ]; then
rm "$LOG_DIRECTORY/logfile_$(date "+%Y%m%d_0$hour").log" 2>/dev/null
else
rm "$LOG_DIRECTORY/logfile_$(date "+%Y%m%d_$hour").log" 2>/dev/null
fi
done
# python ํ๋ก์ธ์ค ์คํ ์ค์ธ์ง ํ์ธ
if pgrep -f "$PYTHON_PROCESS" >/dev/null; then
log_current_time "Python process is already running."
else
log_current_time "Python process is not running. Starting the process..."
source ~/.bash_profile
cd "$PROCESS_DIRECTORY"
pyenv activate py39
nohup /home1/irteamsu/.pyenv/versions/py39/bin/python manage.py runserver [IP]:[PORT] --settings=main.config.settings.debug > /dev/null 2>&1 &
if pgrep -f "$PYTHON_PROCESS" >/dev/null; then
log_current_time "Python process started."
else
log_current_time "Failed to start Python process."
fi
fi
# node ํ๋ก์ธ์ค ์คํ ์ค์ธ์ง ํ์ธ
if pgrep -f "$NODE_PROCESS" >/dev/null; then
log_current_time "Node.js process is already running."
else
log_current_time "Node.js process is not running. Starting the process..."
cd "$PROCESS_DIRECTORY"
nohup node ./node_modules/@vue/cli-service/bin/vue-cli-service serve --port [PORT] > /dev/null 2>&1 &
if pgrep -f "$NODE_PROCESS" >/dev/null; then
log_current_time "Node.js process started."
else
log_current_time "Failed to start Node.js process."
fi
fi
*/5 * * * * ~/cronjob/background_process_monitor.sh
๊ฒฐ๊ณผ
- ๋ก๊ทธ ํ์ผ ์์ฑ ํ 1์๊ฐ ๋์๋ง ๋ณด๊ด
- ํฌ๊ฒ ์ ์๋ฏธํ ๋ก๊ทธ๊ฐ ์๋๊ธฐ ๋๋ฌธ์ ์ค๋ ๋ณด๊ดํ ํ์๊ฐ ์๋ค.
- ํ๋ก์ธ์ค๊ฐ ์ข ๋ฃ๋ ๊ฒฝ์ฐ ์๋์ผ๋ก ์น์ด ๋ค์ ์ฌ๋ผ์ค๊ฒ ๋๋ค!