AI - Building APP in lightSAIL AWS instance : Automatic background app start

 Run these on the Lightsail server.

1. Go to app folder

cd /var/www/tradingapp
ls -la

2. Recreate venv

python3 -m venv venv
source venv/bin/activate

3. Install packages

If you have requirements.txt:

pip install --upgrade pip
pip install -r requirements.txt

If no requirements.txt, install basics:

pip install --upgrade pip
pip install fastapi uvicorn flask openai python-dotenv pandas requests

4. Recreate start.sh

nano start.sh

Paste this:

#!/bin/bash
cd /var/www/tradingapp
source venv/bin/activate
python3 webapp/app.py

Save in nano:

Ctrl + O
Enter
Ctrl + X

Make executable:

chmod +x start.sh

5. Test manually

./start.sh

If app starts, stop with:

Ctrl + C

6. Start in background

nohup ./start.sh > /tmp/tradingapp.log 2>&1 &

Check:

ps -ef | grep app.py
tail -50 /tmp/tradingapp.log

7. Important: prevent Git deleting these again

Add to .gitignore:

nano .gitignore

Add:

venv/
start.sh
.env
*.log
__pycache__/

Then:

git status

venv should never be committed. start.sh can be committed only if you want the script version-controlled.



Recreate start.sh exactly like this.

cd /var/www/tradingapp
nano start.sh

Paste:

#!/bin/bash

cd /var/www/tradingapp/webapp

source ../venv/bin/activate

python3 -m py_compile app.py

sudo systemctl restart vikalp-income

sudo systemctl status vikalp-income

Save:

Ctrl + O
Enter
Ctrl + X

Make executable:

chmod +x /var/www/tradingapp/start.sh

Run:

./start.sh

Also check your service exists:

sudo systemctl status vikalp-income

If it says service not found, then recreate the vikalp-income.service.

Comments

Popular posts from this blog

Prediction model using Python

Basics of Artificial Intelligence

AI Architecture