Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
install.sh · 6.3 KB · 173 lines
1#!/usr/bin/env bash
2#
3# DBBASIC Object Server — single-VM installer for Debian/Ubuntu.
4#
5# What it does (idempotent — safe to re-run):
6# - installs python3, venv, pip, git
7# - creates the `dbbasic` service user and the standard directory layout
8# - clones (or reuses) the server under /opt/dbbasic-object-server
9# - builds a virtualenv and installs the server
10# - writes /etc/dbbasic-object-server.env with a freshly generated admin
11# token (only if the file does not already exist — never overwrites yours)
12# - installs and starts a systemd unit bound to 127.0.0.1:8001
13# - runs the filesystem checker and a health check
14#
15# What it deliberately does NOT do (these are short, deliberate follow-ups
16# printed at the end, and covered in docs/quickstart.md):
17# - create your admin user / turn on password login
18# - enable source writes, file writes, or package installs
19# - configure a public domain / TLS proxy
20#
21# Read it before you run it. Then: sudo bash scripts/install.sh
22#
23set -euo pipefail
24
25REPO_URL="${DBBASIC_REPO_URL:-https://github.com/askrobots/dbbasic-object-server.git}"
26CODE_DIR="${DBBASIC_CODE_DIR:-/opt/dbbasic-object-server}"
27STATE_DIR="${DBBASIC_STATE_DIR:-/var/lib/dbbasic-object-server}"
28ENV_FILE="${DBBASIC_ENV_FILE:-/etc/dbbasic-object-server.env}"
29UNIT_FILE="/etc/systemd/system/dbbasic-object-server.service"
30SERVICE_USER="dbbasic"
31
32say() { printf '\033[1;36m==>\033[0m %s\n' "$*"; }
33warn() { printf '\033[1;33m warn:\033[0m %s\n' "$*"; }
34
35if [[ "${EUID}" -ne 0 ]]; then
36 echo "Run as root: sudo bash scripts/install.sh" >&2
37 exit 1
38fi
39
40say "Installing system packages"
41apt-get update -qq
42apt-get install -y -qq python3 python3-venv python3-pip git
43
44say "Creating service user and directory layout"
45if ! id "${SERVICE_USER}" >/dev/null 2>&1; then
46 useradd --system --home "${STATE_DIR}" --shell /usr/sbin/nologin "${SERVICE_USER}"
47fi
48mkdir -p "${CODE_DIR}" "${STATE_DIR}/objects" "${STATE_DIR}/data"
49chown -R "${SERVICE_USER}:${SERVICE_USER}" "${CODE_DIR}" "${STATE_DIR}"
50chmod 755 "${CODE_DIR}"
51chmod 750 "${STATE_DIR}" "${STATE_DIR}/objects" "${STATE_DIR}/data"
52
53say "Fetching server code into ${CODE_DIR}"
54if [[ -d "${CODE_DIR}/.git" ]]; then
55 sudo -u "${SERVICE_USER}" git -C "${CODE_DIR}" pull --ff-only
56else
57 sudo -u "${SERVICE_USER}" git clone "${REPO_URL}" "${CODE_DIR}"
58fi
59
60say "Building virtualenv and installing the server"
61if [[ ! -x "${CODE_DIR}/.venv/bin/python" ]]; then
62 sudo -u "${SERVICE_USER}" python3 -m venv "${CODE_DIR}/.venv"
63fi
64sudo -u "${SERVICE_USER}" "${CODE_DIR}/.venv/bin/python" -m pip install -q --upgrade pip
65sudo -u "${SERVICE_USER}" "${CODE_DIR}/.venv/bin/python" -m pip install -q -e "${CODE_DIR}[server]"
66
67if [[ -f "${ENV_FILE}" ]]; then
68 warn "${ENV_FILE} already exists — keeping it (admin token unchanged)"
69else
70 say "Writing ${ENV_FILE} with a freshly generated admin token"
71 ADMIN_TOKEN="$("${CODE_DIR}/.venv/bin/python" -c 'import secrets; print(secrets.token_urlsafe(32))')"
72 cat > "${ENV_FILE}" <<EOF
73# Generated by scripts/install.sh. Edit deliberately; restart the service after changes.
74DBBASIC_OBJECTS_DIR=${STATE_DIR}/objects
75DBBASIC_DATA_DIR=${STATE_DIR}/data
76DBBASIC_BACKUPS_DIR=${STATE_DIR}/data/backups
77DBBASIC_PACKAGES_DIR=${CODE_DIR}/packages
78DBBASIC_ADMIN_TOKEN=${ADMIN_TOKEN}
79
80# First-boot posture: writes and public code execution stay closed until you
81# have login, backups, and proxy access confirmed. Turn these on deliberately
82# (see docs/quickstart.md and docs/single-vm-deployment.md).
83DBBASIC_ENABLE_SOURCE_WRITES=false
84DBBASIC_ENABLE_FILE_WRITES=false
85DBBASIC_ENABLE_PACKAGE_INSTALLS=false
86DBBASIC_ENABLE_PACKAGE_RESTORE=false
87DBBASIC_ENABLE_PASSWORD_LOGIN=false
88DBBASIC_COOKIE_SECURE=true
89
90# Clean page URLs (/notes, /tasks) resolved to objects and seeded view
91# records. Without this every app page 404s before routes are even
92# consulted -- the flag exists for API-only deployments, but the app
93# suite is the product, so it ships ON (found via the e2e browser lane,
94# whose fixture was the only place all the required flags appeared
95# together).
96DBBASIC_ENABLE_SITE_ROUTES=true
97
98# Permissions start in the open; move to audit, then enforcement, once a
99# policy and login are in place (docs/permissions-model.md).
100DBBASIC_ENABLE_PERMISSION_AUDIT=false
101DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=false
102
103# Conservative traffic and safety limits.
104DBBASIC_MAX_REQUEST_BYTES=1048576
105DBBASIC_MAX_CONCURRENT_REQUESTS=64
106DBBASIC_MAX_CONCURRENT_EXECUTIONS=8
107DBBASIC_OBJECT_TIMEOUT_SECONDS=5
108DBBASIC_RATE_LIMIT_REQUESTS=1000
109DBBASIC_RATE_LIMIT_WINDOW_SECONDS=60
110DBBASIC_RATE_LIMIT_TRUST_PROXY_HEADERS=true
111DBBASIC_LOGIN_LOCKOUT_ATTEMPTS=5
112DBBASIC_LOGIN_LOCKOUT_WINDOW_SECONDS=900
113DBBASIC_ENABLE_REALTIME=true
114EOF
115fi
116chown root:"${SERVICE_USER}" "${ENV_FILE}"
117chmod 640 "${ENV_FILE}"
118
119say "Installing systemd unit"
120cat > "${UNIT_FILE}" <<EOF
121[Unit]
122Description=DBBASIC Object Server
123After=network-online.target
124Wants=network-online.target
125
126[Service]
127User=${SERVICE_USER}
128Group=${SERVICE_USER}
129WorkingDirectory=${CODE_DIR}
130EnvironmentFile=${ENV_FILE}
131ExecStart=${CODE_DIR}/.venv/bin/uvicorn object_server:app --host 127.0.0.1 --port 8001 --no-access-log
132Restart=on-failure
133RestartSec=2
134NoNewPrivileges=true
135PrivateTmp=true
136ProtectSystem=full
137ReadWritePaths=${STATE_DIR}
138
139[Install]
140WantedBy=multi-user.target
141EOF
142
143systemctl daemon-reload
144systemctl enable --now dbbasic-object-server
145
146say "Running filesystem checks"
147set -a; . "${ENV_FILE}"; set +a
148( cd "${CODE_DIR}" && .venv/bin/python -m deployment_checks ) || warn "deployment_checks reported issues (see above)"
149
150say "Health check"
151sleep 2
152if curl -fsS http://127.0.0.1:8001/health >/dev/null; then
153 say "Server is up on 127.0.0.1:8001"
154else
155 warn "Health check failed — see: journalctl -u dbbasic-object-server -e"
156fi
157
158cat <<EOF
159
160$(printf '\033[1;32mInstalled.\033[0m') Next, deliberate steps (docs/quickstart.md):
161
162 1. Create your admin user and turn on login:
163 cd ${CODE_DIR}
164 sudo -u ${SERVICE_USER} DBBASIC_DATA_DIR=${STATE_DIR}/data \\
165 .venv/bin/python object_identity_cli.py create-superuser --user-id you --email you@example.com
166 # then set DBBASIC_ENABLE_PASSWORD_LOGIN=true in ${ENV_FILE} and:
167 sudo systemctl restart dbbasic-object-server
168
169 2. Put a domain and TLS in front (Caddy), then enable package installs to
170 add apps. Your admin token is in ${ENV_FILE} (DBBASIC_ADMIN_TOKEN).
171
172 Watch logs: journalctl -u dbbasic-object-server -f
173EOF