BlueGit

timfa filemanager

service requirements

timfa Tim Falken · pushed by timfa

Authored 2026-05-03 · 6 months ago

Hash
7f110dabf38f6934d52abef8524f0dc84011668f
Parent
d3c0b911
2 files changed +71 −0
installsystemdservice.sh added +50 −0
@@ -0,0 +1,50 @@
1 #!/usr/bin/env bash
2 # installsystemdservice.sh — Installs filemanager as a systemd service.
3 # Must be run as root: sudo ./installsystemdservice.sh
4
5 set -euo pipefail
6
7 if [[ "$(id -u)" -ne 0 ]]; then
8 echo "Error: this script must be run as root (use sudo)." >&2
9 exit 1
10 fi
11
12 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13 SERVICE_NAME="filemanager"
14 SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
15
16 # Resolve the user who owns the project directory (i.e. the user who cloned it,
17 # not root). Falls back to the SUDO_USER env var, then 'pi'.
18 RUN_AS="${SUDO_USER:-pi}"
19
20 echo "[install] Project directory : $SCRIPT_DIR"
21 echo "[install] Service will run as user: $RUN_AS"
22
23 # Make sure start.sh is executable
24 chmod +x "$SCRIPT_DIR/start.sh"
25
26 cat > "$SERVICE_FILE" <<EOF
27 [Unit]
28 Description=File Manager
29 After=network.target
30
31 [Service]
32 Type=simple
33 User=${RUN_AS}
34 WorkingDirectory=${SCRIPT_DIR}
35 ExecStart=${SCRIPT_DIR}/start.sh
36 Restart=always
37 RestartSec=5
38
39 [Install]
40 WantedBy=multi-user.target
41 EOF
42
43 echo "[install] Service file written to $SERVICE_FILE"
44
45 systemctl daemon-reload
46 systemctl enable "${SERVICE_NAME}"
47 systemctl restart "${SERVICE_NAME}"
48
49 echo "[install] Done. Service status:"
50 systemctl status "${SERVICE_NAME}" --no-pager
@@ -0,0 +1,50 @@
1#!/usr/bin/env bash
2# installsystemdservice.sh — Installs filemanager as a systemd service.
3# Must be run as root: sudo ./installsystemdservice.sh
4
5set -euo pipefail
6
7if [[ "$(id -u)" -ne 0 ]]; then
8 echo "Error: this script must be run as root (use sudo)." >&2
9 exit 1
10fi
11
12SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13SERVICE_NAME="filemanager"
14SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
15
16# Resolve the user who owns the project directory (i.e. the user who cloned it,
17# not root). Falls back to the SUDO_USER env var, then 'pi'.
18RUN_AS="${SUDO_USER:-pi}"
19
20echo "[install] Project directory : $SCRIPT_DIR"
21echo "[install] Service will run as user: $RUN_AS"
22
23# Make sure start.sh is executable
24chmod +x "$SCRIPT_DIR/start.sh"
25
26cat > "$SERVICE_FILE" <<EOF
27[Unit]
28Description=File Manager
29After=network.target
30
31[Service]
32Type=simple
33User=${RUN_AS}
34WorkingDirectory=${SCRIPT_DIR}
35ExecStart=${SCRIPT_DIR}/start.sh
36Restart=always
37RestartSec=5
38
39[Install]
40WantedBy=multi-user.target
41EOF
42
43echo "[install] Service file written to $SERVICE_FILE"
44
45systemctl daemon-reload
46systemctl enable "${SERVICE_NAME}"
47systemctl restart "${SERVICE_NAME}"
48
49echo "[install] Done. Service status:"
50systemctl status "${SERVICE_NAME}" --no-pager
start.sh added +21 −0
@@ -0,0 +1,21 @@
1 #!/usr/bin/env bash
2 # start.sh — used as the systemd service ExecStart.
3 # Pulls latest code, installs dependencies, then replaces this shell with
4 # the Node process so systemd tracks the correct PID and restart works.
5
6 set -euo pipefail
7
8 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9 cd "$SCRIPT_DIR"
10
11 echo "[start.sh] git reset --hard"
12 git reset --hard
13
14 echo "[start.sh] git pull"
15 git pull
16
17 echo "[start.sh] npm install --omit=dev"
18 npm install --omit=dev
19
20 echo "[start.sh] starting server"
21 exec node server/index.js
@@ -0,0 +1,21 @@
1#!/usr/bin/env bash
2# start.sh — used as the systemd service ExecStart.
3# Pulls latest code, installs dependencies, then replaces this shell with
4# the Node process so systemd tracks the correct PID and restart works.
5
6set -euo pipefail
7
8SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9cd "$SCRIPT_DIR"
10
11echo "[start.sh] git reset --hard"
12git reset --hard
13
14echo "[start.sh] git pull"
15git pull
16
17echo "[start.sh] npm install --omit=dev"
18npm install --omit=dev
19
20echo "[start.sh] starting server"
21exec node server/index.js