Home > Enterprise >  How to run shell command after gunicorn service? this is for docker enterypoint.sh file
How to run shell command after gunicorn service? this is for docker enterypoint.sh file

Time:02-10

Below is my docker enterypoint.sh file code

#!/bin/bash
set -e

python3 test1.py

gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600

node /home/test2.js

I want to run test2.js nodejs app after gunicorn service starts because test2.js required to connect with localhost:8000. Please help me with a solution for this

CodePudding user response:

By default, the next line is only executed after the previous one, but maybe the command ends before the port is active, so you can use a while to check that

#!/bin/bash
set -e

python3 test1.py

gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600
#
check=1
#
while [ $check -eq 1 ]
do
  echo "Testing"
  test=$(netstat -nlt | grep "0.0.0.0:8000" &> /dev/null)
  check=$?
  sleep 2
done

node /home/test2.js

CodePudding user response:

Try this :

#!/bin/bash
set -e

python3 test1.py

# wait 10 seconds, then run test2.js
{ sleep 10; node /home/test2.js; } &

gunicorn -b 0.0.0.0:8000 "app:app" --workers=1 --threads=10 --timeout=3600

  • Related