-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_server.sh
More file actions
executable file
·64 lines (53 loc) · 1.67 KB
/
start_server.sh
File metadata and controls
executable file
·64 lines (53 loc) · 1.67 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
#!/bin/bash
# NetBox Server Startup Script
# Requires: Python 3.8+ and virtual environment setup
set -e # Exit on error
echo "=== NetBox Server Startup ==="
echo ""
# Check if virtual environment exists
if [ ! -d ".venv" ]; then
echo "ERROR: Virtual environment not found!"
echo "Please run: ./setup.sh"
exit 1
fi
echo "1. Activating virtual environment..."
source .venv/bin/activate
# Run migrations
echo "2. Running database migrations..."
python manage.py migrate --noinput
# Collect static files
echo "3. Collecting static files..."
python manage.py collectstatic --noinput
# Create superuser if it doesn't exist
echo "4. Creating superuser (if not exists)..."
python manage.py shell -c "
from django.contrib.auth import get_user_model
User = get_user_model()
if not User.objects.filter(username='admin').exists():
u = User.objects.create_superuser('admin', 'admin@example.com', 'admin')
print('Superuser created: username=admin, password=admin')
else:
print('Superuser already exists')
" 2>/dev/null || echo "Superuser creation skipped"
# Create API token for admin user
echo "5. Creating/retrieving API token..."
TOKEN=$(python manage.py shell -c "
from users.models import Token
from django.contrib.auth import get_user_model
User = get_user_model()
u = User.objects.get(username='admin')
t, created = Token.objects.get_or_create(user=u)
print(t.key)
" 2>/dev/null | tail -1)
echo ""
echo "=== Setup Complete ==="
echo ""
echo "API Token: $TOKEN"
echo ""
echo "Starting server on 127.0.0.1:8000..."
echo "Login credentials: username=admin, password=admin"
echo ""
echo "Press Ctrl+C to stop the server"
echo ""
# Start the server
python manage.py runserver 127.0.0.1:8000