-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-auth-service.sh
More file actions
executable file
·56 lines (44 loc) · 1.27 KB
/
install-auth-service.sh
File metadata and controls
executable file
·56 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Install dstack auth-simple as a systemd service
set -e
DSTACK_DIR="${DSTACK_DIR:-/opt/dstack}"
AUTH_DIR="${DSTACK_DIR}/auth-simple"
AUTH_PORT="${AUTH_PORT:-3001}"
SERVICE_NAME="dstack-auth"
BUN_PATH="$(which bun 2>/dev/null || echo "/home/$(logname)/.bun/bin/bun")"
BUN_DIR="$(dirname "$BUN_PATH")"
if [ "$(id -u)" -ne 0 ]; then
echo "error: this script must be run as root (sudo)."
exit 1
fi
if [ ! -f "$BUN_PATH" ]; then
echo "error: bun not found at $BUN_PATH. Install bun or set BUN_PATH."
exit 1
fi
if [ ! -f "$AUTH_DIR/index.ts" ]; then
echo "error: $AUTH_DIR/index.ts not found."
exit 1
fi
if [ ! -f "$AUTH_DIR/auth-config.json" ]; then
echo "error: $AUTH_DIR/auth-config.json not found."
exit 1
fi
echo "Creating systemd service $SERVICE_NAME (port $AUTH_PORT)..."
cat > /etc/systemd/system/${SERVICE_NAME}.service <<EOF
[Unit]
Description=dstack auth-simple server
After=network.target
[Service]
Type=simple
WorkingDirectory=${AUTH_DIR}
Environment=PORT=${AUTH_PORT}
Environment=AUTH_CONFIG_PATH=${AUTH_DIR}/auth-config.json
Environment=PATH=${BUN_DIR}:/usr/local/bin:/usr/bin:/bin
ExecStart=${BUN_PATH} run start
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now ${SERVICE_NAME}