-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
74 lines (59 loc) · 2.05 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Install script for Proxmox VM Autoscale project
# Repository: https://github.com/fabriziosalmi/proxmox-vm-autoscale
# Variables
INSTALL_DIR="/usr/local/bin/vm_autoscale"
REPO_URL="https://github.com/fabriziosalmi/proxmox-vm-autoscale"
SERVICE_FILE="vm_autoscale.service"
CONFIG_FILE="/usr/local/bin/vm_autoscale/config.yaml"
BACKUP_FILE="/usr/local/bin/vm_autoscale/config.yaml.backup"
# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Backup existing config.yaml if it exists
if [ -f "$CONFIG_FILE" ]; then
echo "Backing up existing config.yaml to config.yaml.backup..."
cp "$CONFIG_FILE" "$BACKUP_FILE"
fi
# Install necessary dependencies
echo "Installing necessary dependencies..."
apt-get update
apt-get install -y python3 curl bash git python3-paramiko python3-yaml python3-requests python3-cryptography
# Clone the repository
echo "Cloning the repository..."
if [ -d "$INSTALL_DIR" ]; then
echo "Removing existing installation directory..."
rm -rf "$INSTALL_DIR"
fi
git clone "$REPO_URL" "$INSTALL_DIR"
# Install Python dependencies
echo "Installing Python dependencies..."
pip3 install -r "$INSTALL_DIR/requirements.txt"
# Set permissions
echo "Setting permissions..."
chmod -R 755 "$INSTALL_DIR"
# Create the systemd service file
echo "Creating the systemd service file..."
cat <<EOF > /etc/systemd/system/$SERVICE_FILE
[Unit]
Description=Proxmox VM Autoscale Service
After=network.target
[Service]
ExecStart=/usr/bin/python3 $INSTALL_DIR/autoscale.py
WorkingDirectory=$INSTALL_DIR
Restart=always
User=root
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable the service, and ensure it's not started
echo "Reloading systemd, enabling the service..."
systemctl daemon-reload
systemctl enable $SERVICE_FILE
# Post-installation instructions
echo "Installation complete. The service is enabled but not started."
echo "To start the service, use: sudo systemctl start $SERVICE_FILE"
echo "Logs can be monitored using: journalctl -u $SERVICE_FILE -f"