<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ritik Saxena</title>
    <description>The latest articles on DEV Community by Ritik Saxena (@ritik_saxena).</description>
    <link>https://dev.to/ritik_saxena</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1544981%2F07454d52-ed36-4d94-a24b-853fce7cbb95.png</url>
      <title>DEV Community: Ritik Saxena</title>
      <link>https://dev.to/ritik_saxena</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ritik_saxena"/>
    <language>en</language>
    <item>
      <title>Streamlining Webpage Deployment on Multi-VMs Using Bash Scripts</title>
      <dc:creator>Ritik Saxena</dc:creator>
      <pubDate>Wed, 29 May 2024 22:17:42 +0000</pubDate>
      <link>https://dev.to/ritik_saxena/streamlining-webpage-deployment-on-multi-vms-using-bash-scripts-2ml2</link>
      <guid>https://dev.to/ritik_saxena/streamlining-webpage-deployment-on-multi-vms-using-bash-scripts-2ml2</guid>
      <description>&lt;p&gt;Hey! 👋 Today, I'll guide you through the deployment of a static website on a Linux server using the power of Bash scripting. But, before diving in, let's ensure we have the essentials in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Install Git&lt;/li&gt;
&lt;li&gt;Install Vagrant&lt;/li&gt;
&lt;li&gt;Install Virtualbox&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Creating a Multi-VM Vagrantfile 📄
&lt;/h2&gt;

&lt;p&gt;We need to create a Vagrantfile that will allow us to create multiple VMs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Git Bash terminal and create a Vagrantfile using the command &lt;code&gt;vim Vagrantfile&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy and paste the below code into the Vagrantfile
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vagrant.configure("2") do |config|

  # VM configurations for Ubuntu
  config.vm.define "web01" do |web01|
    web01.vm.box = "ubuntu/bionic64"
    web01.vm.network "private_network", ip: "192.168.56.41"
    web01.vm.hostname = "web01"

    config.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
    end

    config.vm.provision "shell", inline: &amp;lt;&amp;lt;-SHELL
      mkdir -p /var/log/barista_cafe_logs
      sudo chown vagrant:vagrant /var/log/barista_cafe_logs/
  SHELL

  end

  # Configuration for CentOS 9 VM
  config.vm.define "web02" do |web02|
    web02.vm.box = "eurolinux-vagrant/centos-stream-9"
    web02.vm.network "private_network", ip: "192.168.56.42"
    web02.vm.hostname = "web02"

    config.vm.provision "shell", inline: &amp;lt;&amp;lt;-SHELL
      mkdir -p /var/log/barista_cafe_logs
      sudo chown vagrant:vagrant /var/log/barista_cafe_logs/
  SHELL

  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, we have specified the configurations of two VMs, &lt;em&gt;Ubuntu OS&lt;/em&gt; (hostname as 'web01') and CentOS 9 (hostname as 'web02') with specified Memory and IPv4 addresses.&lt;/p&gt;

&lt;p&gt;Inline shell provisioning is used to create a barista_cafe_logs folder at location '&lt;strong&gt;/var/log&lt;/strong&gt;' for storing the website setup and teardown log files. Ownership is set for the &lt;strong&gt;vagrant&lt;/strong&gt; user (default user) so that log files for setup and teardown can be created without any restriction.&lt;/p&gt;

&lt;p&gt;Note that we have given Ubuntu OS and CentOS the same identifier name as the hostname. In &lt;code&gt;config.vm.define "web01"&lt;/code&gt;, web01 is the identifier name/ VM name that vagrant uses to identify for which VM we want to execute any command, while in &lt;code&gt;web01.vm.hostname = "web01"&lt;/code&gt;, we have set a hostname for the VM to identify the device within a local network.&lt;/p&gt;




&lt;h2&gt;
  
  
  Logging in to the VM 💻
&lt;/h2&gt;

