-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·110 lines (94 loc) · 3.28 KB
/
deploy.sh
File metadata and controls
executable file
·110 lines (94 loc) · 3.28 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
#!/bin/bash
# Deployment script for RSC Platform (Gunicorn + Nginx)
set -e # Exit on error
echo "=========================================="
echo "RSC Platform Deployment Script"
echo "=========================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if running as root
if [ "$EUID" -eq 0 ]; then
echo -e "${RED}Please do not run as root. Run as your regular user.${NC}"
exit 1
fi
# Project directory
PROJECT_DIR="/var/www/html/rsc-site"
VENV_DIR="$PROJECT_DIR/venv"
echo -e "${YELLOW}Step 1: Checking environment file...${NC}"
if [ ! -f "$PROJECT_DIR/.env" ]; then
echo -e "${RED}Error: .env file not found!${NC}"
echo "Please create .env file with required settings."
echo "See DEPLOYMENT.md for details."
exit 1
fi
echo -e "${GREEN}✓ .env file found${NC}"
echo ""
echo -e "${YELLOW}Step 2: Activating virtual environment...${NC}"
if [ ! -d "$VENV_DIR" ]; then
echo -e "${RED}Error: Virtual environment not found at $VENV_DIR${NC}"
echo "Create it with: python3 -m venv $VENV_DIR"
exit 1
fi
source "$VENV_DIR/bin/activate"
echo -e "${GREEN}✓ Virtual environment activated${NC}"
echo ""
echo -e "${YELLOW}Step 3: Installing Python dependencies...${NC}"
pip install -r "$PROJECT_DIR/requirements.txt" --quiet
echo -e "${GREEN}✓ Dependencies installed${NC}"
echo ""
# Use production settings for all management commands
export DJANGO_SETTINGS_MODULE=rsc_platform.settings.production
echo -e "${YELLOW}Step 4: Ensuring log directory exists...${NC}"
sudo mkdir -p /var/log/rsc_platform
sudo chown www-data:www-data /var/log/rsc_platform
echo -e "${GREEN}✓ Log directory ready${NC}"
echo ""
echo -e "${YELLOW}Step 5: Running database migrations...${NC}"
python3 "$PROJECT_DIR/manage.py" migrate --noinput
echo -e "${GREEN}✓ Migrations complete${NC}"
echo ""
echo -e "${YELLOW}Step 6: Collecting static files...${NC}"
python3 "$PROJECT_DIR/manage.py" collectstatic --noinput
echo -e "${GREEN}✓ Static files collected${NC}"
echo ""
echo -e "${YELLOW}Step 7: Setting permissions...${NC}"
sudo chown -R www-data:www-data "$PROJECT_DIR"
sudo chmod -R 755 "$PROJECT_DIR"
sudo chmod -R 775 "$PROJECT_DIR/media"
sudo chmod -R 775 "$PROJECT_DIR/staticfiles"
sudo chmod -R 775 "$PROJECT_DIR/static"
sudo chmod 600 "$PROJECT_DIR/.env"
echo -e "${GREEN}✓ Permissions set${NC}"
echo ""
echo -e "${YELLOW}Step 8: Testing Nginx configuration...${NC}"
sudo nginx -t
echo -e "${GREEN}✓ Nginx configuration valid${NC}"
echo ""
echo -e "${YELLOW}Step 9: Restarting Gunicorn and Nginx...${NC}"
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
sudo systemctl restart nginx
echo -e "${GREEN}✓ Gunicorn and Nginx restarted${NC}"
echo ""
echo -e "${GREEN}=========================================="
echo "Deployment Complete!"
echo "==========================================${NC}"
echo ""
echo "Your site should now be live."
echo ""
echo "To check service status:"
echo " sudo systemctl status gunicorn"
echo " sudo systemctl status nginx"
echo ""
echo "To view logs:"
echo " sudo journalctl -u gunicorn -f"
echo " sudo tail -f /var/log/nginx/rsc_platform_error.log"
echo " sudo tail -f /var/log/rsc_platform/django.log"
echo ""
echo "To access Django admin:"
echo " https://your-domain.com/admin/"
echo ""