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