&lt;p&gt;Navigate to the folder where we have created the Vagrantfile using the cd command.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Launching the VM:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Command: &lt;code&gt;vagrant up&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj09l3yd5g681xpc1h6lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj09l3yd5g681xpc1h6lg.png" alt="vagrant up" width="725" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; &lt;code&gt;vagrant up&lt;/code&gt; command will create all the VMs mentioned in the Vagrantfile at once. We can also create a specific VM, and then we can use a command &lt;code&gt;vagrant up vm_name&lt;/code&gt; e.g., &lt;code&gt;vagrant up web01&lt;/code&gt; will create only an Ubuntu VM (here, web01 is the identifier name).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Check VM status:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Command: &lt;code&gt;vagrant status&lt;/code&gt; or &lt;code&gt;vagrant global-status&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34rlm6ne82qdhjh51uo0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F34rlm6ne82qdhjh51uo0.png" alt="Check VM status" width="634" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vagrant status&lt;/code&gt; will give the status of VMs of Vagrantfile in the current location while &lt;code&gt;vagrant global-status&lt;/code&gt; will give the status of all the VMs in the system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Login to the VM:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Ubuntu OS: &lt;code&gt;vagrant ssh web01&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;For CentOS: &lt;code&gt;vagrant ssh web02&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Create bash files in Synced Directory 📁📝
&lt;/h2&gt;

&lt;p&gt;We will create two bash files, &lt;strong&gt;webpage_setup.sh&lt;/strong&gt;, and &lt;strong&gt;webpage_teardown.sh&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The extension of a bash file is .sh&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are two ways to proceed further:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Way1: Create a bash file in the local machine itself&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create bash files in a local machine at the same location where Vagrantfile is located&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypcfn5ky9r6k83f66mho.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypcfn5ky9r6k83f66mho.png" alt="create bash file" width="790" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Way2: Create a bash file in the VM directly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create bash files at location /vagrant/&lt;/p&gt;

&lt;p&gt;Navigate to location /vagrant using the command &lt;code&gt;cd /vagrant/&lt;/code&gt; and create a bash file using the command &lt;code&gt;touch webpage_setup.sh&lt;/code&gt; and &lt;code&gt;touch webpage_teardown.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhtzhltr06mcdzvzj29ed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhtzhltr06mcdzvzj29ed.png" alt="create bash file" width="441" height="93"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use command &lt;code&gt;ls&lt;/code&gt; to see the files and folders in Linux&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fah41voyaywok7d9kovf3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fah41voyaywok7d9kovf3.png" alt="list command" width="572" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; The directory where Vagrantfile exists in our local machine and the directory /vagrant in VM are synced together. This means that if we make changes to the same location on our local machine, we can see the changes in the /vagrant directory in the VM as well.&lt;/p&gt;




&lt;h2&gt;
  
  
  Writing automation bash script 👨‍💻
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In Windows/MacOS, use any Code Editor like VSCode, Sublime Text, XCode, etc.&lt;/p&gt;

&lt;p&gt;In Linux/Unix, navigate using cd /vagrant and edit using a command vim webpage_setup.sh&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;webpage_setup.sh
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Function to log messages to deploy.log file
log() {
        message="$(date) - $1"
        echo "$message" &amp;gt;&amp;gt; /var/log/barista_cafe_logs/deploy.log
        echo "$message"
}


log "*****Starting deployment*****"


# checking if user is root user or not
log "*****Checking for root user access*****"
if [ $EUID -ne 0 ]
  then
        log "Warning: Current user is not root user. Please run the script as root user or use sudo."
fi


# checking if package manager is yum or apt-get
log "*****Checking for the package manager*****"
if command -v yum &amp;gt;&amp;gt; /dev/null
  then
        packages="httpd unzip wget"
        service="httpd"
        pkg_manager="yum"

        log "$pkg_manager package manager found!!!"
elif command -v apt-get &amp;gt;&amp;gt; /dev/null
  then
        packages="apache2 unzip wget"
        service="apache2"
        pkg_manager="apt-get"

        log "$pkg_manager package manager found!!!"
else
        log "Error: Unsupported package manager"
        exit 1
fi


# installing the packages
log "*****Installing the required package*****"
if ! sudo $pkg_manager install $packages -y
  then
        log "Error: Failed to install packages"
        exit 1
else
        log "Packages installed successfully"
fi


# starting and enabling the web service
log "*****Starting and enabling $service*****"
if ! (sudo systemctl start $service &amp;amp;&amp;amp; sudo systemctl enable $service)
  then
        log "Error: Failed to start and enable the $service"
        exit 1
else
        log "$service started and enabled successfully"

fi


# creating variables
url="https://www.tooplate.com/zip-templates/2137_barista_cafe.zip"
temp_folder="/temp/barista_cafe"
target_folder="/var/www/html"
artifact="2137_barista_cafe"


# creating folder /temp/barista_cafe
log "*****Creating folder $temp_folder*****"
if ! sudo mkdir -p $temp_folder
  then
        log "Error: Failed to create folder $temp_folder"
        exit 1
