-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·94 lines (78 loc) · 3.06 KB
/
deploy.sh
File metadata and controls
executable file
·94 lines (78 loc) · 3.06 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
#!/bin/bash
# --- Configuration Variables ---
IMAGE_NAME="imvickykumar999/multiuser-livestream:latest"
CONTAINER_NAME="livestream-app"
PORT="8000"
ADMIN_USER="admin"
ADMIN_EMAIL="admin@example.com"
ADMIN_PASS="changethispassword" # <--- Set your desired password here
echo "--- Starting 24x7 Stream Deployment ---"
# 0. System Check & Auto-Installation (The "Option 2" Fix)
echo "[0/6] Checking system requirements..."
# Check for curl (needed to install Docker)
if ! command -v curl &> /dev/null; then
echo " > Curl not found. Installing curl..."
sudo apt-get update && sudo apt-get install -y curl
fi
# Check for Docker
if ! command -v docker &> /dev/null; then
echo " > 🐳 Docker not found. Installing Docker..."
curl -fsSL https://get.docker.com | sh
echo " > Starting Docker service..."
sudo systemctl start docker
sudo systemctl enable docker
# Add current user to docker group to avoid permission issues
echo " > Adding user to Docker group..."
sudo usermod -aG docker $USER
else
echo " > ✅ Docker is already installed."
fi
# 1. Pull the Docker Image
echo "[1/6] Pulling latest image..."
# We use sudo here in case the user isn't in the docker group yet
sudo docker pull $IMAGE_NAME
# 2. Stop and remove existing container if it exists
if [ "$(sudo docker ps -aq -f name=$CONTAINER_NAME)" ]; then
echo "[2/6] Stopping and removing existing container..."
sudo docker stop $CONTAINER_NAME
sudo docker rm $CONTAINER_NAME
else
echo "[2/6] No existing container found. Skipping removal."
fi
# 3. Create Required Directories
echo "[3/6] Creating directories..."
mkdir -p media logs
# 4. Set Proper Permissions
# The container user (UID 1000) needs write access to these folders
echo "[4/6] Setting permissions for media/ and logs/..."
sudo chown -R 1000:1000 media/ logs/
# 5. Run the Container
echo "[5/6] Starting container..."
sudo docker run -d --name $CONTAINER_NAME \
--restart unless-stopped \
-p 0.0.0.0:$PORT:$PORT \
-v "$(pwd)/media:/app/media" \
-v "$(pwd)/logs:/app/logs" \
$IMAGE_NAME
echo "Container started successfully."
# 6. Create Super User with Password
echo "--- Admin Setup ---"
echo "[6/6] Creating superuser '$ADMIN_USER'..."
# We pass the password as an environment variable to the container command
sudo docker exec \
-e DJANGO_SUPERUSER_PASSWORD=$ADMIN_PASS \
$CONTAINER_NAME \
python manage.py createsuperuser \
--username $ADMIN_USER \
--email $ADMIN_EMAIL \
--noinput || echo " > Note: User '$ADMIN_USER' likely already exists."
echo "---------------------------------------------------"
echo "✅ Deployment Complete!"
echo "---------------------------------------------------"
echo "🌐 App URL: http://localhost:$PORT (or http://<your-server-ip>:$PORT)"
echo "👤 Username: $ADMIN_USER"
echo "🔑 Password: $ADMIN_PASS"
echo "---------------------------------------------------"
echo "To change the password later, run:"
echo "sudo docker exec -it $CONTAINER_NAME python manage.py changepassword $ADMIN_USER"
echo "---------------------------------------------------"