-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart-server-dev.sh
More file actions
executable file
·114 lines (98 loc) · 3.73 KB
/
Copy pathstart-server-dev.sh
File metadata and controls
executable file
·114 lines (98 loc) · 3.73 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
# start-server-dev.sh - Development server for worktree
# Starts both Django backend and Vite frontend in development mode
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get the script directory (worktree root)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$SCRIPT_DIR/pkpdapp"
FRONTEND_DIR="$SCRIPT_DIR/frontend-v2"
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Starting PKPD App Development Server${NC}"
echo -e "${BLUE}Worktree: $(basename $SCRIPT_DIR)${NC}"
echo -e "${BLUE}========================================${NC}"
# Function to cleanup background processes on exit
cleanup() {
echo -e "\n${YELLOW}Shutting down servers...${NC}"
kill $(jobs -p) 2>/dev/null || true
wait 2>/dev/null || true
echo -e "${GREEN}Cleanup complete${NC}"
}
trap cleanup EXIT INT TERM
# Check if virtual environment exists
if [ ! -d "$SCRIPT_DIR/venv" ]; then
echo -e "${YELLOW}Virtual environment not found. Creating one...${NC}"
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
else
source venv/bin/activate
fi
# Backend setup
echo -e "\n${GREEN}[Backend]${NC} Setting up Django..."
cd "$BACKEND_DIR"
# Run migrations
echo -e "${GREEN}[Backend]${NC} Running migrations..."
python manage.py migrate --no-input
# Create test users
echo -e "${GREEN}[Backend]${NC} Creating test users (password matches username)..."
python manage.py shell -c "
from django.contrib.auth import get_user_model;
from pkpdapp.models import Profile;
User = get_user_model();
test_users = [
('test', 'test@example.com', 'Test', 'User', 'Clinical Pharmacology'),
('alice', 'alice@example.com', 'Alice', 'Anderson', 'Pharmacometrics'),
('bob', 'bob@example.com', 'Bob', 'Baker', 'Drug Metabolism'),
];
for username, email, first_name, last_name, department in test_users:
user, created = User.objects.get_or_create(
username=username,
defaults={'email': email}
);
user.email = email;
user.first_name = first_name;
user.last_name = last_name;
user.is_staff = False;
user.is_superuser = False;
user.set_password(username);
user.save();
profile, _ = Profile.objects.get_or_create(user=user);
profile.department = department;
profile.save();
print(('Created ' if created else 'Updated ') + username);
" 2>/dev/null || echo "Note: Could not create test users (may already exist)"
# Start Django development server in background
echo -e "${GREEN}[Backend]${NC} Starting Django dev server on http://127.0.0.1:8000..."
python manage.py runserver 0.0.0.0:8000 &
BACKEND_PID=$!
# Frontend setup
echo -e "\n${BLUE}[Frontend]${NC} Setting up Vite..."
cd "$FRONTEND_DIR"
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}[Frontend]${NC} node_modules not found. Installing dependencies..."
yarn install
fi
# Start Vite dev server in background
echo -e "${BLUE}[Frontend]${NC} Starting Vite dev server on http://127.0.0.1:3000..."
yarn start &
FRONTEND_PID=$!
# Wait a bit for servers to start
sleep 3
echo -e "\n${GREEN}========================================${NC}"
echo -e "${GREEN}✓ Development servers started!${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "${BLUE}Frontend:${NC} http://127.0.0.1:3000"
echo -e "${GREEN}Backend:${NC} http://127.0.0.1:8000"
echo -e "${GREEN}Admin:${NC} http://127.0.0.1:8000/admin"
echo -e "\n${YELLOW}Test Logins:${NC} test/test, alice/alice, bob/bob (password = username)"
echo -e "\n${YELLOW}Press Ctrl+C to stop all servers${NC}"
echo -e "${GREEN}========================================${NC}\n"
# Wait for background processes
wait