Skip to content

Commit

Permalink
Update install.sh
Browse files Browse the repository at this point in the history
lxc_autoscale projects are now hosted on separate repositories. 
Here will continue standard lxc_autoscale, hopefully by including VM scaling.

If you are interested into the lxc_autoscale_ml (the proxmox machine learning autoscaling tool) please check this out:  https://github.com/fabriziosalmi/proxmox-lxc-autoscale-ml
  • Loading branch information
fabriziosalmi authored Sep 27, 2024
1 parent 7d891e6 commit 192ebde
Showing 1 changed file with 3 additions and 157 deletions.
160 changes: 3 additions & 157 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,48 +130,11 @@ remove_service_files() {
done
}

# Function to prompt the user for installation choice
prompt_user_choice() {
local default_choice="1"
local timeout=1

log "INFO" "Prompting user for installation choice with a ${timeout}-second timeout..."

echo -e "Please choose an installation option:"
echo "1) ⚙️ LXC AutoScale (default)"
echo "2) ✨ LXC AutoScale ML (experimental)"
echo -e "You have ${timeout} seconds to choose. If no choice is made, option 1 will be selected automatically.\n"

# Using /dev/tty to read input from the terminal directly
if read -r -t $timeout user_choice < /dev/tty; then
log "INFO" "User selected option ${user_choice}."
else
user_choice=$default_choice
log "INFO" "No input received, defaulting to option ${user_choice}."
fi

echo -e "You chose option ${user_choice}."
echo

case $user_choice in
1)
install_flag="LXC_AUTO_SCALE"
;;
2)
install_flag="LXC_AUTO_SCALE_ML"
;;
*)
log "ERROR" "Invalid choice. Exiting."
exit 1
;;
esac
}

# Function to install LXC AutoScale
install_lxc_autoscale() {
log "INFO" "Installing LXC AutoScale..."

# Disable and stop lxc_autoscale_ml if running. Don't use both at same time (you can still run api and monitor)
# Disable and stop lxc_autoscale_ml if running. Don't use both at the same time (you can still run api and monitor)
systemctl disable lxc_autoscale_ml
systemctl stop lxc_autoscale_ml

Expand Down Expand Up @@ -219,129 +182,12 @@ install_lxc_autoscale() {
fi
}

# Function to install LXC AutoScale ML
install_lxc_autoscale_ml() {
log "INFO" "Installing LXC AutoScale ML..."

# Disable and stop lxc_autoscale if running. Don't use both at same time
systemctl disable lxc_autoscale
systemctl stop lxc_autoscale

# Stop lxc_autoscale_ml if running
systemctl stop lxc_autoscale_ml

# Reload systemd
systemctl daemon-reload

# Install needed packages
apt install git python3-flask python3-requests python3-paramiko -y

# Create necessary directories
mkdir -p /etc/lxc_autoscale_ml
mkdir -p /usr/local/bin/lxc_autoscale_api
mkdir -p /usr/local/bin/lxc_autoscale_ml

# Create an empty __init__.py file to treat the directory as a Python package
touch /usr/local/bin/lxc_autoscale_ml/__init__.py
touch /usr/local/bin/lxc_autoscale_api/__init__.py

# Download and install all Python files in the lxc_autoscale_ml directory

# Download and install the api application files
curl -sSL -o /usr/local/bin/lxc_autoscale_api/lxc_autoscale_api.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/lxc_autoscale_api.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/cloning_management.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/cloning_management.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/config.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/config.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/error_handling.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/error_handling.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/health_check.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/health_check.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/lxc_management.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/lxc_management.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/resource_checking.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/resource_checking.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/scaling.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/scaling.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/snapshot_management.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/snapshot_management.py
curl -sSL -o /usr/local/bin/lxc_autoscale_api/utils.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/utils.py
# Download and install the api configuration file
curl -sSL -o /etc/lxc_autoscale_ml/lxc_autoscale_api.yaml https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/lxc_autoscale_api.yaml

# Download and install the monitor application file
curl -sSL -o /usr/local/bin/lxc_monitor.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/monitor/lxc_monitor.py
# Download and install the monitor configuration file
curl -sSL -o /etc/lxc_autoscale_ml/lxc_monitor.yaml https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/lxc_autoscale_api.yaml

# Download and install the model application files
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/config_manager.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/config_manager.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/data_manager.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/data_manager.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/lock_manager.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/lock_manager.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/logger.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/logger.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/model.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/model.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/scaling.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/scaling.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/signal_handler.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/signal_handler.py
curl -sSL -o /usr/local/bin/lxc_autoscale_ml/lxc_autoscale_ml.py https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/lxc_autoscale_ml.py
# Download and install the model configuration file
curl -sSL -o /etc/lxc_autoscale_ml/lxc_autoscale_ml.yaml https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/lxc_autoscale_ml.yaml

# Download and install the systemd services file
curl -sSL -o /etc/systemd/system/lxc_autoscale_ml.service https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/model/lxc_autoscale_ml.service
curl -sSL -o /etc/systemd/system/lxc_autoscale_api.service https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/api/lxc_autoscale_api.service
curl -sSL -o /etc/systemd/system/lxc_monitor.service https://raw.githubusercontent.com/fabriziosalmi/proxmox-lxc-autoscale/main/lxc_autoscale_ml/monitor/lxc_monitor.service

# Make the main script executable
chmod +x /usr/local/bin/lxc_autoscale_ml/lxc_autoscale_ml.py
chmod +x /usr/local/bin/lxc_autoscale_api/lxc_autoscale_api.py
chmod +x /usr/local/bin/lxc_monitor.py

# Reload systemd to recognize the new service
systemctl daemon-reload
systemctl enable lxc_autoscale_ml.service
systemctl enable lxc_autoscale_api.service
systemctl enable lxc_monitor.service

# Automatically start the service after installation
if systemctl start lxc_autoscale_api.service; then
log "INFO" "${CHECKMARK} Service LXC AutoScale API started successfully!"
else
log "ERROR" "${CROSSMARK} Failed to start Service LXC AutoScale."
fi

# Automatically start the service after installation
if systemctl start lxc_monitor.service; then
log "INFO" "${CHECKMARK} Service LXC Monitor started successfully!"
else
log "ERROR" "${CROSSMARK} Failed to start Service LXC Monitor."
fi

# Automatically start the service after installation
if systemctl start lxc_autoscale_ml.service; then
log "INFO" "${CHECKMARK} Service LXC AutoScale ML started successfully!"
else
log "ERROR" "${CROSSMARK} Failed to start Service LXC AutoScale ML."
fi

# Show status for all installed services
systemctl status lxc_monitor.service --no-pager
systemctl status lxc_autoscale_api.service --no-pager
systemctl status lxc_autoscale_ml.service --no-pager
}

# Main script execution
header
backup_files
delete_files_and_folders
prompt_user_choice

# Ensure the install_flag is initialized
install_flag=${install_flag:-""}

# Proceed with installation based on the chosen option
case $install_flag in
"LXC_AUTO_SCALE")
install_lxc_autoscale
;;
"LXC_AUTO_SCALE_ML")
install_lxc_autoscale_ml
;;
*)
log "ERROR" "Invalid installation flag. Exiting."
exit 1
;;
esac
# Proceed with LXC AutoScale installation
install_lxc_autoscale

log "INFO" "${CHECKMARK} Installation process complete!"

0 comments on commit 192ebde

Please sign in to comment.