@@ -20,26 +20,69 @@ color
2020catch_errors
2121
2222function update_script() {
23- header_info
24- check_container_storage
25- check_container_resources
26- if [[ ! -f /etc/systemd/system/prometheus-pve-exporter.service ]]; then
27- msg_error " No ${APP} Installation Found!"
28- exit
29- fi
30- msg_info " Stopping ${APP} "
31- systemctl stop prometheus-pve-exporter
32- msg_ok " Stopped ${APP} "
33-
34- msg_info " Updating ${APP} "
35- $STD pip install prometheus-pve-exporter --default-timeout=300 --upgrade --root-user-action=ignore
36- msg_ok " Updated ${APP} "
37-
38- msg_info " Starting ${APP} "
39- systemctl start prometheus-pve-exporter
40- msg_ok " Started ${APP} "
41- msg_ok " Updated Successfully"
42- exit
23+ header_info
24+ check_container_storage
25+ check_container_resources
26+ if [[ ! -f /etc/systemd/system/prometheus-pve-exporter.service ]]; then
27+ msg_error " No ${APP} Installation Found!"
28+ exit 1
29+ fi
30+
31+ msg_info " Stopping ${APP} "
32+ systemctl stop prometheus-pve-exporter
33+ msg_ok " Stopped ${APP} "
34+
35+ export PVE_VENV_PATH=" /opt/prometheus-pve-exporter/.venv"
36+ export PVE_EXPORTER_BIN=" ${PVE_VENV_PATH} /bin/pve_exporter"
37+
38+ if [[ ! -d " $PVE_VENV_PATH " || ! -x " $PVE_EXPORTER_BIN " ]]; then
39+ PYTHON_VERSION=" 3.12" setup_uv
40+ msg_info " Migrating to uv/venv"
41+ rm -rf " $PVE_VENV_PATH "
42+ mkdir -p /opt/prometheus-pve-exporter
43+ cd /opt/prometheus-pve-exporter
44+ $STD uv venv " $PVE_VENV_PATH "
45+ $STD " $PVE_VENV_PATH /bin/python" -m ensurepip --upgrade
46+ $STD " $PVE_VENV_PATH /bin/python" -m pip install --upgrade pip
47+ $STD " $PVE_VENV_PATH /bin/python" -m pip install prometheus-pve-exporter
48+ msg_ok " Migrated to uv/venv"
49+ else
50+ msg_info " Updating Prometheus Proxmox VE Exporter"
51+ PYTHON_VERSION=" 3.12" setup_uv
52+ $STD " $PVE_VENV_PATH /bin/python" -m pip install --upgrade prometheus-pve-exporter
53+ msg_ok " Updated Prometheus Proxmox VE Exporter"
54+ fi
55+ local service_file=" /etc/systemd/system/prometheus-pve-exporter.service"
56+ if ! grep -q " ${PVE_VENV_PATH} /bin/pve_exporter" " $service_file " ; then
57+ msg_info " Updating systemd service"
58+ cat << EOF >"$service_file "
59+ [Unit]
60+ Description=Prometheus Proxmox VE Exporter
61+ Documentation=https://github.com/znerol/prometheus-pve-exporter
62+ After=syslog.target network.target
63+
64+ [Service]
65+ User=root
66+ Restart=always
67+ Type=simple
68+ ExecStart=${PVE_VENV_PATH} /bin/pve_exporter \\
69+ --config.file=/opt/prometheus-pve-exporter/pve.yml \\
70+ --web.listen-address=0.0.0.0:9221
71+ ExecReload=/bin/kill -HUP \$ MAINPID
72+
73+ [Install]
74+ WantedBy=multi-user.target
75+ EOF
76+ $STD systemctl daemon-reload
77+ msg_ok " Updated systemd service"
78+ fi
79+
80+ msg_info " Starting ${APP} "
81+ systemctl start prometheus-pve-exporter
82+ msg_ok " Started ${APP} "
83+
84+ msg_ok " Updated Successfully"
85+ exit 0
4386}
4487
4588start
@@ -49,4 +92,4 @@ description
4992msg_ok " Completed Successfully!\n"
5093echo -e " ${CREATING}${GN}${APP} setup has been successfully initialized!${CL} "
5194echo -e " ${INFO}${YW} Access it using the following URL:${CL} "
52- echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :9221${CL} "
95+ echo -e " ${TAB}${GATEWAY}${BGN} http://${IP} :9221${CL} "
0 commit comments