Sfoglia il codice sorgente

Server: Install script

Christian Kahlau 3 anni fa
parent
commit
4cb17191e9
4 ha cambiato i file con 109 aggiunte e 2 eliminazioni
  1. 2 1
      .gitignore
  2. 5 1
      Readme.md
  3. 0 0
      server/.env.default
  4. 102 0
      server/install/install.sh

+ 2 - 1
.gitignore

@@ -7,4 +7,5 @@ daemon/.env
 
 server/public/
 server/dist/
-server/data/
+server/data/
+server/.env

+ 5 - 1
Readme.md

@@ -10,4 +10,8 @@ curl -fsSL https://gogs.hostbbq.com/hostbbq/hostbbq-monitoring/raw/master/daemon
 
 ## Monitoring Server & Web UI
 
-...
+### Install
+
+```bash
+curl -fsSL https://gogs.hostbbq.com/hostbbq/hostbbq-monitoring/raw/master/server/install/install.sh | sudo -E bash -
+```

+ 0 - 0
server/.env → server/.env.default


+ 102 - 0
server/install/install.sh

@@ -0,0 +1,102 @@
+#!/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
+
+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 https://gogs.hostbbq.com/hostbbq/hostbbq-monitoring.git "$TMPFOLDER"
+git submodule init
+git submodule update
+
+cd "$TMPFOLDER/server"
+echo "[INSTALL] Installing npm build dependencies for server project"
+$EXC_NPM install
+
+cd "$TMPFOLDER/ng"
+echo "[INSTALL] Installing npm build dependencies for Angular project"
+$EXC_NPM install
+
+echo "[INSTALL] Building Angular project"
+$EXC_NPM run build
+
+cd "$TMPFOLDER/server"
+echo "[INSTALL] Transpiling typescript sources of server project"
+$EXC_NPM run build
+
+echo "[INSTALL] Installing server application"
+if [ -d "$INSTALL_DIR/dist" ]; then
+  rm -rf "$INSTALL_DIR/dist"
+fi
+cp -rv "dist" "$INSTALL_DIR/"
+cp -rv "public" "$INSTALL_DIR/"
+if [ ! -f "$INSTALL_DIR/.env" ]; then
+  cp -v ".env.default" "$INSTALL_DIR/.env"
+fi
+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@server.service\""
+SVC_FILE="/lib/systemd/system/monitoring@server.service"
+
+ACTION="update"
+if [ ! -f "$SVC_FILE" ]; then
+  ACTION="install"
+fi
+
+cat > $SVC_FILE << EOF
+[Unit]
+Description=HostBBQ Monitoring Server Service
+After=network.target
+
+[Service]
+Type=simple
+WorkingDirectory=$INSTALL_DIR
+ExecStart=node .
+
+[Install]
+WantedBy=multi-user.target
+Alias=monitoring@server.service
+EOF
+
+if [[ "$ACTION" = "install" ]]; then
+  systemctl enable monitoring@server.service
+  systemctl start monitoring@server.service
+else
+  systemctl restart monitoring@server.service
+fi
+
+echo "[CLEANUP] Removing temp folder $TMPFOLDER"
+rm -rf "$TMPFOLDER"
+
+echo "[SUCCESS] HostBBQ Monitoring Server installed and activated successfully"