Code Monkey home page Code Monkey logo

command-line-script's Introduction

Docker LEMP(Linux, Nginx, MySQL, PHP) Stack Generation Script

The python script contain in this repository is used to create a LEMP stack (Linux, Nginx, MySQL, PHP) with docker. The script consist the functionality to create, enable, disable and also delete WordPress sites using docker containers. It automates the setup of the LEMP stack and WordPress, which make it easy to handle multiple WordPress sites on a local development environment.

Prerequisites

Before using this script, Please confirm you have the following installed on your system:

  • This script is created based on Ubuntu system so in order to test this please make sure you are using Ubuntu machine.

    sudo apt-get update
  • Python (python --version)

Getting Started

  1. Clone this repository to your local machine:

    git clone https://github.com/ToseebNadaf/Command-line-script.git
    cd Command-line-script/wordpress/
  2. Change the permission to make the Python script executable:

    chmod +x docker_lemp.py
  3. The script provides the following subcommands :

    This script assumes you have the necessary permissions to run Docker and modify system files. It may require running with sudo or as an administrator.

    --- Enable: Create and start a new WordPress site.

    sudo ./docker_lemp.py enable example.com

    --- Disable: Stop the containers for an existing WordPress site.

    sudo ./docker_lemp.py disable example.com

    --- Delete: Completely delete an existing WordPress site, including containers, volumes, and local files.

    • When deleting a site, please check again, as the process is irreversible and will delete all the containers, volumes, and local files.
    sudo ./docker_lemp.py delete example.com

    In order to open in Browser: After enabling a site, the script will prompt you to open the site in your default web browser.(localhost)

    Important Note -

    When enabling a site, ensure that the provided domain name (eg. example.com) is not already mapped to another service on your system. Confirm it by checking

    cat /etc/hosts

How this script works :

First of all in order to proceed with this we need to have python installed in our system as we mentioned in installation procress so now lets understand how it works.

  • Check Docker and Docker Compose:

It basicaaly use the subprocess module in order to check if Docker and Docker Compose are installed on the system. If it is not installed then prompt the user to install them manually or use the package manager (eg. apt-get) to install them.

  • Accept Site Name as Command-Line Argument:

Accept the site name as a command-line argument when user run the script. Ensure that the user provides the site name as a parameter, for example: python script.py example.com

  • Docker Compose File (docker-compose.yml):

Created a Docker Compose file (docker-compose.yml) which defines the stack configuration having MySQL image and custom wordpress image with additional configuration.

  • Create a WordPress Site:

It uses the subprocess module to run the docker-compose up -d command to create and start the containers. The containers configured to run WordPress, and the site name provided by the user is used as the container name.

  • Add /etc/hosts Entry:

It also use the subprocess module to add an entry to the /etc/hosts file. The entry should point example.com to localhost (127.0.0.1)

  • Check Site Health:

Use the subprocess module to check if the WordPress site is up and healthy. Wait for the containers to start successfully before proceeding.

  • Prompt to Open in Browser:

Use the webbrowser module to prompt the user to open http://example.com in their default web browser.

  • Enable/Disable Site :

Add subcommands in order to enable and disable to start and stop the containers respectively. Use the docker-compose up -d command to enable the site and docker-compose down to disable it.

  • Delete Site (Subcommand):

Add a subcommand delete to delete the site. Use the docker-compose down --volumes command to remove the containers and associated volumes. Remove the /etc/hosts entry for example.com. Delete any local files related to the site, such as WordPress configuration and database files.

  • Handle Errors and Exceptions:

Also Implemented error handling to display appropriate error messages to user if any command fails. Handle cases where the provided site name is invalid or conflicts with existing entries in /etc/hosts.

command-line-script's People

Contributors

toseebnadaf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.