이제 이 스크립트를 사용하여 프로세스를 다시 시작합니다.
#!/usr/bin/env bash
set -u
set -e
set -x
#
# const define area
#
PROGRAM_NAME="schedulespider.py"
CELERY_PROGRAM_NAME="celery"
PYTHON_BIN_PATH="/usr/bin/python3"
#
# stop celery process
#
ps auxww | grep celery | awk '{print $2}' | xargs kill -9
sleep 5s
ps auxww | grep schedulespider | awk '{print $2}' | xargs kill -9
#
# stop python process
#
sleep 5s
#
# start process
#
count=`ps -ef | grep ${PROGRAM_NAME} | grep -v "grep" | wc -l`
if [[ ${count} -lt 1 ]]; then
# /usr/bin/python3 -m pip install --upgrade pip
# pip3 install -r requirements.txt
export PYTHONIOENCODING=utf-8
nohup ${PYTHON_BIN_PATH} schedulespider.py > /dev/null &
#https://stackoverflow.com/questions/36651680/click-will-abort-further-execution-because-python-3-was-configured-to-use-ascii
export LC_ALL=en_US.utf-8 \
&& export LANG=en_US.utf-8 \
&& nohup celery -A dolphin.tasks.tasks worker \
--loglevel=INFO -n worker1 -Q editor_pick_and_diff_pull --concurrency 1 &
export LC_ALL=en_US.utf-8 \
&& export LANG=en_US.utf-8 \
&& nohup celery -A dolphin.tasks.tasks worker \
--loglevel=INFO -n worker2 -Q non_editor_pick_and_diff_pull --concurrency 1 &
export LC_ALL=en_US.utf-8 \
&& export LANG=en_US.utf-8 \
&& nohup celery -A dolphin.tasks.tasks worker \
--loglevel=INFO -n worker3 -Q non_editor_pick_and_non_diff_pull --concurrency 1 &
sleep 3
else
echo "unable to start app, process already exists!"
fi
이 스크립트는 이전 프로세스를 종료하고 새 프로세스를 시작합니다. 그러나 GitHub Actions에서 원격으로 스크립트를 실행하면 다음 로그가 표시됩니다.
cd /opt/apps/pydolphin
. /opt/apps/pydolphin/restart.sh
======END======
err: +/opt/apps/pydolphin/restart.sh:16> PROGRAM_NAME=schedulespider.py
err: +/opt/apps/pydolphin/restart.sh:17> CELERY_PROGRAM_NAME=celery
err: +/opt/apps/pydolphin/restart.sh:18> PYTHON_BIN_PATH=/usr/bin/python3
err: +/opt/apps/pydolphin/restart.sh:23> ps auxww
err: +/opt/apps/pydolphin/restart.sh:23> grep celery
err: +/opt/apps/pydolphin/restart.sh:23> awk '{print $2}'
err: +/opt/apps/pydolphin/restart.sh:23> xargs kill -9
err: +/opt/apps/pydolphin/restart.sh:25> sleep 5s
err: +/opt/apps/pydolphin/restart.sh:31> PID=+/opt/apps/pydolphin/restart.sh:31> ps -ef
err: +/opt/apps/pydolphin/restart.sh:31> PID=+/opt/apps/pydolphin/restart.sh:31> grep -w schedulespider.py
err: +/opt/apps/pydolphin/restart.sh:31> PID=+/opt/apps/pydolphin/restart.sh:31> grep -v grep
err: +/opt/apps/pydolphin/restart.sh:31> PID=+/opt/apps/pydolphin/restart.sh:31> cut -c 9-15
err: +/opt/apps/pydolphin/restart.sh:31> PID=' 9772 '
err: +/opt/apps/pydolphin/restart.sh:32> [ -z ' 9772 ' ']'
err: +/opt/apps/pydolphin/restart.sh:35> array=( ' 9772 ' )
err: +/opt/apps/pydolphin/restart.sh:36> var= 9772
err: +/opt/apps/pydolphin/restart.sh:38> single_pid=+/opt/apps/pydolphin/restart.sh:38> echo ' 9772 '
err: +/opt/apps/pydolphin/restart.sh:38> single_pid=+/opt/apps/pydolphin/restart.sh:38> awk 'gsub(/^ *| *$/,"")'
err: +/opt/apps/pydolphin/restart.sh:38> single_pid=9772
err: +/opt/apps/pydolphin/restart.sh:39> [[ 9772 -gt 1 ]]
err: +/opt/apps/pydolphin/restart.sh:40> kill -15 9772
err: +/opt/apps/pydolphin/restart.sh:47> sleep 5s
err: +/opt/apps/pydolphin/restart.sh:52> count=+/opt/apps/pydolphin/restart.sh:52> ps -ef
err: +/opt/apps/pydolphin/restart.sh:52> count=+/opt/apps/pydolphin/restart.sh:52> grep schedulespider.py
err: +/opt/apps/pydolphin/restart.sh:52> count=+/opt/apps/pydolphin/restart.sh:52> grep -v grep
err: +/opt/apps/pydolphin/restart.sh:52> count=+/opt/apps/pydolphin/restart.sh:52> wc -l
err: +/opt/apps/pydolphin/restart.sh:52> count=0
err: +/opt/apps/pydolphin/restart.sh:53> [[ 0 -lt 1 ]]
err: +/opt/apps/pydolphin/restart.sh:57> export 'PYTHONIOENCODING=utf-8'
err: +/opt/apps/pydolphin/restart.sh:61> export 'LC_ALL=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:62> export 'LANG=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:59> nohup /usr/bin/python3 schedulespider.py
err: +/opt/apps/pydolphin/restart.sh:66> export 'LC_ALL=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:67> export 'LANG=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:63> nohup celery -A dolphin.tasks.tasks worker '--loglevel=INFO' -n worker1 -Q editor_pick_and_diff_pull --concurrency 1
err: +/opt/apps/pydolphin/restart.sh:71> export 'LC_ALL=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:72> export 'LANG=en_US.utf-8'
err: +/opt/apps/pydolphin/restart.sh:68> nohup celery -A dolphin.tasks.tasks worker '--loglevel=INFO' -n worker2 -Q non_editor_pick_and_diff_pull --concurrency 1
err: +/opt/apps/pydolphin/restart.sh:73> nohup celery -A dolphin.tasks.tasks worker '--loglevel=INFO' -n worker3 -Q non_editor_pick_and_non_diff_pull --concurrency 1
err: +/opt/apps/pydolphin/restart.sh:81> sleep 3
out:
out: -------------- celery@worker3 v5.1.2 (sun-harmonics)
out: --- ***** -----
out: -- ******* ---- Linux-3.10.0-1127.19.1.el7.x86_64-x86_64-with-centos-7.9.2009-Core 2021-07-19 21:12:01
out: - *** --- * ---
out: - ** ---------- [config]
out: - ** ---------- .> app: tasks:0x7fa484116518
out: - ** ---------- .> transport: redis://:**@121.196.199.223:6379/5
out: - ** ---------- .> results: redis://:**@121.196.199.223:6379/5
out: - *** --- * --- .> concurrency: 1 (prefork)
out: -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
out: --- ***** -----
out: -------------- [queues]
out: .> non_editor_pick_and_non_diff_pull exchange=non_editor_pick_and_non_diff_pull(direct) key=non_editor_pick_and_non_diff_pull
out:
out:
out: [tasks]
out: . pydolphin.dolphin.tasks.tasks
out:
out:
out: -------------- celery@worker1 v5.1.2 (sun-harmonics)
out: --- ***** -----
out: -- ******* ---- Linux-3.10.0-1127.19.1.el7.x86_64-x86_64-with-centos-7.9.2009-Core 2021-07-19 21:12:01
out: - *** --- * ---
out: - ** ---------- [config]
out: - ** ---------- .> app: tasks:0x7f4f1efa40b8
out: - ** ---------- .> transport: redis://:**@121.196.199.223:6379/5
out: - ** ---------- .> results: redis://:**@121.196.199.223:6379/5
out: - *** --- * --- .> concurrency: 1 (prefork)
out: -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
out: --- ***** -----
out: -------------- [queues]
out: .> editor_pick_and_diff_pull exchange=editor_pick_and_diff_pull(direct) key=editor_pick_and_diff_pull
out:
out:
out: [tasks]
out: . pydolphin.dolphin.tasks.tasks
out:
out:
out: -------------- celery@worker2 v5.1.2 (sun-harmonics)
out: --- ***** -----
out: -- ******* ---- Linux-3.10.0-1127.19.1.el7.x86_64-x86_64-with-centos-7.9.2009-Core 2021-07-19 21:12:01
out: - *** --- * ---
out: - ** ---------- [config]
out: - ** ---------- .> app: tasks:0x7fec552640b8
out: - ** ---------- .> transport: redis://:**@121.196.199.223:6379/5
out: - ** ---------- .> results: redis://:**@121.196.199.223:6379/5
out: - *** --- * --- .> concurrency: 1 (prefork)
out: -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
out: --- ***** -----
out: -------------- [queues]
out: .> non_editor_pick_and_diff_pull exchange=non_editor_pick_and_diff_pull(direct) key=non_editor_pick_and_diff_pull
out:
out:
out: [tasks]
out: . pydolphin.dolphin.tasks.tasks
out:
2021/07/19 13:21:45 Error: command timeout
err: Run Command Timeout!
마침내 스크립트 시간이 초과되었습니다! ! ! 스크립트가 자동으로 종료되지 않는 이유는 무엇입니까? 백그라운드에서 프로세스가 진행되고 있습니다. 이 문제를 피하려면 어떻게 해야 합니까?
답변1
비슷한 문제가 있습니다. 출력뿐만 아니라 dev\null에 입력을 전송하여 문제를 해결했습니다. 귀하의 경우:
nohup ${PYTHON_BIN_PATH} schedulespider.py < /dev/null & > /dev/null &