Home > database >  How to start fastapi ,react, node server using shell script file
How to start fastapi ,react, node server using shell script file

Time:06-17

I need to run many commands one by one to start my project instead of that i tried to put commands on shell script file

server.sh

#!/bin/bash
sudo systemctl start elasticsearch.service
sudo systemctl start kibana.service
cd fastapi
uvicorn main:app --reload --port 8000
cd ..
cd reactjs
npm i 
npm start
cd ..
cd node
npm i 
npm run dev

These are commands I put it in a .sh file, now problem is after uvicorn main:app --reload --port 8000 this command sh files failed to execute rest of the commands.

how to resolve this using .sh file or yaml file

CodePudding user response:

You must run in background the three main scripts in your code:

uvicorn main:app --reload --port 8000 &

npm start &

npm run dev &

That & is used after a command to run this one in background, so the script will not stop in the first command (avicorn) and it will follow with the code.

And because of those commands will generate an output in the terminal (in the case you are running them from it) that output can be confused, so I would recommend redirect the output to a file for every command you run in background.

Your code could be like this:

#!/bin/bash

sudo systemctl start elasticsearch.service
sudo systemctl start kibana.service
cd fastapi
uvicorn main:app --reload --port 8000 > uvicorn.log &
cd ../reactjs
npm i
npm start > npmstart.log &
cd ../node
npm i 
npm run dev > npmdev.log &
  • Related