service requirements
@@ -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 bash2
# installsystemdservice.sh — Installs filemanager as a systemd service.3
# Must be run as root: sudo ./installsystemdservice.sh4
5
set -euo pipefail6
7
if [[ "$(id -u)" -ne 0 ]]; then8
echo "Error: this script must be run as root (use sudo)." >&29
exit 110
fi11
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 executable24
chmod +x "$SCRIPT_DIR/start.sh"25
26
cat > "$SERVICE_FILE" <<EOF27
[Unit]28
Description=File Manager29
After=network.target30
31
[Service]32
Type=simple33
User=${RUN_AS}34
WorkingDirectory=${SCRIPT_DIR}35
ExecStart=${SCRIPT_DIR}/start.sh36
Restart=always37
RestartSec=538
39
[Install]40
WantedBy=multi-user.target41
EOF42
43
echo "[install] Service file written to $SERVICE_FILE"44
45
systemctl daemon-reload46
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,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 bash2
# start.sh — used as the systemd service ExecStart.3
# Pulls latest code, installs dependencies, then replaces this shell with4
# the Node process so systemd tracks the correct PID and restart works.5
6
set -euo pipefail7
8
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"9
cd "$SCRIPT_DIR"10
11
echo "[start.sh] git reset --hard"12
git reset --hard13
14
echo "[start.sh] git pull"15
git pull16
17
echo "[start.sh] npm install --omit=dev"18
npm install --omit=dev19
20
echo "[start.sh] starting server"21
exec node server/index.js