Deploy a Netflix-like web server using Nginx on an Ubuntu Os with bash script running Lab
Centos /Ubuntu/Alpine/redhat
Step 1 ) CentOS (or) Ubuntu
#!/bin/bash
# Determine the OS type
OS_TYPE=$(head -n 1 /etc/os-release | awk -F "=" '{ print $2 }' | sed 's/"//g')
APT="Ubuntu"
YUM="CentOS"
Step 2) Check Linux Os Type and Disk usage
DISK_USAGE=$(df -hT)
# Check the OS type and display disk usage
if [ "$OS_TYPE" = "$APT" ] || [ "$OS_TYPE" = "$YUM" ]; then
echo "$DISK_USAGE"
fi
# Confirm the installation
echo "Confirm the installation -> yes"
read -r confirm
Step 3) Install nginx on Ubuntu OS (Default Website)
# Install nginx based on the OS type
if [ "$confirm" = "yes" ] || [ "$confirm" = "Yes" ] || [ "$confirm" = "YES" ];
then
if [ "$OS_TYPE" = "Ubuntu" ]; then
sudo apt update -y && sudo apt install nginx -y
elif [ "$OS_TYPE" = "CentOS" ]; then
sudo yum update -y && sudo yum install nginx -y
else
echo "Operating System is not supported"
exit 1
fi
else
exit 1
fi
Step 4 ) Start nginx service
# Start nginx service
sudo systemctl start nginx
Step 5) Backup and Deployment
# Backup and Deployment
backup_dest="/tmp/backup"
prod_path="/var/www/html/"
prod_source="/home/hpc/bash-tutorial/Netflix_Home_Page_Using_HTML_And_CSS"
source_code="https://github.com/Alok-
2002/Netflix_Home_Page_Using_HTML_And_CSS.git"
website_folder="Netflix_Home_Page_Using_HTML_And_CSS"
cd /home/hpc/bash-tutorial || exit
# Check if the folder already exists
if [ -d "$website_folder" ]; then
echo "Folder already exists"
else
git clone "$source_code"
fi
Step 6) Backup the existing file and Deploy new file
# Backup the existing production files
sudo cp -r "$prod_path"/* "$backup_dest"
# Deploy the new files
sudo cp -r "$prod_source"/* "$prod_path"
Step 7) Restart Nginx Service and running
# Restart the Nginx service
sudo systemctl restart nginx
sudo systemctl status | grep -i running
Step 8) Bash Script Running
Checking ip
Testing Netflix nginx ( Lab Done)