Refactor: Glances (+ Feature Bump) (#6976)
* Refactor: Glances * Update glances.json * Update glances.json
This commit is contained in:
parent
067f9eb209
commit
66c03ce1b4
@ -6,7 +6,7 @@
|
|||||||
],
|
],
|
||||||
"date_created": "2024-05-02",
|
"date_created": "2024-05-02",
|
||||||
"type": "addon",
|
"type": "addon",
|
||||||
"updateable": false,
|
"updateable": true,
|
||||||
"privileged": false,
|
"privileged": false,
|
||||||
"interface_port": 61208,
|
"interface_port": 61208,
|
||||||
"documentation": "https://glances.readthedocs.io/en/latest/",
|
"documentation": "https://glances.readthedocs.io/en/latest/",
|
||||||
@ -33,12 +33,8 @@
|
|||||||
},
|
},
|
||||||
"notes": [
|
"notes": [
|
||||||
{
|
{
|
||||||
"text": "Execute within an existing LXC Console",
|
"text": "Execute within an existing LXC Console (Debian / Ubuntu / Alpine supported)",
|
||||||
"type": "warning"
|
"type": "info"
|
||||||
},
|
|
||||||
{
|
|
||||||
"text": "WARNING: Installation sources scripts outside of Community Scripts repo. Please check the source before installing.",
|
|
||||||
"type": "warning"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Copyright (c) 2021-2025 tteck
|
# Copyright (c) 2021-2025 tteck
|
||||||
# Author: tteck (tteckster)
|
# Author: tteck (tteckster) | MickLesk (CanbiZ)
|
||||||
# License: MIT
|
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||||
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
|
||||||
|
|
||||||
function header_info {
|
function header_info {
|
||||||
clear
|
clear
|
||||||
@ -16,65 +15,55 @@ function header_info {
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
IP=$(hostname -I | awk '{print $1}')
|
|
||||||
YW=$(echo "\033[33m")
|
|
||||||
BL=$(echo "\033[36m")
|
|
||||||
RD=$(echo "\033[01;31m")
|
|
||||||
BGN=$(echo "\033[4;92m")
|
|
||||||
GN=$(echo "\033[1;92m")
|
|
||||||
DGN=$(echo "\033[32m")
|
|
||||||
CL=$(echo "\033[m")
|
|
||||||
BFR="\\r\\033[K"
|
|
||||||
HOLD=" "
|
|
||||||
CM="${GN}✓${CL}"
|
|
||||||
APP="Glances"
|
APP="Glances"
|
||||||
hostname="$(hostname)"
|
YW=$(echo "\033[33m")
|
||||||
silent() { "$@" >/dev/null 2>&1; }
|
GN=$(echo "\033[1;92m")
|
||||||
set -e
|
RD=$(echo "\033[01;31m")
|
||||||
spinner() {
|
BL=$(echo "\033[36m")
|
||||||
local chars="/-\|"
|
CL=$(echo "\033[m")
|
||||||
local spin_i=0
|
CM="${GN}✔️${CL}"
|
||||||
printf "\e[?25l"
|
CROSS="${RD}✖️${CL}"
|
||||||
while true; do
|
INFO="${BL}ℹ️${CL}"
|
||||||
printf "\r \e[36m%s\e[0m" "${chars:spin_i++%${#chars}:1}"
|
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_info() {
|
function msg_info() { echo -e "${INFO} ${YW}$1...${CL}"; }
|
||||||
local msg="$1"
|
function msg_ok() { echo -e "${CM} ${GN}$1${CL}"; }
|
||||||
echo -ne " ${HOLD} ${YW}${msg} "
|
function msg_error() { echo -e "${CROSS} ${RD}$1${CL}"; }
|
||||||
spinner &
|
|
||||||
SPINNER_PID=$!
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_ok() {
|
get_local_ip() {
|
||||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
if command -v hostname >/dev/null 2>&1 && hostname -I 2>/dev/null; then
|
||||||
printf "\e[?25h"
|
hostname -I | awk '{print $1}'
|
||||||
local msg="$1"
|
elif command -v ip >/dev/null 2>&1; then
|
||||||
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
|
ip -4 addr show scope global | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1
|
||||||
}
|
|
||||||
|
|
||||||
install() {
|
|
||||||
header_info
|
|
||||||
while true; do
|
|
||||||
read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn
|
|
||||||
case $yn in
|
|
||||||
[Yy]*) break ;;
|
|
||||||
[Nn]*) exit ;;
|
|
||||||
*) echo "Please answer yes or no." ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
header_info
|
|
||||||
read -r -p "Verbose mode? <y/N> " prompt
|
|
||||||
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
|
|
||||||
STD=""
|
|
||||||
else
|
else
|
||||||
STD="silent"
|
echo "127.0.0.1"
|
||||||
fi
|
fi
|
||||||
msg_info "Installing $APP"
|
}
|
||||||
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
|
IP=$(get_local_ip)
|
||||||
$STD bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicolargo/glancesautoinstall/master/install.sh)"
|
|
||||||
|
install_glances_debian() {
|
||||||
|
msg_info "Installing dependencies"
|
||||||
|
apt-get update >/dev/null 2>&1
|
||||||
|
apt-get install -y gcc lm-sensors wireless-tools >/dev/null 2>&1
|
||||||
|
msg_ok "Installed dependencies"
|
||||||
|
|
||||||
|
msg_info "Setting up Python + uv"
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
|
||||||
|
setup_uv PYTHON_VERSION="3.12"
|
||||||
|
msg_ok "Setup Python + uv"
|
||||||
|
|
||||||
|
msg_info "Installing $APP (with web UI)"
|
||||||
|
cd /opt
|
||||||
|
mkdir -p glances
|
||||||
|
cd glances
|
||||||
|
uv venv
|
||||||
|
source .venv/bin/activate >/dev/null 2>&1
|
||||||
|
uv pip install --upgrade pip wheel setuptools >/dev/null 2>&1
|
||||||
|
uv pip install "glances[web]" >/dev/null 2>&1
|
||||||
|
deactivate
|
||||||
|
msg_ok "Installed $APP"
|
||||||
|
|
||||||
|
msg_info "Creating systemd service"
|
||||||
cat <<EOF >/etc/systemd/system/glances.service
|
cat <<EOF >/etc/systemd/system/glances.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Glances - An eye on your system
|
Description=Glances - An eye on your system
|
||||||
@ -82,44 +71,132 @@ After=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/usr/local/bin/glances -w
|
ExecStart=/opt/glances/.venv/bin/glances -w
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
WorkingDirectory=/opt/glances
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
systemctl enable -q --now glances.service
|
systemctl enable -q --now glances
|
||||||
msg_ok "Installed $APP on $hostname"
|
msg_ok "Created systemd service"
|
||||||
|
|
||||||
echo -e "${APP} should be reachable by going to the following URL.
|
echo -e "\n$APP is now running at: http://$IP:61208\n"
|
||||||
${BL}http://$IP:61208${CL} \n"
|
|
||||||
}
|
}
|
||||||
uninstall() {
|
|
||||||
header_info
|
# update on Debian/Ubuntu
|
||||||
|
update_glances_debian() {
|
||||||
|
if [[ ! -d /opt/glances/.venv ]]; then
|
||||||
|
msg_error "$APP is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
msg_info "Updating $APP"
|
||||||
|
cd /opt/glances
|
||||||
|
source .venv/bin/activate
|
||||||
|
uv pip install --upgrade "glances[web]" >/dev/null 2>&1
|
||||||
|
deactivate
|
||||||
|
systemctl restart glances
|
||||||
|
msg_ok "Updated $APP"
|
||||||
|
}
|
||||||
|
|
||||||
|
# uninstall on Debian/Ubuntu
|
||||||
|
uninstall_glances_debian() {
|
||||||
msg_info "Uninstalling $APP"
|
msg_info "Uninstalling $APP"
|
||||||
if [ -n "$SPINNER_PID" ] && ps -p $SPINNER_PID >/dev/null; then kill $SPINNER_PID >/dev/null; fi
|
systemctl disable -q --now glances || true
|
||||||
systemctl disable -q --now glances
|
rm -f /etc/systemd/system/glances.service
|
||||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nicolargo/glancesautoinstall/master/uninstall.sh)"
|
rm -rf /opt/glances
|
||||||
rm -rf /etc/systemd/system/glances.service
|
msg_ok "Removed $APP"
|
||||||
msg_ok "Uninstalled $APP"
|
|
||||||
msg_ok "Completed Successfully!\n"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# install on Alpine
|
||||||
|
install_glances_alpine() {
|
||||||
|
msg_info "Installing dependencies"
|
||||||
|
apk update >/dev/null 2>&1
|
||||||
|
$STD apk add --no-cache \
|
||||||
|
gcc musl-dev linux-headers python3-dev \
|
||||||
|
python3 py3-pip py3-virtualenv lm-sensors wireless-tools >/dev/null 2>&1
|
||||||
|
msg_ok "Installed dependencies"
|
||||||
|
|
||||||
|
msg_info "Setting up Python + uv"
|
||||||
|
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/tools.func)
|
||||||
|
setup_uv PYTHON_VERSION="3.12"
|
||||||
|
msg_ok "Setup Python + uv"
|
||||||
|
|
||||||
|
msg_info "Installing $APP (with web UI)"
|
||||||
|
cd /opt
|
||||||
|
mkdir -p glances
|
||||||
|
cd glances
|
||||||
|
uv venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
uv pip install --upgrade pip wheel setuptools >/dev/null 2>&1
|
||||||
|
uv pip install "glances[web]" >/dev/null 2>&1
|
||||||
|
deactivate
|
||||||
|
msg_ok "Installed $APP"
|
||||||
|
|
||||||
|
msg_info "Creating OpenRC service"
|
||||||
|
cat <<'EOF' >/etc/init.d/glances
|
||||||
|
#!/sbin/openrc-run
|
||||||
|
command="/opt/glances/.venv/bin/glances"
|
||||||
|
command_args="-w"
|
||||||
|
command_background="yes"
|
||||||
|
pidfile="/run/glances.pid"
|
||||||
|
name="glances"
|
||||||
|
description="Glances monitoring tool"
|
||||||
|
EOF
|
||||||
|
chmod +x /etc/init.d/glances
|
||||||
|
rc-update add glances default
|
||||||
|
rc-service glances start
|
||||||
|
msg_ok "Created OpenRC service"
|
||||||
|
|
||||||
|
echo -e "\n$APP is now running at: http://$IP:61208\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# update on Alpine
|
||||||
|
update_glances_alpine() {
|
||||||
|
if [[ ! -d /opt/glances/.venv ]]; then
|
||||||
|
msg_error "$APP is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
msg_info "Updating $APP"
|
||||||
|
cd /opt/glances
|
||||||
|
source .venv/bin/activate
|
||||||
|
uv pip install --upgrade "glances[web]" >/dev/null 2>&1
|
||||||
|
deactivate
|
||||||
|
rc-service glances restart
|
||||||
|
msg_ok "Updated $APP"
|
||||||
|
}
|
||||||
|
|
||||||
|
# uninstall on Alpine
|
||||||
|
uninstall_glances_alpine() {
|
||||||
|
msg_info "Uninstalling $APP"
|
||||||
|
rc-service glances stop || true
|
||||||
|
rc-update del glances || true
|
||||||
|
rm -f /etc/init.d/glances
|
||||||
|
rm -rf /opt/glances
|
||||||
|
msg_ok "Removed $APP"
|
||||||
|
}
|
||||||
|
|
||||||
|
# options menu
|
||||||
OPTIONS=(Install "Install $APP"
|
OPTIONS=(Install "Install $APP"
|
||||||
|
Update "Update $APP"
|
||||||
Uninstall "Uninstall $APP")
|
Uninstall "Uninstall $APP")
|
||||||
|
|
||||||
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "$APP" --menu "Select an option:" 10 58 2 \
|
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "$APP" --menu "Select an option:" 12 58 3 \
|
||||||
"${OPTIONS[@]}" 3>&1 1>&2 2>&3)
|
"${OPTIONS[@]}" 3>&1 1>&2 2>&3 || true)
|
||||||
|
|
||||||
case $CHOICE in
|
# OS detection
|
||||||
"Install")
|
if grep -qi "alpine" /etc/os-release; then
|
||||||
install
|
case "$CHOICE" in
|
||||||
;;
|
Install) install_glances_alpine ;;
|
||||||
"Uninstall")
|
Update) update_glances_alpine ;;
|
||||||
uninstall
|
Uninstall) uninstall_glances_alpine ;;
|
||||||
;;
|
*) exit 0 ;;
|
||||||
*)
|
esac
|
||||||
echo "Exiting..."
|
else
|
||||||
exit 0
|
case "$CHOICE" in
|
||||||
;;
|
Install) install_glances_debian ;;
|
||||||
esac
|
Update) update_glances_debian ;;
|
||||||
|
Uninstall) uninstall_glances_debian ;;
|
||||||
|
*) exit 0 ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user