-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_start.sh
49 lines (38 loc) · 1.28 KB
/
first_start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# remove old migrations
find . -path "*/content/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/profile_/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/core/migrations/*.py" -not -name "__init__.py" -delete
# remove old DataBase
rm db.sqlite3
# Create virtual environment if not created
if [ ! -d "dna101blog_venv" ]; then
python -m venv dna101blog_venv
fi
# Activate the virtual environment
source dna101blog_venv/bin/activate
# Install requirements packages
pip install -r requirements.txt
# make & apply new migrations
python manage.py makemigrations
python manage.py migrate
# create superuser
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('[email protected]', 'string12')" | python manage.py shell
# Define a function to stop the server processes
function stop_server() {
echo "Stopping server..."
# Find all processes listening on port 8000
pids=$(lsof -i :8000 | awk 'NR>1 {print $2}')
# Kill each process
for pid in $pids; do
echo "Killing process $pid..."
kill $pid
done
exit
}
# Run Django development server
python manage.py runserver &
# Stop the server process on Ctrl+C
trap stop_server SIGINT
# Wait for the server to be stopped
wait