0

Now I am using this script to restart my process:

#!/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

the script killed the old process and start a new one. But when I execute the script remote in GitHub Actions, shows the log like this:

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!

finally the script going timeout!!! why the script did not exit automatic? I already make the process in background. What should I do to avoid this problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.