Switched from influx to victoria metrics (more light weight for pi)
This commit is contained in:
97
setup.sh
97
setup.sh
@@ -3,22 +3,48 @@ set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
USER_NAME="$(whoami)"
|
||||
VM_VERSION="1.99.0"
|
||||
VM_DIR="/opt/victoriametrics"
|
||||
|
||||
echo "🔧 Setting up Weather Station..."
|
||||
|
||||
# ── InfluxDB ──────────────────────────────────────────────────────────────────
|
||||
# ── VictoriaMetrics ───────────────────────────────────────────────────────────
|
||||
|
||||
if ! command -v influxd &> /dev/null; then
|
||||
echo "📦 Installing InfluxDB..."
|
||||
curl https://repos.influxdata.com/influxdata-archive.key | gpg --dearmor | sudo tee /usr/share/keyrings/influxdata-archive-keyring.gpg > /dev/null
|
||||
echo "deb [signed-by=/usr/share/keyrings/influxdata-archive-keyring.gpg] https://repos.influxdata.com/debian stable main" | sudo tee /etc/apt/sources.list.d/influxdata.list
|
||||
sudo apt update && sudo apt install -y influxdb2
|
||||
sudo systemctl enable --now influxdb
|
||||
if ! systemctl is-enabled --quiet victoriametrics 2>/dev/null; then
|
||||
echo "📦 Installing VictoriaMetrics..."
|
||||
sudo mkdir -p $VM_DIR/data
|
||||
|
||||
wget -qO /tmp/vm.tar.gz \
|
||||
"https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v${VM_VERSION}/victoria-metrics-arm-v7-v${VM_VERSION}.tar.gz"
|
||||
sudo tar xf /tmp/vm.tar.gz -C $VM_DIR
|
||||
sudo chmod +x $VM_DIR/victoria-metrics-prod
|
||||
rm /tmp/vm.tar.gz
|
||||
|
||||
sudo tee /etc/systemd/system/victoriametrics.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=VictoriaMetrics
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=$VM_DIR/victoria-metrics-prod \
|
||||
-storageDataPath=$VM_DIR/data \
|
||||
-httpListenAddr=:8428 \
|
||||
-retentionPeriod=12
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now victoriametrics
|
||||
else
|
||||
echo "✅ InfluxDB already installed, skipping..."
|
||||
echo "✅ VictoriaMetrics already installed, skipping..."
|
||||
fi
|
||||
|
||||
# ── Node.js ───────────────────────────────────────────────────────────────────
|
||||
# ── Server / Node.js ──────────────────────────────────────────────────────────
|
||||
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo "📦 Installing Node.js..."
|
||||
@@ -28,7 +54,47 @@ else
|
||||
echo "✅ Node.js already installed, skipping..."
|
||||
fi
|
||||
|
||||
# ── Python venv ───────────────────────────────────────────────────────────────
|
||||
if [ ! -d "$SCRIPT_DIR/server/public/index.html" ]; then
|
||||
echo "🌐 Building Client..."
|
||||
cd "$SCRIPT_DIR/client"
|
||||
npm ci
|
||||
npx vite build
|
||||
else
|
||||
echo "✅ Client installed, skipping..."
|
||||
fi
|
||||
|
||||
if [ ! -d "$SCRIPT_DIR/server/node_modules" ]; then
|
||||
echo "🌐 Installing Server..."
|
||||
cd "$SCRIPT_DIR/server"
|
||||
npm ci
|
||||
else
|
||||
echo "✅ Server installed, skipping..."
|
||||
fi
|
||||
|
||||
if ! systemctl is-enabled --quiet weather-station 2>/dev/null; then
|
||||
echo "⚙️ Installing server service..."
|
||||
sudo tee /etc/systemd/system/weather-station.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Weather Station API
|
||||
After=network.target victoriametrics.service
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=$SCRIPT_DIR/server
|
||||
ExecStart=npm run start
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
User=$USER_NAME
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now weather-sensors
|
||||
else
|
||||
echo "✅ Server service already installed, skipping..."
|
||||
fi
|
||||
|
||||
# ── Sensors / Python venv ─────────────────────────────────────────────────────
|
||||
|
||||
if [ ! -d "$SCRIPT_DIR/sensors/venv" ]; then
|
||||
echo "🐍 Setting up Python environment..."
|
||||
@@ -40,14 +106,12 @@ else
|
||||
echo "✅ Python environment already set up, skipping..."
|
||||
fi
|
||||
|
||||
# ── Systemd service ───────────────────────────────────────────────────────────
|
||||
|
||||
if ! systemctl is-enabled --quiet weather-sensors 2>/dev/null; then
|
||||
echo "⚙️ Installing systemd service..."
|
||||
echo "⚙️ Installing sensor service..."
|
||||
sudo tee /etc/systemd/system/weather-sensors.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Weather Station Sensors
|
||||
After=network.target
|
||||
After=network.target victoriametrics.service
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=$SCRIPT_DIR/sensors
|
||||
@@ -62,10 +126,9 @@ EOF
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now weather-sensors
|
||||
else
|
||||
echo "✅ Systemd service already installed, skipping..."
|
||||
echo "✅ Sensor service already installed, skipping..."
|
||||
fi
|
||||
|
||||
echo "✅ All done!"
|
||||
echo " InfluxDB UI: http://localhost:8086"
|
||||
echo " VictoriaMetrics UI: http://localhost:8428"
|
||||
echo " Sensor logs: journalctl -fu weather-sensors"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user