Эх сурвалжийг харах

Daemon: Install Script + Readme

Christian Kahlau 3 жил өмнө
parent
commit
2491a4c1c9

+ 13 - 0
Readme.md

@@ -0,0 +1,13 @@
+# HostBBQ Monitoring System
+
+## Monitoring Daemon
+
+### Install
+
+```bash
+curl -fsSL https://gogs.hostbbq.com/hostbbq/hostbbq-monitoring/raw/master/daemon/install/install.sh | bash -
+```
+
+## Monitoring Server & Web UI
+
+...

+ 98 - 0
daemon/install/install.sh

@@ -0,0 +1,98 @@
+#!/bin/bash
+
+INSTALL_DIR="${PWD}"
+
+# Check system requirements: Git, Node & NPM
+EXC_GIT="$(/usr/bin/which git)"
+if [ -z "$EXC_GIT" ]; then
+  echo "[ERROR] Missing required system dependency 'git'." >&2
+  echo "Please install using \"apt install git\"" >&2
+  exit 1
+fi
+
+EXC_NPM="$(/usr/bin/which npm)"
+if [ -z "$EXC_NPM" ]; then
+  echo "[ERROR] Missing required system dependency 'npm'." >&2
+  echo "Please install following the official install documentation." >&2
+  exit 1
+fi
+
+EXC_NODE="$(/usr/bin/which node)"
+if [ -z "$EXC_NODE" ]; then
+  echo "[ERROR] Missing required system dependency 'node'." >&2
+  echo "Please install following the official install documentation." >&2
+  exit 1
+fi
+
+# exit on error exit codes
+set -e
+
+# Ensure SSH-Agent is started and id_rsa loaded, 
+# git and npm will do a lot of stuff via ssh and 
+# ask for id passphrase multiple times if there's
+# no agent
+echo "[INSTALL] Starting SSH agent"
+eval $(ssh-agent)
+ssh-add ~/.ssh/id_rsa
+
+TMPFOLDER="/tmp/hbbq/monitoring/$(date +'%Y%m%d%H%M%S')"
+
+echo "[INSTALL] Cloning entire project into temp folder $TMPFOLDER"
+mkdir -p "$TMPFOLDER"
+git clone ssh://git@gogs.hostbbq.com:8301/hostbbq/hostbbq-monitoring.git "$TMPFOLDER"
+
+cd "$TMPFOLDER/daemon"
+
+echo "[INSTALL] Installing npm build dependencies for daemon project"
+$EXC_NPM install
+
+echo "[INSTALL] Transpiling typescript sources of daemon project"
+$EXC_NPM run build
+
+echo "[INSTALL] Installing daemon service application"
+cp -rv "dist" "$INSTALL_DIR/"
+cp -v ".env.default" "$INSTALL_DIR/.env"
+cp -v "cpu.sh" "$INSTALL_DIR/"
+cp -v "hdd.sh" "$INSTALL_DIR/"
+cp -v "ram.sh" "$INSTALL_DIR/"
+cp -v "package.json" "$INSTALL_DIR/"
+
+cd "$INSTALL_DIR"
+
+echo "[INSTALL] Installing npm runtime dependencies"
+$EXC_NPM install --omit=dev
+
+echo "[INSTALL] Creating and enabling systemd unit \"monitoring@daemon.service\""
+SVC_FILE="/etc/systemd/system/monitoring@daemon.service"
+
+ACTION="update"
+if [ ! -f "$SVC_FILE" ]; then
+  ACTION="install"
+fi
+
+cat > $SVC_FILE << EOF
+[Unit]
+Description=HostBBQ Monitoring Daemon Service
+After=network.target
+
+[Service]
+Type=simple
+WorkingDirectory="$INSTALL_DIR"
+ExecStart=node .
+ExecStop=/bin/kill -TERM \$MAINPID
+
+[Install]
+WantedBy=multi-user.target
+Alias=monitoring@daemon.service
+EOF
+
+if [[ "$ACTION" = "install" ]]; then
+  systemctl enable monitoring@daemon.service
+else
+  systemctl restart monitoring@daemon.service
+fi
+
+echo "[CLEANUP] Removing temp folder $TMPFOLDER"
+rm -rf "$TMPFOLDER"
+
+echo "[SUCCESS] HostBBQ Monitoring Daemon installed and activated successfully"