From acb1239e2ce3de9bf146e054d64b36c634fbcccb Mon Sep 17 00:00:00 2001 From: "abdur.rehman" Date: Fri, 30 Aug 2024 09:55:51 +0200 Subject: [PATCH] update prod and dev ips --- installer.sh | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/installer.sh b/installer.sh index e854f69..338a65d 100644 --- a/installer.sh +++ b/installer.sh @@ -1,68 +1,68 @@ -#!/bin/bash - -# Define variables for easier modifications and readability -GIT_REPO="https://git.maxprint.io/MaxApex/ticket_ai_flask_app.git" -APP_DIR="/opt/ticket-ai" -VENV_DIR="$APP_DIR/venv" -SERVICE_FILE="/etc/systemd/system/ticket-ai.service" -PYTHON_BIN="$VENV_DIR/bin/python3" -ACTIVATE_SCRIPT="$VENV_DIR/bin/activate" -IPTABLES_RULES=("83.136.253.122") # Add IPs as needed - -# Ensure the script is run as root -if [ "$(id -u)" != "0" ]; then - echo "This script must be run as root" 1>&2 - exit 1 -fi - -# Installing git -yum install -y git || { echo "Failed to install git. Exiting."; exit 1; } - -# Clone the repository if it doesn't exist -if [ ! -d "$APP_DIR" ]; then - git clone $GIT_REPO $APP_DIR || { echo "Failed to clone repository. Exiting."; exit 1; } -else - echo "$APP_DIR already exists. Skipping clone." -fi - -# Navigate to the repo directory -cd $APP_DIR || { echo "Failed to navigate to $APP_DIR. Exiting."; exit 1; } - -# Create virtual environment if it doesn't exist -if [ ! -d "$VENV_DIR" ]; then - python3 -m venv $VENV_DIR -else - echo "$VENV_DIR already exists. Skipping virtual environment creation." -fi - -# Activate virtual environment and install dependencies -source $ACTIVATE_SCRIPT -pip install Flask flask_jwt_extended || { echo "Failed to install Flask or flask_jwt_extended. Exiting."; exit 1; } - -# Create systemd service file -cat < $SERVICE_FILE -[Unit] -Description=Ticket AI - -[Service] -Type=simple -ExecStart=$PYTHON_BIN $APP_DIR/src/app.py - -[Install] -WantedBy=multi-user.target -EOF - -# Reload systemd to recognize the new service and start it -systemctl daemon-reload -systemctl start ticket-ai.service || { echo "Failed to start ticket-ai.service. Exiting."; exit 1; } - -# Add firewall rules to accept traffic -for IP in "${IPTABLES_RULES[@]}"; do - iptables -A INPUT -p tcp -m tcp -s $IP --dport 5000 -j ACCEPT -done - -# Save iptables rules and restart the service to apply changes -service iptables save -service iptables restart || { echo "Failed to restart iptables. Exiting."; exit 1; } - -echo "Setup completed successfully." +#!/bin/bash + +# Define variables for easier modifications and readability +GIT_REPO="https://git.maxprint.io/MaxApex/ticket_ai_flask_app.git" +APP_DIR="/opt/ticket-ai" +VENV_DIR="$APP_DIR/venv" +SERVICE_FILE="/etc/systemd/system/ticket-ai.service" +PYTHON_BIN="$VENV_DIR/bin/python3" +ACTIVATE_SCRIPT="$VENV_DIR/bin/activate" +IPTABLES_RULES=("94.130.177.171" "78.47.32.44") # Add IPs as needed + +# Ensure the script is run as root +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" 1>&2 + exit 1 +fi + +# Installing git +yum install -y git || { echo "Failed to install git. Exiting."; exit 1; } + +# Clone the repository if it doesn't exist +if [ ! -d "$APP_DIR" ]; then + git clone $GIT_REPO $APP_DIR || { echo "Failed to clone repository. Exiting."; exit 1; } +else + echo "$APP_DIR already exists. Skipping clone." +fi + +# Navigate to the repo directory +cd $APP_DIR || { echo "Failed to navigate to $APP_DIR. Exiting."; exit 1; } + +# Create virtual environment if it doesn't exist +if [ ! -d "$VENV_DIR" ]; then + python3 -m venv $VENV_DIR +else + echo "$VENV_DIR already exists. Skipping virtual environment creation." +fi + +# Activate virtual environment and install dependencies +source $ACTIVATE_SCRIPT +pip install Flask flask_jwt_extended || { echo "Failed to install Flask or flask_jwt_extended. Exiting."; exit 1; } + +# Create systemd service file +cat < $SERVICE_FILE +[Unit] +Description=Ticket AI + +[Service] +Type=simple +ExecStart=$PYTHON_BIN $APP_DIR/src/app.py + +[Install] +WantedBy=multi-user.target +EOF + +# Reload systemd to recognize the new service and start it +systemctl daemon-reload +systemctl start ticket-ai.service || { echo "Failed to start ticket-ai.service. Exiting."; exit 1; } + +# Add firewall rules to accept traffic +for IP in "${IPTABLES_RULES[@]}"; do + iptables -A INPUT -p tcp -m tcp -s $IP --dport 5000 -j ACCEPT +done + +# Save iptables rules and restart the service to apply changes +service iptables save +service iptables restart || { echo "Failed to restart iptables. Exiting."; exit 1; } + +echo "Setup completed successfully."