else
        log "$temp_folder created successfully"
fi


# navigating to the temp folder
log "*****Navigating to the folder $temp_folder*****"
if ! cd $temp_folder
  then
        log "Error: Failed to navigate to $temp_folder"
        exit 1
else
        log "Navigated to $temp_folder"
fi


# downloading the web files
log "*****Downloading the web files*****"
if ! sudo wget $url
  then
        log "Error: Failed to download the web files from url"
        exit 1
else
        log "Downloaded the web files successfully"
fi


# unzipping the downloaded files
log "*****Unzipping the downlaoded files*****"
if ! sudo unzip -o $artifact.zip
  then
        log "Error: Failed to unzip the web files"
        exit 1
else
        log "Unzipped the web files successfully"
fi


# copying the extracted files to /var/www/html
log "*****Copying the extracted files to $target_folder*****"
if ! sudo cp -r $artifact/* $target_folder
  then
        log "Error: Failed to copy the files to $target_folder"
        exit 1
else
        log "Copied the extracted files to $target_folder successfully"
fi


# printing the files at location /var/www/html
log "*****Printing the files at $target_folder*****"
ls $target_folder


# restarting the web service
log "*****Restarting the $service*****"

if ! sudo systemctl restart $service
  then
        log "Error: Failed to restart the $service"
else
        log "Re-started the $service successfully"
fi


log "Successfully deployed the website"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;webpage_teardown.sh
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

log() {
    message="$(date) - $1"
    echo "$message" &amp;gt;&amp;gt; /var/log/barista_cafe_logs/teardown.log
    echo "$message"
}


log "*****Starting teardown...*****"


# checking for root user
log "*****Checking for root user access*****"
if [ $EUID -ne 0 ]
    then
        log "Warning: Warning: Current user is not root user. Please run the script as root user or use sudo."
fi


# checking for package manager
log "*****Checking for package manager*****"
if command -v yum &amp;gt;&amp;gt; /dev/null
    then
        packages="httpd unzip wget"
        service="httpd"
        pkg_manager="yum"

        log "$pkg_manager package manager found!!!"
elif command -v apt-get &amp;gt;&amp;gt; /dev/null
  then
        packages="apache2 unzip wget"
        service="apache2"
        pkg_manager="apt-get"

        log "$pkg_manager package manager found!!!"
else
        log "Error: Unsupported package manager"
        exit 1
fi


# stopping the web-service
log "*****Stopping $service*****"
if ! sudo systemctl stop $service
    then
        log "Error: Unable to stop $service"
else
    log "Successfully stopped $service"
fi


# removing installed packages
log "*****Removing installed packages*****"
if ! sudo $pkg_manager remove $packages -y
    then
        log "Error: Unable to remove packages: $packages"
        exit 1
else
    log "Packages removed successfully"
fi


# creating variables
temp_folder="/temp/barista_cafe"
target_folder="/var/www/html"
artifact="2137_barista_cafe"


# removing downloaded web files
log "*****Deleting web files*****"
if ! sudo rm -rf $temp_folder
    then
        log "Error: Unable to delete folder $temp_folder"
        exit 1
else
    log "Successfully deleted $temp_folder"
fi


# removing web files at location /var/www/html
log "*****Deleting web files*****"
if ! sudo rm -rf $target_folder
    then
        log "Error: Unable to delete folder $target_folder"
        exit 1
else
    log "Successfully deleted $target_folder"
fi


log "Teardown completed successfully!"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Running the bash scripts 💨
&lt;/h2&gt;

&lt;p&gt;Follow the below steps to log in to the VM and navigate to the bash files.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Git bash and navigate to the folder where the Vagrant file resides&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;cd /path_to_vagrantfile/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Log in to any of the VM&lt;br&gt;
&lt;strong&gt;Commands:&lt;/strong&gt;&lt;br&gt;
For Ubuntu OS: &lt;code&gt;vagrant ssh web01&lt;/code&gt;&lt;br&gt;
For CentOS: &lt;code&gt;vagrant ssh web02&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Navigate to the vagrant folder where bash scripts reside&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;cd /vagrant/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nw6lnaz1vts7vk5ivuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nw6lnaz1vts7vk5ivuh.png" alt="navigate to vagrant folder" width="572" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now follow the below steps to execute the scripts:&lt;/p&gt;

&lt;h4&gt;
  
  
  For Website Setup:
&lt;/h4&gt;

&lt;p&gt;We will run webpage_setup.sh file for the webpage setup. Follow the below steps to execute the setup file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Making the webpage_setup.sh bash file executable&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;chmod +x webpage_setup.sh&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running the bash script&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;./webpage_setup.sh&lt;/code&gt;&lt;br&gt;
Wait until the bash script runs completely; if everything goes right, we can see a success message.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmi619gmgtpxohk717h15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmi619gmgtpxohk717h15.png" alt="run bash script" width="607" height="206"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get the IPv4 address&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;ip addr show&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k8yq2axnlttoox1g43e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0k8yq2axnlttoox1g43e.png" alt="get IP address" width="742" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the IP address and paste it into the browser and we can see our website live on our local Linux server&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jog9qt7z6vb9jyafoti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0jog9qt7z6vb9jyafoti.png" alt="website running" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray 👏 ... We have successfully deployed a webpage on a Linux server using a bash script.&lt;/p&gt;

&lt;h4&gt;
  
  
  For Website Teardown:
&lt;/h4&gt;

&lt;p&gt;Once we have successfully deployed the website, we can also destroy the setup if we want. Simply run the webpage_teardown.sh file that we have created previously. The steps are similar to that of setup,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Making the webpage_teardown.sh bash file executable&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;chmod +x webpage_teardown.sh&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running the bash script&lt;br&gt;
&lt;strong&gt;Command:&lt;/strong&gt; &lt;code&gt;./webpage_teardown.sh&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Wait until the bash script runs completely; if everything goes right, we can see a success message for teardown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpiqkromwsliwo6ylsma6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpiqkromwsliwo6ylsma6.png" alt="teardown bash script" width="657" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now cross-check if we can access the website or not by copying the IP address using the command &lt;code&gt;ip addr show&lt;/code&gt; and pasting it into the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxga5i8utbehnmsy3tgn1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxga5i8utbehnmsy3tgn1.png" alt="re-checking website" width="239" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great, we have successfully destroyed the website setup and released all the resources.&lt;/p&gt;

&lt;h4&gt;
  
  
  Destroying the VM:
&lt;/h4&gt;

&lt;p&gt;Now we can destroy the created VM by running a command &lt;code&gt;vagrant destroy&lt;/code&gt;. This command will destroy all the VMs that we have created. In case we want to destroy any specific VM then we can use the VM name to destroy it using the command &lt;code&gt;vagrant destroy vm_name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After deletion, we can check the status of the Vagrant environment and verify that the VMs have been successfully destroyed using the command &lt;code&gt;vagrant status&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvskgf1892p31nosxyg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvskgf1892p31nosxyg1.png" alt="vagrant status" width="638" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq4mpojdg5y0jlad2haf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frq4mpojdg5y0jlad2haf.png" alt="vagrant status" width="634" height="165"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Checking the Logs 📈📋
&lt;/h2&gt;

&lt;p&gt;The logs of setup and teardown will be saved at the location '&lt;strong&gt;/var/logs/barista_cafe_logs/&lt;/strong&gt;' in the files &lt;strong&gt;deploy.log&lt;/strong&gt; and &lt;strong&gt;teardown.log&lt;/strong&gt;. Let's see the logs,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Navigate to the log folder using the command &lt;code&gt;cd /var/logs/barista_cafe_logs/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;ls&lt;/code&gt; command to see the files in this folder&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcruaukvmqjcwy1b9oiru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcruaukvmqjcwy1b9oiru.png" alt="list command" width="501" height="76"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read the log files using the command &lt;code&gt;cat deploy.log&lt;/code&gt; and &lt;code&gt;cat teardown.log&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Logs in deploy.log&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flksrqixava3wjqorzv1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flksrqixava3wjqorzv1u.png" alt="deploy log" width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Logs in teardown.log&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8mq6o6nec6qupqjd06r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8mq6o6nec6qupqjd06r.png" alt="teardown log" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Download the source files: 💾
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Github Repo:&lt;/strong&gt; &lt;a href="https://github.com/Ritik-Saxena/Static-Webpage-Deployment-Bash"&gt;https://github.com/Ritik-Saxena/Static-Webpage-Deployment-Bash&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect with me: 🤝
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/ritik-saxena/"&gt;https://www.linkedin.com/in/ritik-saxena/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fks1vb6ocy9gvx1scxr7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fks1vb6ocy9gvx1scxr7c.png" alt="thank you" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>bash</category>
      <category>deployment</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
