mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-11-26 02:29:31 +08:00
* Start a hosted server before the disk restore when a release is ready After a wake, boat restores the disk lazily for about 3.5 minutes. The apply unit waited for the restore when a release was staged, so OpenBot started only after it. The unit now runs `boot`, which skips a staged release during the restore. OpenBot asks root to stage the release, which waits for the restore, and installs it when the server is idle and no client used it for 5 minutes. openbot.service also starts with lightdm, about 8 seconds before boat starts the other enabled units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep the hosted wake safe after a failed boot and during reading - `boot` does nothing while OpenBot runs. boat starts the apply unit a second time after a wake, and a failed `boot` was not active then. - Self-hosted setup releases the update lock before it starts OpenBot, because the start runs `boot`, which waits for the lock. - The automatic install also waits 5 minutes after the start while a client is connected, because a member who only reads is not in use. - Remove the `client-use` label: `host-update-v1` sends it as `other`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Let a member's update request replace the automatic schedule On a hosted server, the automatic schedule waits for client use, also for the use of the member who asks. Also accept an undefined `clientInUse` for exactOptionalPropertyTypes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.8 KiB
Bash
Executable File
83 lines
3.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Installs OpenBot as a self-hosted server. install-server.sh downloads the release, checks it
|
|
# against the release manifest, unpacks it, and runs this file from that release as root:
|
|
#
|
|
# openbot-server-setup <service-user> <unpacked release> [<account server URL>]
|
|
#
|
|
# An empty user or no URL keeps the ones of the installed server: the keyring and the sign-in are in
|
|
# the home folder of that user, for that account server.
|
|
#
|
|
# It uses the install steps of a hosted server (openbot-hosted-update), with `mode` set to `self`:
|
|
# openbot-hosted-server then starts OpenBot for a terminal sign-in, not for a claim. Run it again to
|
|
# reinstall or upgrade; the data in the home folder of the service user stays.
|
|
set -euo pipefail
|
|
|
|
SOURCE=$(cd "$(dirname "$0")" && pwd)
|
|
# shellcheck source=openbot-hosted-update
|
|
source "$SOURCE/openbot-hosted-update"
|
|
|
|
[ "$(id -u)" -eq 0 ] || fail "Run this as root."
|
|
[ "$#" -ge 2 ] && [ "$#" -le 3 ] || fail "usage: $0 <service-user> <unpacked release> [<account server URL>]"
|
|
SERVICE_USER=$1
|
|
RELEASE=$2
|
|
AUTH_API_URL=${3:-}
|
|
installed_user=""
|
|
if [ -r "$INSTALL/hosted/mode" ] && [ "$(<"$INSTALL/hosted/mode")" = self ] && [ -r "$INSTALL/hosted/service-user" ]; then
|
|
installed_user=$(<"$INSTALL/hosted/service-user")
|
|
fi
|
|
if [ -z "$SERVICE_USER" ]; then
|
|
SERVICE_USER=${installed_user:-openbot}
|
|
elif [ -n "$installed_user" ] && [ "$SERVICE_USER" != "$installed_user" ]; then
|
|
fail "OpenBot is installed for the user $installed_user. Install again without --user, or with --user $installed_user."
|
|
fi
|
|
|
|
[[ $SERVICE_USER =~ ^[a-z_][a-z0-9_-]*$ ]] && [ "$SERVICE_USER" != root ] || fail "The service user is not valid."
|
|
[ -x "$RELEASE/openbot" ] || fail "The release has no openbot executable."
|
|
if [ -n "$AUTH_API_URL" ]; then
|
|
[[ $AUTH_API_URL =~ ^https://[^/?#[:space:]]+/?$ ]] || fail "The account server URL must be an HTTPS origin."
|
|
fi
|
|
if [ -f "$INSTALL/hosted/service-user" ] && ! { [ -r "$INSTALL/hosted/mode" ] && [ "$(<"$INSTALL/hosted/mode")" = self ]; }; then
|
|
fail "This computer is an OpenBot hosted server. A self-hosted install would replace it."
|
|
fi
|
|
# Agents run shell commands as this user, so it gets a login shell, and no password.
|
|
if ! id "$SERVICE_USER" >/dev/null 2>&1; then
|
|
useradd --system --create-home --home-dir "/var/lib/$SERVICE_USER" --shell /bin/bash "$SERVICE_USER"
|
|
echo "Created the user $SERVICE_USER."
|
|
fi
|
|
|
|
exec 9>"$LOCK"
|
|
flock 9
|
|
install_packages "$SOURCE/packages.txt"
|
|
install -d -m 0755 "$INSTALL" "$INSTALL/hosted"
|
|
recover
|
|
prepare_release "$RELEASE"
|
|
version=$(version_of "$RELEASE")
|
|
[ -n "$version" ] || fail "The release has no version."
|
|
# An older OpenBot cannot open a database that a newer one migrated.
|
|
installed=$(version_of "$INSTALL/app")
|
|
if [ -n "$installed" ] && newer "$installed" "$version"; then
|
|
fail "OpenBot $installed is installed, and this release has an older version."
|
|
fi
|
|
# The copy below replaces the files that a running OpenBot uses.
|
|
systemctl stop openbot.service 2>/dev/null || true
|
|
stage_release "$RELEASE"
|
|
swap_in
|
|
printf '%s\n' "$SERVICE_USER" >"$INSTALL/hosted/service-user"
|
|
printf 'self\n' >"$INSTALL/hosted/mode"
|
|
chmod 0644 "$INSTALL/hosted/service-user" "$INSTALL/hosted/mode"
|
|
install_hosting "$SOURCE"
|
|
finish_swap
|
|
|
|
# The keyring that keeps the account session. openbot-hosted-server explains the place.
|
|
install -d -o "$SERVICE_USER" -g "$(id -gn "$SERVICE_USER")" -m 0700 /srv/openbot-hosted
|
|
if [ -n "$AUTH_API_URL" ]; then
|
|
printf 'OPENBOT_AUTH_API_URL=%s\n' "${AUTH_API_URL%/}" >"$INSTALL/hosted/openbot.env"
|
|
chmod 0644 "$INSTALL/hosted/openbot.env"
|
|
fi
|
|
# The start runs `boot` through openbot-update-apply.service, and `boot` waits for this lock.
|
|
flock -u 9
|
|
systemctl start openbot.service
|
|
# install_hosting only enables the timer, and the first boot is maybe a long time away.
|
|
systemctl start openbot-update.timer
|
|
echo "Installed OpenBot $version. It runs as the user $SERVICE_USER."
|