#!/bin/sh # Brokkr 0.2.0 - the SourceLess node installer for Linux and macOS. # # GENERATED by scripts/brokkr.mjs, written and checked by scripts/pharos.mjs. Do not edit this # file; edit the generator. `node scripts/pharos.mjs --check` fails when they disagree. # # sh brokkr.sh --network dev install, start and verify # sh brokkr.sh --network dev --dry-run print every command, change nothing # sh brokkr.sh --network dev --verify check an install that already exists # sh brokkr.sh --help the whole flag list # # --------------------------------------------------------------------------------------------- # On being piped from a URL # --------------------------------------------------------------------------------------------- # # The usual shape for this is curl -fsSL https://.../brokkr.sh | sh -s -- --network dev , and # security people are right to object to it: it hands a remote host a shell on your machine, the # bytes that run are not the bytes you read, and a server can serve a different script to curl # than to a browser. This script does not make that objection go away. What it does is make the # defensible version of it available, and every one of these is a property you can check before # you trust it: # # * It is readable. Download it, read it, run it. It is one file, it has no minified section, # and it fetches no second script. Anything it would do to your machine is in this file. # * --dry-run performs nothing and prints every command it would run, in order, with the # arguments filled in. Run that first. If the printed plan is not what you want, nothing has # happened yet. # * It verifies what it downloads. The binary channel will not install bytes it has not # checksummed: pass --sha256, or it stops. There is no --insecure and no fallback that # skips the check. # * It pins what it installed. The chain identity is recorded at install time and --verify # diffs against it, so an upgrade that quietly moves the chain is caught here rather than by # your node halting three days later. # * It refuses rather than guesses. No network, no install. No checksum, no download. A port # it cannot probe is reported UNCHECKED and never as free. # # What it CANNOT give you today, said here rather than in a footnote: there is no signature. # This project publishes no signing key, so there is nothing to verify a release against beyond # a digest you obtained some other way. Until a key exists, "verified" here means "matches the # digest you supplied", which is exactly as strong as the channel you got the digest through. set -eu # --------------------------------------------------------------------------------------------- # Registry values. Generated; every one of these has a source in the tree. # --------------------------------------------------------------------------------------------- BROKKR_VERSION=0.2.0 BIN_NAME=strblk REPO_URL=https://github.com/alexccoin/strblkv1.git OPS_PORT_DEFAULT=8081 # ASTROLABE_DEFAULT_PORT, src/ops/astrolabe.ts DASH_PORT_DEFAULT=8082 # GUNGNIR_DEFAULT_PORT, src/gungnir/server.ts RPC_PORT_DEFAULT=8083 # IRIS_DEFAULT_PORT, src/network/iris.ts LOOPBACK=127.0.0.1 # ASTROLABE_DEFAULT_HOST KEY_ENV=SOURCELESS_KEY_PASSPHRASE # KEYSTORE_ENV, src/node/keystore.ts # The register of realms, from NETWORKS in src/core/snotra.ts. # key|chainId|mode|launched|genesisSource|keyProvenance|genesisHash REALMS='dev|31337|development|yes|built-in|published|8ee28b94b15c1db6cfb7e052d2ade53b5e1a8be5d8698e17a679f4b567a576ea midgard|131313|production|yes|built-in|published|e88a8753925935b0c003961f7988fe3df6f466cf648584a7bf39c486c4772d37 asgard|1313|production|yes|operator|custody|1cf8655125cc1bbbc0ca06a491f53775499785c349b4d0f5748d5ea170e517bf' # The register of STARW node classes, from STARW_CLASSES in src/network/mnemosyne.ts. # class|minRamMib|minDiskMib|retentionBudgetBytes|maxPeers|retainedBlocks|produces|servesSync|keepsFullState|portOffset # # Every field is derived from that module, except the two resource figures: those are a MEASURED # idle resident set (scripts/brokkr.mjs MEASURED_IDLE) plus the class's retention budget plus # 64 MiB of headroom. The budget ALONE is not a machine requirement and is not used as one - a # pulsar reported 0 accounted bytes against its 716,800-byte budget while its PROCESS held # 76,103,680 - and src/network/mnemosyne.ts says so itself, at length. CLASSES='pulsar|192|64|716800|24|0|no|no|no|0 quasar|448|2048|268435456|128|4096|yes|yes|yes|10 supernova|4288|20480|4294967296|512|all|yes|yes|yes|20' # --------------------------------------------------------------------------------------------- # Output. Every line is prefixed, so a log of a run can be read by grepping for the prefix. # --------------------------------------------------------------------------------------------- say() { printf '%s\n' "$*"; } step() { printf '\n== %s\n' "$*"; } ok() { printf ' ok %s\n' "$*"; } info() { printf ' . %s\n' "$*"; } warn() { printf ' WARN %s\n' "$*"; WARNINGS=$((WARNINGS + 1)); } bad() { printf ' FAIL %s\n' "$*"; FAILURES=$((FAILURES + 1)); } die() { printf '\nbrokkr: %s\n' "$*" >&2; exit 2; } WARNINGS=0 FAILURES=0 have() { command -v "$1" >/dev/null 2>&1; } # The env file, written and read. One file is read by systemd's EnvironmentFile= on a systemd # host and by the runner everywhere else, so a value is written in the one form both parsers # read to the same bytes, and it is READ as data - never sourced. Sourcing it is what ran the # 7801 of '--port 7801' as a command on every non-systemd install with --p2p-port. See # ENV_QUOTE_SH and ENV_READER_SH in scripts/brokkr.mjs for the grammar. env_quote() { case $1 in *[!A-Za-z0-9_./:,@%+=-]*) printf '"%s"' "$(printf '%s' "$1" | sed 's/[\\"`$]/\\&/g')" ;; *) printf '%s' "$1" ;; esac } read_env_file() { # A file saved with CRLF line ends - an editor on Windows, a copy through one - reads the same as # with LF: systemd takes the carriage return as trailing whitespace and drops it, so this does too, # rather than keep it in a port, a path or a secret, and leave a quoted value unrecognised. env_cr=$(printf '\r') while IFS= read -r env_line || [ -n "$env_line" ]; do case $env_line in *"$env_cr") env_line=$(printf '%s\n' "$env_line" | sed "s/$env_cr\$//") ;; esac case $env_line in ''|'#'*|';'*) continue ;; *=*) ;; *) continue ;; esac env_name=$(printf '%s\n' "$env_line" | sed 's/=.*//') # SOURCELESS_ names only. The file configures this node and nothing else: a PATH, IFS or # LD_PRELOAD line in it - typed by hand, or left by some other tool - is not this reader's # to set in a shell that is about to exec the node. case $env_name in SOURCELESS_*) ;; *) continue ;; esac case $env_name in *[!A-Za-z0-9_]*) continue ;; esac env_value=$(printf '%s\n' "$env_line" | sed 's/^[^=]*=//') case $env_value in '"'*'"') env_value=$(printf '%s\n' "$env_value" | sed 's/^"//; s/"$//; s/\\\([\\"`$]\)/\1/g') ;; "'"*"'") env_value=$(printf '%s\n' "$env_value" | sed "s/^'//; s/'\$//") ;; esac IFS= read -r "$env_name" <' could add keys to the job. xml_escape() { printf '%s' "$1" | sed "s/&/\&/g; s//\>/g; s/\"/\"/g; s/'/\'/g" } # A file that is about to hold a secret, made owner-only BEFORE the secret is in it. umask covers # a file that does not exist yet, but an existing one keeps its mode through a truncating write: # a re-run over a 0644 file left by an older install wrote the new secret into a world-readable # file and narrowed it afterwards. So whatever is there is removed - a symlink planted in its # place included - and the file is made again, empty, under umask 077. narrow() still reads back # the mode afterwards, because a filesystem without POSIX modes accepts the request and ignores it. # # Created with noclobber (O_EXCL), so a symlink put back between the rm and the create - by an # account that can write the directory - makes the create FAIL rather than be followed: root # writing through a link the node account planted is root clobbering whatever it points at. private_file() { rm -f "$1" ( set -C; umask 077; : > "$1" ) 2>/dev/null || die "could not create $1 afresh: something put it back between removing and creating it. Nothing was written to it." chmod 600 "$1" 2>/dev/null || true } # 0 when $1 is a real file or directory (not a symlink) owned by uid $2 that no group and no other # account can write. What a root --verify requires of the env file and its directory before it # READS them: the file names the program --verify runs, so a file another account can write is a # file that chooses what root executes. owned_only_by() { [ -L "$1" ] && return 1 [ -e "$1" ] || return 1 owned_meta=$(stat -c '%u %a' "$1" 2>/dev/null || stat -f '%u %Lp' "$1" 2>/dev/null || printf '') [ -n "$owned_meta" ] || return 1 owned_uid=$(printf '%s' "$owned_meta" | cut -d' ' -f1) owned_mode=$(printf '%s' "$owned_meta" | cut -d' ' -f2) [ "$owned_uid" = "$2" ] || return 1 case $owned_mode in *[2367]|*[2367][0-7]) return 1 ;; esac return 0 } # A directory a root install may hand to the node's account with chown -R, judged by its PATH: # absolute, no '.', '..', empty component or trailing slash, and not a system directory. This is # defence in depth, not the rule - a list of system directories is never complete (it missed # /var/lib, /var/log and /var/spool/cron, any of which handed to the node account is root). The # rule is chown_plan below: only a directory this run creates, or one that is empty, is chowned. chown_target_ok() { case $1 in /*) ;; *) return 1 ;; esac case $1 in *//*|*/./*|*/.|*/../*|*/..|*/) return 1 ;; /bin|/bin/*|/boot|/boot/*|/dev|/dev/*|/etc|/etc/*|/lib|/lib/*|/lib32|/lib32/*|/lib64|/lib64/*) return 1 ;; /proc|/proc/*|/root|/root/*|/run|/run/*|/sbin|/sbin/*|/sys|/sys/*|/usr|/usr/*|/snap|/snap/*) return 1 ;; /var|/var/lib|/var/log|/var/log/*|/var/spool|/var/spool/*|/var/cache|/var/cache/*|/var/mail|/var/mail/*) return 1 ;; /home|/opt|/srv|/tmp|/mnt|/media) return 1 ;; esac return 0 } # What a root install may do to the data directory, decided BEFORE anything is written, printed as # one word: 'recursive' (it does not exist yet, or it is empty, so everything in it will be this # install's), 'top' (it already belongs to the node account, so nothing is chowned again - chown -R # over a tree that account controls would follow its hard links), or 'refuse:'. A symlink is # refused, so the path checked is the path chowned. chown_plan() { chown_target_ok "$1" || { printf 'refuse:a system directory or not a plain absolute path\n'; return 0; } if [ -L "$1" ]; then printf 'refuse:a symbolic link\n'; return 0; fi if [ ! -e "$1" ]; then printf 'recursive\n'; return 0; fi if [ ! -d "$1" ]; then printf 'refuse:not a directory\n'; return 0; fi if [ -z "$(ls -A "$1" 2>/dev/null)" ]; then printf 'recursive\n'; return 0; fi chown_owner=$(stat -c '%U' "$1" 2>/dev/null || stat -f '%Su' "$1" 2>/dev/null || printf '') if [ "$chown_owner" = "$2" ]; then printf 'top\n'; return 0; fi printf 'refuse:it already holds files that belong to %s\n' "$chown_owner" } # A path a systemd unit or drop-in carries. ReadWritePaths= splits on whitespace and removes # quotes and backslashes, and every unit line reads %x as a specifier: '--dir "/srv/a /etc"' made # the drop-in grant /etc. Refused rather than escaped, before anything is written. unit_path_ok() { case $1 in *[[:space:]\"\'\\%]*) return 1 ;; esac return 0 } # A value handed to git, curl, wget, docker or the node as a positional argument is read as an # OPTION when it starts with '-': '--repo --upload-pack=CMD' is git running CMD. And a newline in # a path, URL or name is a second line in every file it is written to. Both are refused here, # before anything runs, rather than left to every call site to remember '--'. The value itself is # not printed: a URL can carry a token. refuse_unsafe_value() { case $2 in -*) die "$1 cannot start with '-': git, curl, docker and the node would read it as an option, not as a value. A relative path that starts with a dash can be written ./-name." ;; esac case $2 in *" "*) die "$1 carries a newline, which no path, URL or name this installer writes can hold. Nothing was written." ;; esac } # What kind of machine this is, in the vocabulary the release manifest uses. # # 'uname -m' is what the host calls itself and it is NOT what the artifacts are named: Linux says # x86_64 where the manifest says x64, and aarch64 where the manifest says arm64. The mapping is # here, once, and it is the same list as ARCHES in scripts/package-sea.mjs and ELF_MACHINES in # scripts/release.mjs. Anything else is "unknown", which this script treats as "could not look" # and never as "fine" - see where it is used. UNAME_S=$(uname -s 2>/dev/null || printf unknown) HOST_MACHINE=$(uname -m 2>/dev/null || printf unknown) case $HOST_MACHINE in x86_64|amd64) HOST_ARCH=x64 ;; aarch64|arm64) HOST_ARCH=arm64 ;; *) HOST_ARCH=unknown ;; esac # What kind of machine a downloaded FILE will run on, read out of the file. # # ------------------------------------------------------------------------------------------ # The failure this closes, measured 2026-09-21 # ------------------------------------------------------------------------------------------ # # The binary channel checked a SHA-256 and nothing else. So an x86-64 build downloaded onto an # aarch64 host passed the checksum gate, printed "sha256 ... matches", was installed, was made # executable, and then died at the first invocation with # # /usr/local/bin/strblk: cannot execute binary file: Exec format error # # - a message that names neither the cause nor the fix, arriving AFTER this script has told the # operator their download verified. The two builds were also indistinguishable upstream: until # the same day, scripts/package-sea.mjs read process.platform and never process.arch, so both # architectures wrote dist-linux/strblk and both produced a release manifest row reading # "platform": "linux". Both halves are now fixed; this is the half that protects a machine # somebody else's manifest is pointing at. # # It reads the ELF header rather than the file NAME, because a name is what somebody typed and a # header is what the kernel reads. Four magic bytes, then e_machine - a 16-bit little-endian # field at offset 18 - which the linker writes and nothing downstream edits. # # Prints one of: x64, arm64, unknown (an ELF this does not have a name for), notelf (not an ELF # at all), or nolook (no od command, so the question could not be asked). elf_arch() { have od || { printf nolook; return; } _hdr=$(od -An -v -tx1 -N20 "$1" 2>/dev/null | tr -d ' \n') case $_hdr in 7f454c46*) ;; *) printf notelf; return ;; esac # Byte n of the file is characters 2n+1..2n+2 of that hex string, so e_machine - bytes 18 and # 19 - is characters 37 to 40. Little-endian, so x86-64 (0x003e) reads "3e00". case $(printf '%s' "$_hdr" | cut -c37-40) in 3e00) printf x64 ;; b700) printf arm64 ;; *) printf unknown ;; esac } # The same question for a Mach-O file, because macOS now ships an artifact. # # MH_MAGIC_64 is 0xfeedfacf written little-endian, so the first four bytes on disk are # cf fa ed fe. cputype is the next 32-bit field, also little-endian: 07000001 is # CPU_TYPE_X86|CPU_ARCH_ABI64 and 0c000001 is CPU_TYPE_ARM|CPU_ARCH_ABI64. # # A universal ("fat") binary at 0xcafebabe reads notmacho rather than being unpacked. This # project publishes one architecture per file on purpose, so a fat file did not come from here # and guessing which slice an operator wanted is not this script's business. macho_arch() { have od || { printf nolook; return; } _mhdr=$(od -An -v -tx1 -N8 "$1" 2>/dev/null | tr -d ' ') case $_mhdr in cffaedfe07000001) printf x64 ;; cffaedfe0c000001) printf arm64 ;; cffaedfe*) printf unknown ;; *) printf notmacho ;; esac } # Narrows a file to its owner and REPORTS THE MODE THAT IS ACTUALLY THERE. # # "chmod returned 0" and "the file is 0600" are different questions, and this script used to # answer the second by asking the first. MEASURED 2026-09-19, running this very script on a # filesystem that does not carry POSIX modes: chmod 600 succeeded, stat reported 644 afterwards, # and the line this script printed said "stored 0600 at ...". A secret reported as narrowed # while every account on the host can read it is worse than one reported as exposed, because # only the second one gets fixed. src/node/keystore.ts carries the same rule for the node's own # writers; this is the installer's copy of it. # # A mode that did not take is a WARNING and never a refusal: a filesystem that will not honour # it is not something an operator can fix by re-running, and an installer that died there would # be refusing over a control it was never going to have. narrow() { narrow_file=$1 narrow_what=$2 chmod 600 "$narrow_file" 2>/dev/null || true # GNU first, BSD and macOS second. An empty answer means neither could look. narrow_mode=$(stat -c '%a' "$narrow_file" 2>/dev/null || stat -f '%Lp' "$narrow_file" 2>/dev/null || printf '') if [ -z "$narrow_mode" ]; then warn "$narrow_file could not be read back after its mode was set, so this script cannot say" info " whether the $narrow_what in it is owner-only. Check it by hand before" info " relying on this file." return 0 fi case $narrow_mode in *00) return 0 ;; esac warn "$narrow_file is mode $narrow_mode after a request for 0600: this filesystem accepted" info " the request and did not apply it, so the $narrow_what in it is readable" info " by other accounts on this host and is protected only by the directory it" info " lives in. On a host where that is not acceptable, move the install to a" info " filesystem that carries POSIX modes." return 0 } # The class register, read the way the realm register is read: pipe-separated rows and cut. The # alternative is a JSON parser in sh, and the alternative to that is jq, which is a dependency an # installer must not have. class_row() { case $1 in ''|*'|'*) return 0 ;; esac printf '%s\n' "$CLASSES" | while IFS= read -r row; do case $row in "$1|"*) printf '%s\n' "$row" ;; esac done } class_field() { printf '%s\n' "$1" | cut -d'|' -f"$2"; } class_table() { printf '%s\n' "$CLASSES" | while IFS='|' read -r c ram disk budget peers blocks prod sync full off; do printf ' %-10s %5s MiB RAM %6s MiB disk peers %-4s blocks %-5s produces %-4s serves-sync %-4s full-state %-4s ports +%s\n' \ "$c" "$ram" "$disk" "$peers" "$blocks" "$prod" "$sync" "$full" "$off" done } # Every mutation goes through this, so --dry-run is total rather than best-effort. A step that # forgets to call run() is a step that runs during a dry run, which is the one way a dry run can # lie; there is exactly one write below that does not go through here and it is commented. run() { if [ "$DRY" = 1 ]; then printf ' would %s\n' "$*" return 0 fi "$@" } usage() { cat <<'USAGE' brokkr - install and verify a SourceLess node sh brokkr.sh --network [options] sh brokkr.sh --network --verify sh brokkr.sh --network --dry-run Realm --network KEY Which realm. REQUIRED. There is no default: a node refuses to start without one of --network, --genesis or --dev, because the old default silently started the development chain, where any well-signed producer is accepted. --genesis FILE A genesis file. Checked against --network when both are given. Where --prefix PATH Install root. Default /opt/sourceless as root, else ~/.sourceless --dir PATH The node's data directory. Default /data/ How it is obtained --channel C source | binary | docker | auto (default auto) --source-dir PATH An existing checkout to build from, instead of cloning --repo URL Clone from here (default: this project's repository) --ref REF Clone this tag or branch --binary-url URL A prebuilt single-file executable --sha256 HEX Its SHA-256. The binary channel REFUSES to install without one --image NAME Container image for the docker channel Sockets --ops-port N Astrolabe, the operator endpoint (default from the registry) --rpc-port N Iris, the public JSON-RPC endpoint --dashboard-port N Gungnir, the operating surface --p2p-port N The chain socket --auto-ports If the default block is taken, move all three to the next free block rather than refusing. Without this a collision is an error, because a node whose endpoint did not bind still starts and still runs Chain --peers LIST host:port,host:port. Without it this node dials nobody; see the note this script prints, and read it before deciding that is fine --block-interval MS 0 (default) follows only; non-zero means this node seals --class NAME pulsar | quasar | supernova. Selects an INSTANCE: its own data directory, env file, runner, port block and service unit, so one of every class can stand on one machine. Without it the paths are what they have always been. --classes prints what each one costs. --advertise HOST the address peers should reach this node on. Required for a SEED: a node bound to a wildcard advertises nothing, so no peer can tell a third node about it and the mesh never grows past explicit --peers dials Keys --seal file Generate a passphrase, store it 0600 beside the config (default) --seal prompt Ask for one, store nothing --seal env Use the one already in the environment --seal none Keys UNENCRYPTED at rest. Prints what that means and continues. A node that has taken a VALIDATOR SEAT on a production realm will not start like this: Horkos refuses it (src/ops/horkos.ts) Service --service auto systemd as root; else a systemd USER unit where there is one; else none --service systemd Install and enable the unit. Requires root and systemd. With --class this instantiates the template unit: strblk-node@ --service systemd-user A systemd user unit. NO ROOT NEEDED, and it keeps Restart=always, the burst limiter and the stop policy. It stops at logout unless the account lingers: sudo loginctl enable-linger --service launchd Write a LaunchAgent. macOS only, and for ONE node, not seats: seats need install-launchd-mac.sh. See the banner --service none Print the command to run instead. That is a FOREGROUND process and not a service: nothing restarts it and nothing says why it stopped Other --classes Print the STARW classes, what each one keeps, and what each costs --start / --no-start Start after installing (default: start) --verify Verify an install that already exists, then exit --json Machine-readable verification result --strict A warning is a failure --dry-run Print every command, change nothing --help This One of every class on this machine, which is three installs and three services: sh brokkr.sh --network dev --class supernova --block-interval 3000 --p2p-port 43321 sh brokkr.sh --network dev --class quasar --peers 127.0.0.1:43321 --p2p-port 43311 sh brokkr.sh --network dev --class pulsar --peers 127.0.0.1:43321 --p2p-port 43301 Each takes its own port block from the register, so the three do not collide. The repository has a script that does exactly this and then reports on it: node deploy/local/orion.mjs up USAGE } # --------------------------------------------------------------------------------------------- # Flags # --------------------------------------------------------------------------------------------- NETWORK= GENESIS= PREFIX= DATADIR= CHANNEL=auto SOURCE_DIR= REPO=$REPO_URL REF= BINARY_URL= SHA256= IMAGE= OPS_PORT= DASH_PORT= RPC_PORT= P2P_PORT=0 AUTO_PORTS=0 PEERS= BLOCK_INTERVAL=0 NODE_CLASS= # The endpoint this node tells peers to reach it on. Without it a node bound to a wildcard # advertises NOTHING (advertisedEndpoint returns null for 0.0.0.0), so no peer can ever tell a # third node about it and the mesh never grows past explicit --peers dials. ADVERTISE= SEAL=file SERVICE=auto START=1 DRY=0 MODE=install JSON=0 STRICT=0 while [ $# -gt 0 ]; do case $1 in --network) NETWORK=$2; shift 2 ;; --genesis) GENESIS=$2; shift 2 ;; --prefix) PREFIX=$2; shift 2 ;; --dir) DATADIR=$2; shift 2 ;; --channel) CHANNEL=$2; shift 2 ;; --source-dir) SOURCE_DIR=$2; CHANNEL=source; shift 2 ;; --repo) REPO=$2; shift 2 ;; --ref) REF=$2; shift 2 ;; --binary-url) BINARY_URL=$2; CHANNEL=binary; shift 2 ;; --sha256) SHA256=$2; shift 2 ;; --image) IMAGE=$2; CHANNEL=docker; shift 2 ;; --ops-port) OPS_PORT=$2; shift 2 ;; --rpc-port) RPC_PORT=$2; shift 2 ;; --dashboard-port) DASH_PORT=$2; shift 2 ;; --p2p-port) P2P_PORT=$2; shift 2 ;; --auto-ports) AUTO_PORTS=1; shift ;; --peers) PEERS=$2; shift 2 ;; --block-interval) BLOCK_INTERVAL=$2; shift 2 ;; --class) NODE_CLASS=$2; shift 2 ;; --advertise) ADVERTISE=$2; shift 2 ;; --seal) SEAL=$2; shift 2 ;; --service) SERVICE=$2; shift 2 ;; --start) START=1; shift ;; --no-start) START=0; shift ;; --verify) MODE=verify; shift ;; --json) JSON=1; shift ;; --strict) STRICT=1; shift ;; --dry-run) DRY=1; shift ;; --classes) MODE=classes; shift ;; -h|--help) usage; exit 0 ;; *) die "unknown option $1 (--help for the list)" ;; esac done # Answered before the realm is required, because "what does a mini node cost" is a question # somebody asks BEFORE they have decided which chain to join. if [ "$MODE" = classes ]; then say "STARW node classes, from STARW_CLASSES in src/network/mnemosyne.ts" say "" class_table say "" say " RAM is a MEASURED idle resident set plus the class's retention budget plus 64 MiB of" say " headroom. The measurement: a node of each class started from the shipped entry point," say " alone on the host, no peers, empty queue, resident set read 15 s later." say "" say " The retention budget is NOT the machine requirement and is not used as one. A pulsar" say " reported 0 accounted retained bytes against a 716,800-byte budget while its process" say " held 76,103,680 - two true numbers about different quantities. mnemosyne.ts says so." say "" say " Disk for a pulsar is MEASURED and constant: it retains no blocks, so its directory is" say " key material and a lock file and does not grow with height. For the other two the" say " figure is a REASONED floor: they retain blocks, and no bound has been measured at" say " production block sizes." say "" say " Bandwidth is UNMEASURED. Nothing in this repository has metered a node's socket." say "" say " A pulsar also serves no JSON-RPC, whatever --rpc-port says: Iris needs full state and" say " a pulsar keeps none. The node prints that at start and it is not a fault." exit 0 fi # --------------------------------------------------------------------------------------------- # The register # --------------------------------------------------------------------------------------------- realm_row() { # Exact, not a prefix: a key carrying the separator (dev|31337) matched a row and was taken as # a realm name into every path, unit and container name derived from it. case $1 in ''|*'|'*) return 0 ;; esac printf '%s\n' "$REALMS" | while IFS= read -r row; do case $row in "$1|"*) printf '%s\n' "$row" ;; esac done } realm_field() { printf '%s\n' "$1" | cut -d'|' -f"$2"; } realm_table() { printf '%s\n' "$REALMS" | while IFS='|' read -r k id md lc gs kp gh; do if [ "$lc" = yes ]; then printf ' %-9s chain id %-8s %-12s launched\n' "$k" "$id" "$md" else printf ' %-9s chain id %-8s %-12s NOT LAUNCHED - a node refuses to start on it\n' "$k" "$id" "$md" fi done } if [ -z "$NETWORK" ] && [ -z "$GENESIS" ]; then say "brokkr: --network is required, and there is no default." say "" say " The node itself refuses to start without one of --network, --genesis or --dev, and" say " this installer refuses for the same reason. Omitting the flag used to start the" say " DEVELOPMENT chain in development mode, where a block from any well-signed producer is" say " accepted. An installer that supplied a default would put that silent open door back," say " one layer above where the node can see it." say "" say " Realms this build knows (src/core/snotra.ts):" realm_table say "" say " sh brokkr.sh --network dev --dry-run" exit 2 fi ROW= if [ -n "$NETWORK" ]; then ROW=$(realm_row "$NETWORK") if [ -z "$ROW" ]; then say "brokkr: '$NETWORK' is not a realm this build knows." realm_table exit 2 fi REALM_MODE=$(realm_field "$ROW" 3) REALM_LAUNCHED=$(realm_field "$ROW" 4) REALM_GENESIS_SOURCE=$(realm_field "$ROW" 5) REALM_KEYS=$(realm_field "$ROW" 6) REALM_CHAINID=$(realm_field "$ROW" 2) else NETWORK=custom REALM_MODE=production REALM_LAUNCHED=yes REALM_GENESIS_SOURCE=operator REALM_KEYS=custody REALM_CHAINID=- fi if [ -n "$NODE_CLASS" ]; then CLASS_ROW=$(class_row "$NODE_CLASS") if [ -z "$CLASS_ROW" ]; then say "brokkr: '$NODE_CLASS' is not a STARW class this build knows." say "" say " Classes, from STARW_CLASSES in src/network/mnemosyne.ts:" class_table exit 2 fi CLASS_MIN_RAM=$(class_field "$CLASS_ROW" 2) CLASS_MIN_DISK=$(class_field "$CLASS_ROW" 3) CLASS_BUDGET=$(class_field "$CLASS_ROW" 4) CLASS_MAX_PEERS=$(class_field "$CLASS_ROW" 5) CLASS_BLOCKS=$(class_field "$CLASS_ROW" 6) CLASS_PRODUCES=$(class_field "$CLASS_ROW" 7) CLASS_SERVES_SYNC=$(class_field "$CLASS_ROW" 8) CLASS_FULL_STATE=$(class_field "$CLASS_ROW" 9) CLASS_PORT_OFFSET=$(class_field "$CLASS_ROW" 10) else CLASS_ROW= CLASS_MIN_RAM= CLASS_MIN_DISK= CLASS_BUDGET= CLASS_MAX_PEERS= CLASS_BLOCKS= CLASS_PRODUCES= CLASS_SERVES_SYNC= CLASS_FULL_STATE= CLASS_PORT_OFFSET=0 fi # --------------------------------------------------------------------------------------------- # Values that are written into the runner's command line, checked for what they are. # # The runner carries the node's arguments as text, so a --peers value of '127.0.0.1:7801;cmd' # would be the runner running cmd, as root on a root install, at every start - and the env # file's quoting cannot help with a value that never passes through it. A peer list is # host:port pairs (an IPv6 literal in brackets, or a str:// address), a port is digits, and a # host is a name or an address: anything else is refused here, before a file is written, # rather than escaped into something the operator did not type. # --------------------------------------------------------------------------------------------- refuse_unsafe_value --repo "$REPO" refuse_unsafe_value --ref "$REF" refuse_unsafe_value --binary-url "$BINARY_URL" refuse_unsafe_value --image "$IMAGE" refuse_unsafe_value --prefix "$PREFIX" refuse_unsafe_value --dir "$DATADIR" refuse_unsafe_value --source-dir "$SOURCE_DIR" refuse_unsafe_value --genesis "$GENESIS" refuse_unsafe_value SOURCELESS_NODE_BIN "$(printenv SOURCELESS_NODE_BIN 2>/dev/null || printf '')" # The console secret, when it is supplied, is checked HERE rather than where it is used: that is # after the directories and the passphrase file exist, and a refusal there leaves them behind. # Refused by NAME; the value is a secret and is never printed. SUPPLIED_SECRET=$(printenv SOURCELESS_DASHBOARD_SECRET 2>/dev/null || printf '') case $SUPPLIED_SECRET in *" "*) die "SOURCELESS_DASHBOARD_SECRET carries a newline, which an env file cannot hold. Set it without one. Nothing was written." ;; esac # Any other control character, and bytes that are not UTF-8: a tab or a carriage return is dropped # or kept differently by systemd and by the reader, and a header cannot carry either - the console # would hold one secret and the operator another. UTF-8 is checked where iconv exists to check it. if [ -n "$SUPPLIED_SECRET" ]; then if [ "$(printf '%s' "$SUPPLIED_SECRET" | LC_ALL=C tr -d '\001-\037\177')" != "$SUPPLIED_SECRET" ]; then die "SOURCELESS_DASHBOARD_SECRET carries a control character, which neither an env file nor an HTTP header carries intact. Set it without one. Nothing was written." fi if have iconv && ! printf '%s' "$SUPPLIED_SECRET" | iconv -f UTF-8 -t UTF-8 >/dev/null 2>&1; then die "SOURCELESS_DASHBOARD_SECRET is not valid UTF-8. Set it as UTF-8 text. Nothing was written." fi fi SUPPLIED_SECRET= for port_flag in "--p2p-port:$P2P_PORT" "--ops-port:$OPS_PORT" "--rpc-port:$RPC_PORT" "--dashboard-port:$DASH_PORT"; do port_name=$(printf '%s' "$port_flag" | sed 's/:.*//') port_value=$(printf '%s' "$port_flag" | sed 's/^[^:]*://') case $port_value in '') ;; *[!0-9]*) die "$port_name takes a port number, and '$port_value' is not one" ;; *) [ "$port_value" -le 65535 ] 2>/dev/null || die "$port_name takes a port number, and '$port_value' is not one" ;; esac done case $BLOCK_INTERVAL in ''|*[!0-9]*) die "--block-interval takes a whole number of milliseconds, and '$BLOCK_INTERVAL' is not one" ;; esac case $PEERS in *[!]A-Za-z0-9.:,@/_%[-]*) die "--peers takes host:port[,host:port...] with no spaces, and '$PEERS' carries a character no peer address has" ;; esac case $ADVERTISE in # A slash is let through to the URL check below, which says what to type instead. *[!]A-Za-z0-9.:/_%[-]*) die "--advertise takes a bare HOST - a name or an address - and '$ADVERTISE' carries a character no host has" ;; esac # --------------------------------------------------------------------------------------------- # --advertise takes a HOST. Not host:port, not a URL, not a str:// address. # # MEASURED on live mainnet, and it left a host undiscoverable from launch until 6 October. # HestiaNode.advertisedEndpoint builds str://@tcp/: - it appends the port it # is actually bound to, because that is the only port it can honestly name. Hand it # 92.205.25.236:47002 and the endpoint becomes tcp/92.205.25.236:47002:47002, which # parseStrAddress refuses: every peer that received the record discarded it, so no third node # could ever be told this one existed, and the only visible symptom was a mesh that would not grow # past explicit --peers dials. Nothing logged an error, because the node that MADE the bad record # never parses it. # # Refused loudly here rather than normalised quietly. Stripping the port would be a guess about # which of the two numbers the operator meant, and an installer that silently rewrites the one flag # deciding how the world reaches this node is worse than one that stops. if [ -n "$ADVERTISE" ]; then case $ADVERTISE in *://*) die "--advertise takes a bare HOST, not a URL. Drop the scheme: --advertise $(printf '%s' "$ADVERTISE" | sed 's|.*://||; s|[:/].*||')" ;; \[*\]) ;; *:*:*) # A bare IPv6 literal has several colons and no brackets. Accepted, because the node passes # it straight into the endpoint string and the port is appended after it; a bracketed form is # accepted above for the same reason. ;; *:*) ADVERTISE_HOST_PART=$(printf '%s' "$ADVERTISE" | sed 's|:.*||') ADVERTISE_PORT_PART=$(printf '%s' "$ADVERTISE" | sed 's|.*:||') say "brokkr: --advertise takes a HOST, and you gave host:port." say "" say " You passed $ADVERTISE" say " It must be $ADVERTISE_HOST_PART" say "" say " The node appends the port it is actually listening on, because that is the only port" say " it can honestly name. With a port here the advertised address becomes" say " tcp/$ADVERTISE_HOST_PART:$ADVERTISE_PORT_PART:" say " which parseStrAddress refuses, so every peer that receives this node's record" say " discards it and no third node can ever be told this node exists. It happened on" say " mainnet and went unnoticed for two weeks: the node that writes the bad address never" say " parses it, so nothing logs anything." say "" say " If you meant to change the port the node LISTENS on, that is --p2p-port." exit 2 ;; *) ;; esac fi # A class that cannot seal, told to seal. The chain already decides this - planNode clamps the # interval to 0 for a class whose policy says producesBlocks: false - so this is not a new rule, # it is the same rule said at the point of typing rather than discovered as a timer that never # fires. Not a refusal, because the install is correct; the flag is simply inert. if [ -n "$NODE_CLASS" ] && [ "$CLASS_PRODUCES" = no ] && [ "$BLOCK_INTERVAL" != 0 ]; then say "brokkr: --block-interval $BLOCK_INTERVAL with --class $NODE_CLASS has no effect." say "" say " A $NODE_CLASS has producesBlocks: false in src/network/mnemosyne.ts. planNode clamps" say " the interval to 0 before the node is built, so the timer would never have anything to" say " seal from. Installing with 0 instead, which is what the node would have run anyway." BLOCK_INTERVAL=0 fi # --------------------------------------------------------------------------------------------- # Paths # # **One INSTANCE per class.** Without --class the paths are what they always were, so an existing # install keeps every name it had. With --class they carry the class, because the requirement # "one of every class on this machine" is the requirement "three data directories, three env # files, three runners and three units" - and Cerberus refuses a second process on one directory, # so sharing is not an option that merely performs badly. # --------------------------------------------------------------------------------------------- AM_ROOT=0 if [ "$(id -u)" = 0 ]; then AM_ROOT=1; fi if [ -z "$PREFIX" ]; then if [ "$AM_ROOT" = 1 ]; then PREFIX=/opt/sourceless; else PREFIX=$HOME/.sourceless; fi fi INSTANCE=$NETWORK if [ -n "$NODE_CLASS" ]; then INSTANCE=$NETWORK-$NODE_CLASS; fi if [ -z "$DATADIR" ]; then DATADIR=$PREFIX/data/$INSTANCE; fi ETCDIR=$PREFIX/etc BINDIR=$PREFIX/bin SRCDIR=$PREFIX/src ENV_FILE=$ETCDIR/strblk-$INSTANCE.env PASS_FILE=$ETCDIR/strblk-$INSTANCE.pass IDENT_FILE=$ETCDIR/strblk-$INSTANCE.identity RUNNER=$BINDIR/strblk-node-$INSTANCE CONTAINER=strblk-$INSTANCE # The systemd unit. A class instantiates the TEMPLATE unit, so three classes are three instances # of one file rather than three copies that drift apart; without a class it is the single-instance # unit every existing install already names. if [ -n "$NODE_CLASS" ]; then UNIT=strblk-node@$NODE_CLASS UNIT_FILE=/etc/systemd/system/strblk-node@.service UNIT_ENV=/etc/sourceless/strblk-node-$NODE_CLASS.env else UNIT=strblk-node UNIT_FILE=/etc/systemd/system/strblk-node.service UNIT_ENV=/etc/sourceless/strblk-node.env fi if [ -z "$IMAGE" ]; then IMAGE=strblk:local; fi # Which service this install will write, as far as it can be known before anything is: the checks # below depend on it, and they must refuse before a file exists. # # Which service this install writes, resolved HERE - read-only, by the rule the service step # applies - because the checks below depend on what is actually written. Guessing from "systemctl # exists" refused a path with a space for installs that write no unit at all, and ran the root chown # check for --service systemd-user, which chowns nothing. # # Read through printenv rather than as a parameter expansion with a default: set -u makes an # unset variable fatal, and this generator's own rule is that no shell body may contain a dollar # immediately followed by a brace - that is JavaScript's interpolation in the file this is # generated from. Verbose, and it is what keeps the generated text readable against the generator. XDG_RUNTIME=$(printenv XDG_RUNTIME_DIR 2>/dev/null || printf '') if [ "$SERVICE" = auto ]; then if [ "$UNAME_S" = Linux ] && [ "$AM_ROOT" = 1 ] && have systemctl; then SERVICE=systemd # A user manager when there is one, rather than falling all the way to none. # # "none" means the operator starts the runner by hand, which is a detached background process # under another name - and that is the failure this section exists to prevent: an earlier # deployment started a block generator with nohup, it died, nothing restarted it, and block # production stopped with no signal at all. A mini node's whole premise is a small machine, and # a small machine very often has no root. systemctl --user needs none and still gives # Restart=always and the burst limiter. elif [ "$UNAME_S" = Linux ] && have systemctl && [ -n "$XDG_RUNTIME" ] && systemctl --user show-environment >/dev/null 2>&1; then SERVICE=systemd-user else SERVICE=none; fi fi # A unit is written for systemd and systemd-user, never for the docker channel (both refuse it). WRITES_UNIT=0 case $SERVICE in systemd|systemd-user) if [ "$CHANNEL" != docker ]; then WRITES_UNIT=1; fi ;; esac # Only a root --service systemd install chowns anything. CHOWNS_DATADIR=0 if [ "$AM_ROOT" = 1 ] && [ "$SERVICE" = systemd ] && [ "$CHANNEL" != docker ]; then CHOWNS_DATADIR=1; fi # A root install hands the DATA directory - and only that - to the node's account. Decided now, # before anything is written: see chown_plan. ETCDIR is not handed over any more. It holds the env # file that a root --verify reads and the files root writes, and an ETCDIR the node account owned # let that account choose what root executed (a SOURCELESS_SOURCE_DIR of its own) and where root # wrote (a symlink in place of the env file). Nor may the data directory contain ETCDIR, BINDIR or # the source tree, or chowning it would hand them over too. DATADIR_CHOWN=none if [ "$CHOWNS_DATADIR" = 1 ]; then for owned_dir in "$ETCDIR" "$BINDIR" "$SRCDIR" "$SOURCE_DIR"; do case $owned_dir/ in "$DATADIR"/*) die "$DATADIR would be handed to the node's account, and $owned_dir is inside it. Choose a --dir outside the prefix's etc, bin and src." ;; esac done DATADIR_CHOWN=$(chown_plan "$DATADIR" sourceless) case $DATADIR_CHOWN in refuse:*) die "$DATADIR will not be handed to the node's account with chown: $(printf '%s' "$DATADIR_CHOWN" | sed 's/^refuse://'). Choose a --dir that does not exist yet or is empty, or chown it to sourceless yourself." ;; esac if [ -L "$ETCDIR" ]; then die "$ETCDIR is a symbolic link. A root install writes its secrets there and will not write them through a link."; fi fi # A path a unit carries must be one systemd reads back as the same path. See unit_path_ok. if [ "$WRITES_UNIT" = 1 ]; then for unit_dir in "$DATADIR" "$PREFIX"; do unit_path_ok "$unit_dir" || die "$unit_dir carries whitespace, a quote, a backslash or a %, which a systemd unit does not read back as the same path. Choose a path without them." done fi # --------------------------------------------------------------------------------------------- # Ports. # # The three endpoints all bind loopback and all have fixed defaults, so a second node on one # host takes none of them. That is not a hypothetical: MEASURED on the machine this was written # on, a node whose ops and rpc ports were already held started anyway, exit code 0, printing an # alert to stderr and "NOT LISTENING" on stdout - a running node that nothing can read and no # wallet can reach. Under a service manager those lines go to a journal nobody is tailing and # the unit reports active. So the collision is caught here, before the install, and the # verification step at the end catches it again by asking the endpoints to answer. # # The three move together as a block, so a second node's ports stay a readable run rather than # three numbers from three different neighbourhoods. # --------------------------------------------------------------------------------------------- port_free() { # 0 free, 1 taken, 2 could not look if have nc; then if nc -z "$LOOPBACK" "$1" >/dev/null 2>&1; then return 1; fi return 0 fi if have ss; then if ss -ltn 2>/dev/null | grep -q "[:.]$1[[:space:]]"; then return 1; fi return 0 fi if have lsof; then if lsof -iTCP:"$1" -sTCP:LISTEN -n -P >/dev/null 2>&1; then return 1; fi return 0 fi if have node; then if node -e 'const s=require("net").createServer();s.once("error",()=>process.exit(1));s.listen(Number(process.argv[1]),process.argv[2],()=>s.close(()=>process.exit(0)))' "$1" "$LOOPBACK" >/dev/null 2>&1; then return 0 fi return 1 fi # curl last, and it is here because of a MEASURED false pass. On debian:bookworm-slim there is # no nc, no ss, no lsof and no node, so this function returned 2 - UNCHECKED - and a SECOND # install took the default ports while the first node still held them. Every endpoint check # then passed, because it was reading the FIRST node. curl is on that image and on nearly every # machine that can download an installer at all, and its exit code 7 is "failed to connect", # which is exactly the question being asked. if have curl; then curl -sS -o /dev/null --max-time 3 "http://$LOOPBACK:$1/" >/dev/null 2>&1 if [ $? = 7 ]; then return 0; fi return 1 fi return 2 } PROBE_AVAILABLE=1 if ! have nc && ! have ss && ! have lsof && ! have node && ! have curl; then PROBE_AVAILABLE=0; fi block_free() { a=$((OPS_PORT_DEFAULT + $1)) b=$((DASH_PORT_DEFAULT + $1)) c=$((RPC_PORT_DEFAULT + $1)) port_free "$a" || return 1 port_free "$b" || return 1 port_free "$c" || return 1 return 0 } # --------------------------------------------------------------------------------------------- # HTTP, for verification. curl or wget on the host; busybox wget inside the container. # --------------------------------------------------------------------------------------------- http_status() { if [ "$CHANNEL" = docker ]; then if docker exec "$CONTAINER" wget -q -O /dev/null "$1" >/dev/null 2>&1; then printf '200\n'; else printf '000\n'; fi return 0 fi if have curl; then # -s and not -sS: a refused connection is an ANSWER here, not an error worth printing. And # the code comes from exactly one place, because curl writes 000 itself when it never got a # response - a second fallback that also printed 000 produced '000000', which was MEASURED # and is precisely the kind of nonsense an operator has to decode at 3am. code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$1" 2>/dev/null || true) if [ -z "$code" ]; then code=000; fi printf '%s\n' "$code" return 0 fi if have wget; then if wget -q -O /dev/null --timeout=10 "$1" >/dev/null 2>&1; then printf '200\n'; else printf '000\n'; fi return 0 fi printf 'unchecked\n' } # The same probe carrying the console secret. Over curl the header is read from STDIN (-H @-), so # the secret is never in this host's process list. In a container the probe is node, running the # script CONSOLE_PROBE_JS from scripts/brokkr.mjs read on STDIN, and it takes the secret from the # container's own environment. It used to be wget with an Authorization header inside the # container: off docker exec's command line, but on WGET's, and a container's processes are in # the HOST's process list, which every account on the host can read. Without curl on the host # there is no way to send a header that is not an argument, so the answer is 'unchecked'. CONSOLE_PROBE='fetch(process.argv[2],{headers:{authorization:"Bearer "+(process.env.SOURCELESS_DASHBOARD_SECRET||"")},signal:AbortSignal.timeout(10000)}).then((r)=>process.stdout.write(String(r.status)),()=>process.stdout.write("000"))' http_status_auth() { if [ "$CHANNEL" = docker ]; then code=$(printf '%s' "$CONSOLE_PROBE" | docker exec -i "$CONTAINER" node - "$1" 2>/dev/null || true) case $code in [0-9][0-9][0-9]) ;; *) code=000 ;; esac printf '%s\n' "$code" return 0 fi if have curl; then code=$(printf 'Authorization: Bearer %s\n' "$DASH_SECRET" | curl -s -o /dev/null -w '%{http_code}' --max-time 10 -H @- "$1" 2>/dev/null || true) if [ -z "$code" ]; then code=000; fi printf '%s\n' "$code" return 0 fi printf 'unchecked\n' } http_body() { if [ "$CHANNEL" = docker ]; then docker exec "$CONTAINER" wget -q -O - "$1" 2>/dev/null || true return 0 fi if have curl; then curl -sS --max-time 10 "$1" 2>/dev/null || true; return 0; fi if have wget; then wget -q -O - --timeout=10 "$1" 2>/dev/null || true; return 0; fi } http_post_json() { if [ "$CHANNEL" = docker ]; then docker exec "$CONTAINER" wget -q -O - --header 'Content-Type: application/json' --post-data "$2" "$1" 2>/dev/null || true return 0 fi if have curl; then curl -sS --max-time 10 -H 'Content-Type: application/json' -X POST --data "$2" "$1" 2>/dev/null || true return 0 fi if have wget; then wget -q -O - --timeout=10 --header='Content-Type: application/json' --post-data="$2" "$1" 2>/dev/null || true return 0 fi } # No jq. Whitespace is stripped first so a pretty-printed body and a compact one parse the same; # only numeric and hex fields are read this way, so stripping cannot corrupt a value that matters. json_num() { printf '%s' "$1" | tr -d ' \n\r\t' | sed -n 's/.*"'"$2"'":\([0-9][0-9]*\).*/\1/p' | head -1; } json_hex() { printf '%s' "$1" | tr -d ' \n\r\t' | sed -n 's/.*"'"$2"'":"\([0-9a-fA-F][0-9a-fA-F]*\)".*/\1/p' | head -1; } # --------------------------------------------------------------------------------------------- # The strblk invocation for this install # --------------------------------------------------------------------------------------------- STRBLK= # The ABSOLUTE path to the node binary, resolved here and written into everything this script # generates. # # MEASURED, and it cost 371 installs. A bare STRBLK="node $SRCDIR/..." is correct in the shell # that runs this installer and wrong in every shell that will run the node afterwards. launchd # starts a job with PATH=/usr/bin:/bin:/usr/sbin:/sbin and nothing else; systemctl --user starts # one with a PATH that does not come from the login shell either. Node from Homebrew lives at # /opt/homebrew/bin/node and node from a tarball under the operator's home, so on a Mac the # generated runner died with "node: command not found" on EVERY start while the same line typed # by hand worked perfectly. The symptom is a service that exists, is loaded, and has never run. # # The resolution is the same one launch/scripts/install-launchd-mac.sh and # launch/scripts/install-seats-bulk.sh already use, and it is here so that the third copy is not # a fourth divergence: an operator override first, then PATH, then the three places a Mac or a # Linux box actually puts it. NODE_BIN= resolve_node_bin() { NODE_BIN=$(printenv SOURCELESS_NODE_BIN 2>/dev/null || printf '') if [ -z "$NODE_BIN" ]; then NODE_BIN=$(command -v node 2>/dev/null || printf ''); fi if [ -z "$NODE_BIN" ]; then for candidate in /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node "$HOME/nodejs/bin/node"; do [ -x "$candidate" ] && { NODE_BIN=$candidate; break; } done fi # An absolute path or nothing. command -v answers with whatever is on PATH, which on a shell # started inside the install directory can be a relative path, and a relative interpreter in a # unit file resolves against the service manager's working directory rather than this one. case $NODE_BIN in /*) ;; '') ;; *) NODE_BIN=$(cd "$(dirname "$NODE_BIN")" 2>/dev/null && pwd)/$(basename "$NODE_BIN") ;; esac } resolve_strblk() { case $CHANNEL in source) resolve_node_bin # Refused rather than falling back to the bare word. A bare "node" here is an install that # passes every check this script makes and then never starts under a service manager, which # is the worst failure shape available: the installer said ok. [ -n "$NODE_BIN" ] || die "the source channel needs node on PATH, or SOURCELESS_NODE_BIN set to its absolute path. A bare node in the generated runner is what broke 371 macOS installs: launchd has no Homebrew on its PATH." STRBLK="$NODE_BIN $SRCDIR/dist/src/cli/strblk.js" ;; binary) STRBLK="$BINDIR/$BIN_NAME" ;; docker) STRBLK="docker run --rm $IMAGE" ;; esac } network_flags() { if [ -n "$GENESIS" ] && [ "$NETWORK" != custom ]; then printf '%s' "--network $NETWORK --genesis $GENESIS" elif [ -n "$GENESIS" ]; then printf '%s' "--genesis $GENESIS" else printf '%s' "--network $NETWORK" fi } # The node, run from THIS process with every value one argument. $STRBLK and network_flags above # are strings for printing; executing them word-split a --source-dir, a --genesis or a node path # with a space into several arguments (MEASURED: a source dir of '/tmp/s r c' failed the identity # pin with "Cannot find module '/tmp/s'"). run_strblk() { case $CHANNEL in source) "$NODE_BIN" "$SRCDIR/dist/src/cli/strblk.js" "$@" ;; binary) "$BINDIR/$BIN_NAME" "$@" ;; docker) docker run --rm "$IMAGE" "$@" ;; esac } strblk_identity() { if [ -n "$GENESIS" ] && [ "$NETWORK" != custom ]; then run_strblk genesis --network "$NETWORK" --genesis "$GENESIS" --identity elif [ -n "$GENESIS" ]; then run_strblk genesis --genesis "$GENESIS" --identity else run_strblk genesis --network "$NETWORK" --identity fi } # --------------------------------------------------------------------------------------------- # Verification. # # Six checks, and each one is a way an install can succeed and still be wrong: # # 1. the identity digests match what was pinned at install - wrong chain, or a build whose # state transition moved # 2. Astrolabe /health answers - the node runs and cannot be read # 3. Iris /health answers - no wallet or explorer can reach it # 4. the RPC's own genesis hash matches the pin - the node came up on another chain # 5. Gungnir answers - no operating surface # 6. peers - installed, running, alone # # 1 and 4 are the pair worth having. 1 asks the BUILD what chain it computes; 4 asks the RUNNING # NODE what chain it is on. An artifact swapped under a live install fails 1; a node pointed at # the wrong genesis fails 4; a consensus change that moves state at height 0 fails both. # --------------------------------------------------------------------------------------------- # A string field out of a small JSON file. Same reasoning as json_num: no jq, whitespace # stripped first, and only fields whose values cannot contain a quote are read this way. json_str() { printf '%s' "$1" | tr -d ' \n\r\t' | sed -n 's/.*"'"$2"'":"\([^"]*\)".*/\1/p' | head -1; } verify_install() { step "verify $NETWORK" resolve_strblk # 0. WHO HOLDS THE DATA DIRECTORY. # # First, because without it every check after it can pass against somebody else's node. # MEASURED, 2026-09-08, on debian:bookworm-slim: a second install took the default ports while # the first node still held them, its own endpoints bound nothing, and verification reported # identity, /health, /health, the served genesis and one peer - all green, all read off the # FIRST node. A verification a different process can satisfy is not a verification. # # Cerberus writes .cerberus.lock into the data directory and records in it the pid holding the # directory and the operator endpoint that node actually BOUND - null where the bind failed # (lease.publish(endpoint), with endpoint null on the failure path in the CLI). So the lock # answers both halves at once: is a node of ours running, and is the socket about to be # questioned its socket. OPS_BASE=http://$LOOPBACK:$OPS_PORT if [ "$CHANNEL" = docker ]; then OPS_BASE=http://$LOOPBACK:$OPS_PORT_DEFAULT; fi LOCK_FILE=$DATADIR/.cerberus.lock V_HOLDER=unknown if [ ! -f "$LOCK_FILE" ]; then bad "no .cerberus.lock in $DATADIR - nothing holds this data directory, so no node from this install is running" V_HOLDER=fail else LOCK_BODY=$(cat "$LOCK_FILE") LOCK_PID=$(json_num "$LOCK_BODY" pid) LOCK_ENDPOINT=$(json_str "$LOCK_BODY" endpoint) if [ -z "$LOCK_ENDPOINT" ]; then bad "the node holding $DATADIR bound NO operator endpoint (.cerberus.lock records endpoint: null)." info " It is running and it cannot be read. The port it was given is held by" info " something else - most often another node on this same host. Reinstall" info " with --auto-ports, or free the port." V_HOLDER=fail elif [ "$LOCK_ENDPOINT" != "$OPS_BASE" ]; then bad "the node holding $DATADIR is readable at $LOCK_ENDPOINT, not at $OPS_BASE" info " Anything answering at $OPS_BASE belongs to a DIFFERENT node, and" info " verifying against it would report on somebody else's chain." V_HOLDER=fail else ok "pid $LOCK_PID holds $DATADIR and bound $LOCK_ENDPOINT" V_HOLDER=pass fi fi V_IDENT=unknown V_OPS=unknown V_RPC=unknown V_DASH=unknown V_CHAIN=unknown V_PEERS=unknown # 1. identity IDENT_NOW=$(strblk_identity 2>/dev/null || true) if [ -z "$IDENT_NOW" ]; then bad "identity: '$STRBLK genesis --identity' produced nothing - the build is not runnable" V_IDENT=fail elif ! printf '%s ' "$IDENT_NOW" | grep -q '^genesisHash [0-9a-f]\{64\}$'; then # The SHAPE, not just the presence. --identity prints five 'name value' lines and nothing # else, so output with no 64-hex genesisHash in it is not an identity: it is a usage message, # a stack trace, or a CLI whose output moved. Pinning it would pin nonsense - and this guard # exists because the Windows script did exactly that on its first real run. bad "identity: no '64-hex genesisHash' line in the output - that is not an identity" printf '%s ' "$IDENT_NOW" | head -5 | sed 's/^/ /' V_IDENT=fail elif [ -f "$IDENT_FILE" ]; then if printf '%s\n' "$IDENT_NOW" | diff -u "$IDENT_FILE" - >/dev/null 2>&1; then ok "identity matches the pin taken at install" V_IDENT=pass else bad "identity has MOVED from the pin taken at install - this build computes a different chain" printf '%s\n' "$IDENT_NOW" | diff -u "$IDENT_FILE" - || true V_IDENT=fail fi else warn "no identity pin at $IDENT_FILE; recording this one, nothing to compare against yet" private_file "$IDENT_FILE" printf '%s ' "$IDENT_NOW" > "$IDENT_FILE" V_IDENT=recorded fi printf '%s\n' "$IDENT_NOW" | sed 's/^/ /' GENESIS_PINNED=$(printf '%s\n' "$IDENT_NOW" | sed -n 's/^genesisHash //p') # 2-5. the endpoints OPS_URL=$OPS_BASE/health STATUS_URL=$OPS_BASE/api/status RPC_HEALTH_URL=http://$LOOPBACK:$RPC_PORT/health RPC_URL=http://$LOOPBACK:$RPC_PORT/rpc DASH_URL=http://$LOOPBACK:$DASH_PORT/ if [ "$CHANNEL" = docker ]; then RPC_HEALTH_URL=http://$LOOPBACK:$RPC_PORT_DEFAULT/health RPC_URL=http://$LOOPBACK:$RPC_PORT_DEFAULT/rpc DASH_URL=http://$LOOPBACK:$DASH_PORT_DEFAULT/ fi # Iris and Gungnir are not in the lock, so a socket answering on their ports cannot be proved # to be this node's from outside the way the operator endpoint can. What stands behind them is # the port check at install time; where that could not run, say so, rather than let the green # ticks below carry more than they are worth. if [ "$PROBE_AVAILABLE" = 0 ]; then warn "no port probe on this machine, so the rpc and dashboard checks below prove that" info " SOMETHING answers on those ports, not that it is this node. Only the" info " operator endpoint is tied to this install, by the lock file." fi code=$(http_status "$OPS_URL") if [ "$code" = 200 ]; then ok "astrolabe /health 200 on $OPS_PORT"; V_OPS=pass else bad "astrolabe /health returned '$code' on $OPS_PORT - the node cannot be read"; V_OPS=fail; fi code=$(http_status "$RPC_HEALTH_URL") if [ "$code" = 200 ]; then ok "iris /health 200 on $RPC_PORT"; V_RPC=pass else bad "iris /health returned '$code' on $RPC_PORT - no wallet or explorer can reach this node"; V_RPC=fail; fi # With a console secret configured, two requests and both must say the right thing: one # WITHOUT the secret must be refused (401), and one WITH it must be served (200). A 200 without # it is a FAIL - the secret this install wrote is not being enforced, which is worse than no # console. A 401 alone proves only that something refuses; the second request proves it is this # node's console and that the secret it holds is the one in the env file. The secret travels on # curl's stdin and inside the container's own environment, never on a command line. code=$(http_status "$DASH_URL") if [ -n "$DASH_SECRET" ]; then code_auth=$(http_status_auth "$DASH_URL") if [ "$code" = 200 ]; then bad "gungnir answered on $DASH_PORT WITHOUT the console secret - the secret this install configured is not enforced"; V_DASH=fail elif [ "$code_auth" = 200 ] && { [ "$code" = 401 ] || [ "$CHANNEL" = docker ]; }; then ok "gungnir answers on $DASH_PORT with the console secret and refuses a request without it"; V_DASH=pass else warn "gungnir returned '$code' without the console secret and '$code_auth' with it on $DASH_PORT - no operating surface"; V_DASH=warn fi elif [ "$code" = 200 ]; then ok "gungnir answers on $DASH_PORT"; V_DASH=pass else warn "gungnir returned '$code' on $DASH_PORT - no operating surface"; V_DASH=warn; fi if [ "$V_RPC" = pass ]; then body=$(http_post_json "$RPC_URL" '{"jsonrpc":"2.0","id":1,"method":"genesis","params":{}}') served=$(json_hex "$body" genesisHashHex) if [ -z "$served" ]; then warn "the rpc endpoint answered but published no genesis hash" V_CHAIN=warn elif [ "$served" = "$GENESIS_PINNED" ]; then ok "the running node serves genesis $served - the chain it is on is the chain installed" V_CHAIN=pass else bad "the running node is on genesis $served, the install pinned $GENESIS_PINNED - WRONG CHAIN" V_CHAIN=fail fi fi if [ "$V_OPS" = pass ]; then body=$(http_body "$STATUS_URL") peers=$(json_num "$body" peers) height=$(json_num "$body" height) if [ -z "$peers" ]; then warn "the operator endpoint answered but published no peer count" V_PEERS=warn else V_PEERS=$peers if [ "$peers" = 0 ] && [ -n "$PEERS" ]; then bad "0 peers, and --peers named $PEERS - this node reached none of them" elif [ "$peers" = 0 ]; then warn "0 peers. This node validates what it holds and has joined nothing." say " Asgard has a built-in seed list: PUBLIC_SEED_PEERS in src/core/snotra.ts names the" say " seven seeds the Asgard download page publishes, so an Asgard node installed without" say " --peers dials them. Dev and Midgard have none, and rpcUrls and explorerUrls are empty" say " for every realm, so a dev or Midgard node installed without --peers has nobody to" say " dial. It still verifies everything it holds -- that is what makes the network" say " hostless -- but it joins nothing, and its height stays where the genesis put it." say " " say " Pass --peers host:port,... to name the mesh yourself; it always replaces the" say " built-in list. This installer will not fabricate a peer." else ok "$peers peer(s), height $height" fi fi fi if [ "$JSON" = 1 ]; then verdict=pass if [ "$FAILURES" -gt 0 ]; then verdict=fail elif [ "$WARNINGS" -gt 0 ] && [ "$STRICT" = 1 ]; then verdict=fail elif [ "$WARNINGS" -gt 0 ]; then verdict=warn; fi printf '{"network":"%s","chainId":"%s","genesisHash":"%s","holder":"%s","identity":"%s","astrolabe":"%s","iris":"%s","gungnir":"%s","chain":"%s","peers":"%s","failures":%s,"warnings":%s,"verdict":"%s"}\n' \ "$NETWORK" "$REALM_CHAINID" "$GENESIS_PINNED" "$V_HOLDER" "$V_IDENT" "$V_OPS" "$V_RPC" "$V_DASH" "$V_CHAIN" "$V_PEERS" "$FAILURES" "$WARNINGS" "$verdict" fi if [ "$FAILURES" -gt 0 ]; then return 1; fi if [ "$WARNINGS" -gt 0 ] && [ "$STRICT" = 1 ]; then return 1; fi return 0 } # --------------------------------------------------------------------------------------------- # Verify-only # --------------------------------------------------------------------------------------------- load_env_file() { if [ ! -f "$ENV_FILE" ]; then die "no install found at $ENV_FILE - run without --verify first" fi # As root, the file and its directory must be root's alone BEFORE they are read: the file names # the source tree and channel whose code --verify then RUNS, so a file the node account (or anyone # else) can write would choose what root executes. An install from before ETCDIR stayed root's is # refused here until it is re-run as root, which takes the directory back. if [ "$AM_ROOT" = 1 ]; then for verify_path in "$ETCDIR" "$ENV_FILE"; do owned_only_by "$verify_path" 0 || die "$verify_path is not root's alone (a link, another owner, or group- or world-writable). --verify as root will not run code an env file there names. Re-run the install as root to take it back, or run --verify as the account that owns it." done fi # Read as data, never sourced. See read_env_file. The secret defaults to empty so a file from # before the console secret existed reads under set -u; verify asks only whether one is set. SOURCELESS_DASHBOARD_SECRET= read_env_file "$ENV_FILE" DASH_SECRET=$SOURCELESS_DASHBOARD_SECRET if [ -n "$SOURCELESS_OPS_PORT" ]; then OPS_PORT=$SOURCELESS_OPS_PORT; fi if [ -n "$SOURCELESS_RPC_PORT" ]; then RPC_PORT=$SOURCELESS_RPC_PORT; fi if [ -n "$SOURCELESS_DASHBOARD_PORT" ]; then DASH_PORT=$SOURCELESS_DASHBOARD_PORT; fi if [ -n "$SOURCELESS_DATA_DIR" ]; then DATADIR=$SOURCELESS_DATA_DIR; fi if [ -n "$SOURCELESS_CHANNEL" ]; then CHANNEL=$SOURCELESS_CHANNEL; fi if [ -n "$SOURCELESS_PREFIX" ]; then PREFIX=$SOURCELESS_PREFIX BINDIR=$PREFIX/bin SRCDIR=$PREFIX/src fi if [ -n "$SOURCELESS_SOURCE_DIR" ]; then SRCDIR=$SOURCELESS_SOURCE_DIR; fi if [ -n "$SOURCELESS_PEERS" ]; then PEERS=$SOURCELESS_PEERS; fi if [ -n "$SOURCELESS_GENESIS" ]; then GENESIS=$SOURCELESS_GENESIS; fi if [ -n "$SOURCELESS_IMAGE" ]; then IMAGE=$SOURCELESS_IMAGE; fi } if [ "$MODE" = verify ]; then load_env_file if verify_install; then exit 0; else exit 1; fi fi # --------------------------------------------------------------------------------------------- # 1. The plan # --------------------------------------------------------------------------------------------- say "brokkr $BROKKR_VERSION - SourceLess node installer" if [ "$DRY" = 1 ]; then say "" say "DRY RUN. Nothing below is performed. Every line marked 'would' is a command this" say " script would run, with its arguments as they would be passed." fi step "realm" info "network $NETWORK" info "chain id $REALM_CHAINID" info "runtime mode $REALM_MODE" if [ "$REALM_LAUNCHED" != yes ]; then say "" say "brokkr: '$NETWORK' is not launched, and this installer will not pretend otherwise." say "" say " Snotra's record for it carries a refusal rather than a genesis, and" say " assertNetworkIsLaunched turns that into a non-zero exit before a socket opens. There" say " is nothing to install: a node started on this realm would stop at the same refusal." say "" say " Realms that are launched:" realm_table exit 2 fi if [ "$REALM_MODE" = development ]; then warn "development mode: this node accepts a block from ANY well-signed producer." info " Right for a local mesh. An open door anywhere a stranger can reach." fi if [ "$REALM_KEYS" = published ]; then warn "this realm's keys are PUBLISHED: every address on it derives from a string in this" info " repository. Anyone holding the repository can sign for every account and" info " every validator seat. No balance and no signature on it is evidence of" info " anything. Do not put value on it." fi if [ "$REALM_GENESIS_SOURCE" = operator ] && [ -z "$GENESIS" ]; then die "realm $NETWORK carries no genesis in this build; pass --genesis FILE" fi # --------------------------------------------------------------------------------------------- # 2. Channel # --------------------------------------------------------------------------------------------- step "channel" node_is_new_enough() { have node || return 1 v=$(node -e 'const [a,b]=process.versions.node.split(".").map(Number);process.exit(a>22||(a===22&&b>=11)?0:1)' >/dev/null 2>&1; printf '%s' $?) [ "$v" = 0 ] } if [ "$CHANNEL" = auto ]; then if [ -n "$SOURCE_DIR" ] && node_is_new_enough; then CHANNEL=source elif node_is_new_enough && have git; then CHANNEL=source elif have docker; then CHANNEL=docker elif [ -n "$BINARY_URL" ]; then CHANNEL=binary else say "brokkr: nothing on this machine can produce a node." say "" say " source needs node >= 22.11 and git - node: $(have node && node --version || printf 'absent'), git: $(have git && printf present || printf absent)" say " docker needs docker - docker: $(have docker && printf present || printf absent)" say " binary needs --binary-url and --sha256, and there is no published release to take" say " them from yet; see docs/INSTALL.md section 'the binary channel'." exit 3 fi fi info "channel $CHANNEL" case $CHANNEL in source) node_is_new_enough || die "the source channel needs node >= 22.11 on PATH" if [ -z "$SOURCE_DIR" ]; then have git || die "the source channel needs git to clone $REPO"; fi ;; binary) [ -n "$BINARY_URL" ] || die "the binary channel needs --binary-url" if [ -z "$SHA256" ]; then say "brokkr: the binary channel refuses to install a download it has not checksummed." say "" say " Pass --sha256 . There is no --insecure and no fallback that skips the check," say " because a fallback is what an attacker uses: an installer that verifies when it" say " can and proceeds when it cannot verifies nothing." say "" say " This project publishes no SHA256SUMS and no signing key today, so the digest has" say " to reach you some other way, and 'verified' here means no more than 'matches the" say " digest you supplied'. docs/INSTALL.md says what would have to be published for" say " that to be worth more." exit 2 fi have sha256sum || have shasum || die "need sha256sum or shasum to check the download" have curl || have wget || die "need curl or wget to fetch $BINARY_URL" ;; docker) have docker || die "the docker channel needs docker on PATH" ;; *) die "unknown channel '$CHANNEL'" ;; esac # --------------------------------------------------------------------------------------------- # 3. Ports # --------------------------------------------------------------------------------------------- step "ports" # The docker channel binds nothing on this host. Every endpoint listens on the CONTAINER's own # loopback, in the container's own network namespace, so the host's ports are not in the # question and probing them would refuse an install for a collision that cannot happen. MEASURED # on 2026-09-08: this branch did not exist, a node from an earlier install held the whole default # block on the host, and the docker channel refused with a collision it could never have had. # # The other half of the same fact is why nothing is published with -p: the endpoints bind # loopback INSIDE the container and a non-loopback bind is REFUSED without a TLS statement, so a # published port would forward to a socket that is not there. Verification therefore goes through # docker exec. To reach these from the host you need a TLS terminator in front and # --ops-behind-tls-proxy, which is an assertion this installer will not make on your behalf. if [ "$CHANNEL" = docker ]; then OPS_PORT=$OPS_PORT_DEFAULT DASH_PORT=$DASH_PORT_DEFAULT RPC_PORT=$RPC_PORT_DEFAULT info "container the three endpoints listen on the CONTAINER's loopback, at the registry" info " defaults. Nothing is published to this host and no host port is taken," info " so nothing here was probed. Verification runs through docker exec." elif [ -z "$OPS_PORT" ] && [ -z "$RPC_PORT" ] && [ -z "$DASH_PORT" ]; then if [ "$PROBE_AVAILABLE" = 0 ]; then warn "no nc, ss, lsof or node on this machine, so no port could be probed. UNCHECKED." info " The verification step at the end asks each endpoint to answer, which is" info " what actually decides whether they bound." OPS_PORT=$OPS_PORT_DEFAULT DASH_PORT=$DASH_PORT_DEFAULT RPC_PORT=$RPC_PORT_DEFAULT else # The search STARTS at this class's own offset, so one of every class installs on one host # without an operator working out a port plan: pulsar takes the registry defaults, quasar # +10, supernova +20. The offsets come from CLASS_PORT_OFFSET in scripts/brokkr.mjs and are # in the class register above, so they cannot drift away from what the units and the local # network script use. Without --class the search starts at 0 exactly as it always did. OFFSET= n=$((CLASS_PORT_OFFSET / 10)) n_limit=$((n + 20)) while [ $n -lt $n_limit ]; do candidate=$((n * 10)) if block_free "$candidate"; then OFFSET=$candidate; break; fi n=$((n + 1)) done if [ -z "$OFFSET" ]; then die "no free block of three ports found between the defaults and +190" fi if [ "$OFFSET" != "$CLASS_PORT_OFFSET" ] && [ "$AUTO_PORTS" != 1 ]; then a=$((OPS_PORT_DEFAULT + OFFSET)); b=$((DASH_PORT_DEFAULT + OFFSET)); c=$((RPC_PORT_DEFAULT + OFFSET)) d=$((OPS_PORT_DEFAULT + CLASS_PORT_OFFSET)); e=$((DASH_PORT_DEFAULT + CLASS_PORT_OFFSET)); f=$((RPC_PORT_DEFAULT + CLASS_PORT_OFFSET)) say "brokkr: this class's port block is not free on this machine." say "" say " Something already listens on one of $d / $e / $f." say " This is refused rather than worked around, because a node whose endpoint fails to" say " bind STILL STARTS: it prints an alert, reports NOT LISTENING, and runs. Under a" say " service manager that is a unit reporting active with a node nobody can read." say "" say " Either free those ports, or install into the next free block:" say "" say " --ops-port $a --dashboard-port $b --rpc-port $c" say "" say " or let this script do it: --auto-ports" exit 2 fi OPS_PORT=$((OPS_PORT_DEFAULT + OFFSET)) DASH_PORT=$((DASH_PORT_DEFAULT + OFFSET)) RPC_PORT=$((RPC_PORT_DEFAULT + OFFSET)) if [ "$OFFSET" != "$CLASS_PORT_OFFSET" ]; then warn "this class's block was taken; moved all three to +$OFFSET so they stay a readable block" elif [ "$OFFSET" != 0 ]; then info "ports +$OFFSET, this class's own block from the register" fi fi else # The class's own offset for whichever of the three was not named, so naming one port does not # silently drop the other two back onto another class's block. if [ -z "$OPS_PORT" ]; then OPS_PORT=$((OPS_PORT_DEFAULT + CLASS_PORT_OFFSET)); fi if [ -z "$DASH_PORT" ]; then DASH_PORT=$((DASH_PORT_DEFAULT + CLASS_PORT_OFFSET)); fi if [ -z "$RPC_PORT" ]; then RPC_PORT=$((RPC_PORT_DEFAULT + CLASS_PORT_OFFSET)); fi for p in "$OPS_PORT" "$DASH_PORT" "$RPC_PORT"; do if port_free "$p"; then : elif [ $? = 2 ]; then warn "port $p UNCHECKED - nothing on this machine can probe it" else bad "port $p is already in use; the endpoint on it will not bind"; fi done if [ "$FAILURES" -gt 0 ]; then die "$FAILURES port(s) in use; pick others or free them"; fi fi info "ops $LOOPBACK:$OPS_PORT astrolabe, /health and /metrics" info "rpc $LOOPBACK:$RPC_PORT iris, the public json-rpc endpoint" info "dashboard $LOOPBACK:$DASH_PORT gungnir, the operating surface" if [ "$CHANNEL" = docker ]; then info " inside the container these stay at the registry defaults; see below" fi # --------------------------------------------------------------------------------------------- # 3b. What this class costs, against what this machine has # # **The check that decides whether a mini node is a mini node.** The whole claim of the pulsar # class is that it runs on hardware that could not hold a chain, and a claim like that is worth # nothing unless something refuses when the hardware cannot hold even the pulsar. So the class # register above carries a MEASURED floor per class, and this compares it with what is actually # free. # # It WARNS by default and fails under --strict. Refusing outright would be wrong: /proc/meminfo # is absent on macOS, cgroup limits make a container's host RAM a lie in both directions, and a # node told to run on a machine the operator knows better than this script does is a legitimate # thing to want. What is not legitimate is installing it silently and finding out at the first # out-of-memory kill. # # Where nothing can be read the answer is UNCHECKED and never "enough", on the same rule the # port probe follows. # --------------------------------------------------------------------------------------------- if [ -n "$NODE_CLASS" ]; then step "resources for a $NODE_CLASS" info "class budget $CLASS_BUDGET bytes retained, max peers $CLASS_MAX_PEERS, blocks kept $CLASS_BLOCKS" info "requires $CLASS_MIN_RAM MiB RAM, $CLASS_MIN_DISK MiB disk" info " RAM = the measured idle resident set + this class's retention budget +" info " 64 MiB headroom. The budget alone is NOT a machine requirement: a pulsar" info " reported 0 accounted bytes against 716,800 while its process held" info " 76,103,680. See src/network/mnemosyne.ts, which says so itself." TOTAL_RAM_MIB= if [ -r /proc/meminfo ]; then TOTAL_RAM_MIB=$(awk '/^MemTotal:/ { printf "%d", $2 / 1024 }' /proc/meminfo 2>/dev/null) elif have sysctl; then RAM_BYTES=$(sysctl -n hw.memsize 2>/dev/null || printf '') if [ -n "$RAM_BYTES" ]; then TOTAL_RAM_MIB=$((RAM_BYTES / 1048576)); fi fi if [ -z "$TOTAL_RAM_MIB" ]; then warn "RAM UNCHECKED - no /proc/meminfo and no sysctl hw.memsize on this machine" elif [ "$TOTAL_RAM_MIB" -lt "$CLASS_MIN_RAM" ]; then warn "this machine has $TOTAL_RAM_MIB MiB of RAM; a $NODE_CLASS is profiled at $CLASS_MIN_RAM MiB" info " Nothing here reserves memory, so it will start. What it will do under" info " load is unmeasured on hardware this size, and the first symptom of" info " getting it wrong is the kernel killing the node, not a message." if [ -n "$(class_row pulsar)" ] && [ "$NODE_CLASS" != pulsar ]; then info " --class pulsar is the class for a machine this size: it keeps no" info " chain, follows a constant-size checkpoint, and is profiled at" info " $(class_field "$(class_row pulsar)" 2) MiB." fi else ok "RAM $TOTAL_RAM_MIB MiB available, $CLASS_MIN_RAM MiB profiled for a $NODE_CLASS" fi FREE_DISK_MIB= if have df; then # -P for the POSIX one-line format; the default wraps a long device name onto its own line # and the field numbering then shifts, which is how a disk check reads the mount point as a # byte count. FREE_DISK_MIB=$(df -Pk "$PREFIX" 2>/dev/null || df -Pk . 2>/dev/null) FREE_DISK_MIB=$(printf '%s\n' "$FREE_DISK_MIB" | awk 'NR == 2 { printf "%d", $4 / 1024 }') fi if [ -z "$FREE_DISK_MIB" ]; then warn "disk UNCHECKED - df could not read the filesystem under $PREFIX" elif [ "$FREE_DISK_MIB" -lt "$CLASS_MIN_DISK" ]; then warn "$FREE_DISK_MIB MiB free under $PREFIX; a $NODE_CLASS is profiled at $CLASS_MIN_DISK MiB" else ok "disk $FREE_DISK_MIB MiB free, $CLASS_MIN_DISK MiB profiled for a $NODE_CLASS" fi if [ "$CLASS_BLOCKS" = all ]; then info " disk is a FLOOR and not a bound: this class retains every block, so its" info " directory grows with the chain for as long as it runs." elif [ "$CLASS_BLOCKS" != 0 ]; then info " disk is a FLOOR and not a bound: this class retains $CLASS_BLOCKS blocks." else info " disk does NOT grow with the chain for this class: it retains no blocks" info " at all, and its directory is key material and a lock file." fi info "bandwidth UNMEASURED. Nothing in this repository has metered a node's socket, so no" info " figure is given for it. What IS bounded is the peer table: at most" info " $CLASS_MAX_PEERS peers at 11,264 bytes a record and 8,192 a session." fi # --------------------------------------------------------------------------------------------- # 4. Directories # --------------------------------------------------------------------------------------------- step "directories" run mkdir -p "$PREFIX" "$ETCDIR" "$BINDIR" "$DATADIR" # A root install keeps ETCDIR to root before a file is written into it. An install from before # this rule chowned it to the node account, which could have left links in it. -h and no -L: a link # is re-owned itself and never followed; private_file then removes it. if [ "$AM_ROOT" = 1 ]; then run chown -R -h 0:0 "$ETCDIR" run chmod 755 "$ETCDIR" fi run chmod 700 "$DATADIR" info "prefix $PREFIX" info "data $DATADIR" # --------------------------------------------------------------------------------------------- # 5. Keys at rest # # Sealed is the default path because unsealed is the one that costs something later. Without the # passphrase the node writes its ed25519, ML-DSA-65 and ML-KEM-768 secrets in the clear and # prints a full-width banner saying so at every start - and a banner at every start is a banner # nobody reads by the third day. # # Since 2026-09-10 it is more than a banner on the host that matters most. A node started in # production mode that has taken a VALIDATOR SEAT - a seat.json and a seat-key.json installed on # this host - REFUSES to start while either keystore is in the clear, before it opens a store or # a socket. So --seal none on a validator is not "unprotected", it is "will not run". Followers # and explorers are unaffected: they claim no seat, so they start and are warned. # # What sealing here buys, exactly, so nobody over-reads it: the keystore is encrypted at rest # under scrypt, so a copy of the DATA DIRECTORY alone - a backup, an image layer, a snapshot on # a shared volume - is not an identity. It does not protect against anyone who can read this # whole prefix, because the passphrase file is in it; --seal prompt is the answer to that, at # the cost of a node that cannot restart unattended. # --------------------------------------------------------------------------------------------- step "keys at rest" PASSPHRASE= case $SEAL in env) eval "PASSPHRASE=\$$KEY_ENV" [ -n "$PASSPHRASE" ] || die "--seal env, but $KEY_ENV is not set in this environment" ok "using the passphrase already in $KEY_ENV; nothing written to disk" ;; prompt) printf ' passphrase for the node keystore: ' stty -echo 2>/dev/null || true read -r PASSPHRASE stty echo 2>/dev/null || true printf '\n' [ -n "$PASSPHRASE" ] || die "empty passphrase" ok "held for this run only; nothing written to disk. This node cannot restart unattended." ;; file) if [ "$DRY" = 1 ]; then info "would generate 32 bytes from /dev/urandom and write $PASS_FILE with mode 0600" elif [ -f "$PASS_FILE" ]; then PASSPHRASE=$(cat "$PASS_FILE") ok "reusing the passphrase at $PASS_FILE - the existing keystore stays readable" else if have base64; then PASSPHRASE=$(head -c 32 /dev/urandom | base64 | tr -d '\n=' ) else PASSPHRASE=$(head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n') fi [ -n "$PASSPHRASE" ] || die "could not read 32 bytes from /dev/urandom" # Not through run(): the dry-run branch above covers this, and routing a secret through a # function that echoes its arguments is how a passphrase ends up in a terminal scrollback. private_file "$PASS_FILE" printf '%s' "$PASSPHRASE" > "$PASS_FILE" narrow "$PASS_FILE" "keystore passphrase" ok "generated 32 bytes from /dev/urandom, sealed the keystore, wrote $PASS_FILE" fi ;; none) warn "keys will be stored UNENCRYPTED at rest. And see the dashboard secret below: it is" info " generated regardless of --seal, because the two protect different things." info " Anyone who can read $DATADIR - a backup, an image layer, another user" info " on this host - can sign blocks and peer records as this node. The node" info " prints a full-width banner about it at every single start." info " And if this host ever takes a VALIDATOR SEAT on a production realm it" info " will not start at all: a node holding a seat key in the clear is" info " refused before it opens a store or a socket. Re-run with --seal file." ;; *) die "unknown --seal '$SEAL' (file, prompt, env, none)" ;; esac # --------------------------------------------------------------------------------------------- # 5b. The operating console's shared secret # --------------------------------------------------------------------------------------------- # # WHY THIS IS GENERATED AND NOT OFFERED. # # --dashboard-secret is optional in the node and no installer in this repository had ever set # one, so every brokkr install shipped an operating console whose ONLY perimeter was the # loopback bind. That perimeter is one reverse proxy away from nothing at all, and it fails # open rather than closed: an unauthenticated GET / hands out the session token the console # uses, and that token is everything a POST needs. It was reproduced - an operator action # executed from an anonymous GET carrying a scraped CSRF token. The console has no idea it is # behind a proxy; the operator who put one there has no idea the console was relying on not # being. Nobody is going to notice the gap from inside. # # A generated secret costs an operator nothing on a loopback-only box - they never see it - and # it is the whole difference on the day somebody puts a proxy in front. So it is generated # always, like the keystore passphrase and by exactly the same means, rather than being a flag # an operator has to know to reach for. It is written to a 0600 file so a re-run reuses it # instead of locking out a proxy that was already configured with the old one. # # WHAT IT IS NOT. It is a bearer secret: anything that can read the env file, the process # environment or this file can act as the console. It is not a replacement for TLS, and it is # not an identity - the console still needs --dashboard-key to act at all. It raises the cost # of an anonymous request that reaches the port from zero to "steal a file first". step "console secret" DASH_SECRET= DASH_SECRET_ENV=SOURCELESS_DASHBOARD_SECRET DASH_SECRET_FILE=$ETCDIR/strblk-$INSTANCE.dashboard-secret DASH_SECRET_SUPPLIED=$(printenv "$DASH_SECRET_ENV" 2>/dev/null || printf '') if [ -n "$DASH_SECRET_SUPPLIED" ]; then DASH_SECRET=$DASH_SECRET_SUPPLIED ok "using the secret already in $DASH_SECRET_ENV. It is kept in the owner-only env file, which is" info " how the node still has it after a restart; $DASH_SECRET_FILE is not written" elif [ "$DRY" = 1 ]; then info "would generate 32 bytes from /dev/urandom and write $DASH_SECRET_FILE with mode 0600" elif [ -f "$DASH_SECRET_FILE" ]; then DASH_SECRET=$(cat "$DASH_SECRET_FILE") ok "reusing the console secret at $DASH_SECRET_FILE - anything already configured with it keeps working" else if have base64; then DASH_SECRET=$(head -c 32 /dev/urandom | base64 | tr -d '\n=' ) else DASH_SECRET=$(head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n') fi [ -n "$DASH_SECRET" ] || die "could not read 32 bytes from /dev/urandom for the console secret" # Not through run(): run() echoes its arguments, and this is a secret. private_file "$DASH_SECRET_FILE" printf '%s' "$DASH_SECRET" > "$DASH_SECRET_FILE" narrow "$DASH_SECRET_FILE" "console secret" ok "generated 32 bytes from /dev/urandom, wrote $DASH_SECRET_FILE" fi # A newline cannot be expressed in a systemd EnvironmentFile value, and a silently truncated # secret is a console that refuses every request an operator sends it with the secret they hold. case $DASH_SECRET in *" "*) die "the console secret in $DASH_SECRET_FILE carries a newline, which systemd cannot hold in an EnvironmentFile. Remove the file and re-run to generate one that does not." ;; esac if [ -n "$DASH_SECRET" ]; then info " every request to the console must now carry it, as" info " 'Authorization: Bearer SECRET' or ?secret=SECRET. Read it with:" info " sudo cat $DASH_SECRET_FILE" info " This does not make the console safe to expose. It makes a proxy in front" info " of it survivable. --dashboard-host is still loopback and should stay there." fi # --------------------------------------------------------------------------------------------- # 6. Obtain the runtime # --------------------------------------------------------------------------------------------- step "runtime" case $CHANNEL in source) if [ -n "$SOURCE_DIR" ]; then SRCDIR=$SOURCE_DIR info "building in place from $SRCDIR" else if [ -d "$SRCDIR/.git" ]; then run git -C "$SRCDIR" fetch --tags --quiet if [ -n "$REF" ]; then run git -C "$SRCDIR" checkout --quiet "$REF"; fi else if [ -n "$REF" ]; then run git clone --quiet --branch "$REF" "$REPO" "$SRCDIR" else run git clone --quiet "$REPO" "$SRCDIR" fi fi fi # --ignore-scripts for the reason .github/workflows/ci.yml and the Dockerfile both give: # install hooks are where the npm supply-chain worms of 2025-26 ran, and nothing in this # tree needs a build step at install time. run sh -c 'cd "$1" && npm ci --ignore-scripts' _ "$SRCDIR" run sh -c 'cd "$1" && npm run build' _ "$SRCDIR" ;; binary) TMP=$BINDIR/$BIN_NAME.download if have curl; then run curl -fsSL -o "$TMP" "$BINARY_URL" else run wget -q -O "$TMP" "$BINARY_URL"; fi if [ "$DRY" != 1 ]; then if have sha256sum; then GOT=$(sha256sum "$TMP" | cut -d' ' -f1) else GOT=$(shasum -a 256 "$TMP" | cut -d' ' -f1); fi if [ "$GOT" != "$SHA256" ]; then rm -f "$TMP" say "brokkr: CHECKSUM MISMATCH - the download was deleted and nothing was installed." say " expected $SHA256" say " got $GOT" exit 2 fi ok "sha256 $GOT matches" # The checksum says the bytes are the ones that were published. It does not say this # machine can run them, and those are different questions with the same reassuring answer. # Checked HERE, after the digest and before the install, so a refusal leaves nothing behind # and does not contradict a line that has already been printed. # # Linux and macOS, each judged by its own format. Windows is the .ps1 and is deliberately # not given the same refusal: an ARM64 Windows host RUNS x64 binaries under emulation, so a # mismatch there is a performance remark and not a failure. # # This read "Linux only. macOS ships no artifact from this project at all" until # 2026-09-23, when one started shipping. # # Darwin is NOT a copy of the Linux rule, because the asymmetry is real. An x86-64 Mach-O # runs on Apple silicon under Rosetta 2, so that direction is Windows' case - a remark. An # arm64 Mach-O on an Intel Mac cannot run at all, so that direction is Linux's case - a # refusal. Treating them alike would either refuse a working install or install a binary # that cannot start. if [ "$UNAME_S" = Darwin ]; then FILE_ARCH=$(macho_arch "$TMP") case $FILE_ARCH in notmacho) rm -f "$TMP" say "brokkr: THAT IS NOT AN EXECUTABLE - the download was deleted and nothing was installed." say " The binary channel installs one file and runs it. What arrived has no Mach-O header," say " so it is an archive, an HTML error page or a redirect body - not a macOS program." say " --binary-url must point at the executable itself." exit 2 ;; nolook) warn "architecture UNCHECKED - no od on this host, so the download's Mach-O header" warn " could not be read." ;; unknown) warn "architecture UNCHECKED - the download is a Mach-O this installer has no name for," warn " or a universal binary. This project publishes one architecture per file." ;; *) if [ "$HOST_ARCH" = unknown ]; then warn "architecture UNCHECKED - the download is $FILE_ARCH and uname -m says" warn " '$HOST_MACHINE', which this installer has no name for." elif [ "$FILE_ARCH" = "$HOST_ARCH" ]; then ok "architecture $FILE_ARCH matches this host ($HOST_MACHINE)" elif [ "$FILE_ARCH" = x64 ] && [ "$HOST_ARCH" = arm64 ]; then warn "architecture MISMATCH, and this one runs anyway: the download is x64 and this" warn " Mac is arm64, so it starts under Rosetta 2 if that is installed." warn " Take strblk-macos-arm64 for a native build." else rm -f "$TMP" say "brokkr: WRONG ARCHITECTURE - the download was deleted and nothing was installed." say "" say " this machine $HOST_MACHINE ($HOST_ARCH)" say " the download $FILE_ARCH" say "" say " The checksum matched: these are the published bytes, for a different kind of" say " processor. An arm64 build does not run on an Intel Mac under any emulation." say "" say " Take strblk-macos-$HOST_ARCH, and its sha256 from the release manifest." exit 2 fi ;; esac fi if [ "$UNAME_S" = Linux ]; then FILE_ARCH=$(elf_arch "$TMP") case $FILE_ARCH in notelf) rm -f "$TMP" say "brokkr: THAT IS NOT AN EXECUTABLE - the download was deleted and nothing was installed." say " The binary channel installs one file and runs it. What arrived has no ELF header," say " so it is an archive, an HTML error page or a redirect body - not a Linux program." say " --binary-url must point at the executable itself." exit 2 ;; nolook) warn "architecture UNCHECKED - no od on this host, so the download's ELF header could" warn " not be read. If this machine is $HOST_MACHINE and the file is not, it will" warn " install cleanly and then fail with 'Exec format error'." ;; unknown) warn "architecture UNCHECKED - the download is an ELF for a machine this installer has" warn " no name for. This host is $HOST_MACHINE." ;; *) if [ "$HOST_ARCH" = unknown ]; then warn "architecture UNCHECKED - the download is $FILE_ARCH and uname -m says" warn " '$HOST_MACHINE', which this installer has no name for." elif [ "$FILE_ARCH" != "$HOST_ARCH" ]; then rm -f "$TMP" say "brokkr: WRONG ARCHITECTURE - the download was deleted and nothing was installed." say "" say " this machine $HOST_MACHINE ($HOST_ARCH)" say " the download $FILE_ARCH" say "" say " The checksum matched: these are the published bytes. They are the published" say " bytes for a different kind of processor, and this kernel will not start them." say " Installed anyway, the first run would say 'Exec format error' and nothing else." say "" say " Take the $HOST_ARCH artifact. In the release manifest that is the row whose" say " \"arch\" reads $HOST_ARCH, published as strblk-linux-$HOST_ARCH, and its sha256" say " is the one to pass to --sha256." exit 2 else ok "architecture $FILE_ARCH matches this host ($HOST_MACHINE)" fi ;; esac fi fi run mv "$TMP" "$BINDIR/$BIN_NAME" run chmod 755 "$BINDIR/$BIN_NAME" ;; docker) if [ -n "$SOURCE_DIR" ]; then run docker build -t "$IMAGE" "$SOURCE_DIR" else run docker image inspect "$IMAGE" >/dev/null fi ;; esac resolve_strblk info "strblk $STRBLK" # --------------------------------------------------------------------------------------------- # 7. Pin the chain identity # # Taken from the BUILD before the node starts, and written next to the config. --verify diffs # against it. Three digests and not one, for the reason .github/workflows/ci.yml gives at # length: genesisHash covers the spec and moves when the declared network changes, and does NOT # move when the code that EXECUTES that spec changes - and a change to how state is computed is # exactly a consensus change. genesisStateRoot and genesisBlockHash are what move then. # --------------------------------------------------------------------------------------------- step "chain identity" if [ "$DRY" = 1 ]; then info "would run: $STRBLK genesis $(network_flags) --identity > $IDENT_FILE" else IDENT_NOW=$(strblk_identity) if ! printf '%s\n' "$IDENT_NOW" | grep -q '^genesisHash [0-9a-f]\{64\}$'; then printf '%s\n' "$IDENT_NOW" | head -5 die "strblk genesis --identity printed no 64-hex genesisHash. Refusing to pin that as this install's chain identity." fi private_file "$IDENT_FILE" printf '%s\n' "$IDENT_NOW" > "$IDENT_FILE" printf '%s\n' "$IDENT_NOW" | sed 's/^/ /' ok "pinned at $IDENT_FILE" fi # --------------------------------------------------------------------------------------------- # 8. Configuration # --------------------------------------------------------------------------------------------- step "configuration" # For the docker channel these are the CONTAINER's arguments: the data directory is the mount # point inside it, and the three endpoint ports are left at the registry defaults because nothing # else is in that network namespace to collide with. Passing this host's paths and ports into a # container was MEASURED writing a runner script that named a Windows directory the container # could not see. if [ "$CHANNEL" = docker ]; then NODE_ARGS="--dir /data $(network_flags) --block-interval $BLOCK_INTERVAL" else NODE_ARGS="--dir $DATADIR $(network_flags) --ops-port $OPS_PORT --rpc-port $RPC_PORT --dashboard-port $DASH_PORT --block-interval $BLOCK_INTERVAL" fi if [ -n "$PEERS" ]; then NODE_ARGS="$NODE_ARGS --peers $PEERS"; fi if [ -n "$NODE_CLASS" ]; then NODE_ARGS="$NODE_ARGS --class $NODE_CLASS"; fi if [ "$P2P_PORT" != 0 ]; then NODE_ARGS="$NODE_ARGS --port $P2P_PORT"; fi # --advertise, which was parsed and then dropped. MEASURED 2026-09-12 on darwin 25.6.0, before # this line existed: 'brokkr.sh --advertise seed.example.org --p2p-port 63001 --peers H:P # --class supernova --dry-run' printed # # command ... --block-interval 0 --peers 10.0.0.1:63001 --class supernova --port 63001 # # with no --advertise anywhere in it. The flag reached exactly one place — the literal # \${ADVERTISE:+--advertise \$ADVERTISE} written into the env file below for the systemd unit to # interpolate — and the runner script every non-systemd install is started by never saw it. # # The cost is precisely the failure docs/RUNBOOK_VPS.md section 5 names as the common first one: # "A node with no peers is ... almost always --advertise or 63001 not being open." A node that # advertises nothing returns null from advertisedEndpoint, so no peer it talks to can pass its # address on, and a seed installed this way can only ever be reached by whoever already knew # where it was. RUNBOOK_VPS.md section 4 calls the flag "required, not optional" for a seed. if [ -n "$ADVERTISE" ]; then NODE_ARGS="$NODE_ARGS --advertise $ADVERTISE"; fi # The four flags the systemd unit interpolates, RESOLVED HERE rather than written into the env # file as shell syntax. # # They used to be written into the env file as shell parameter expansions - a dollar, a brace, a # variable name, ":+", the flag, the variable again. **systemd does not expand shell # syntax in an EnvironmentFile** - it is a simple NAME=VALUE parser with quoting, not a shell - so # every systemd install got SOURCELESS_CLASS_FLAG set to that punctuation verbatim, which systemd # then word-split into the node's argument list. strblk refuses an unknown flag # with exit 2, the unit restarts, and StartLimitBurst leaves it failed: a node that could not # start, for a reason nothing in the output names. Two of the four were worse than broken - # CLASS and ADVERTISE are not variables in this script at all, they are NODE_CLASS and ADVERTISE # - so the class an operator asked for could never have reached a systemd-started node. # # An empty value is the right empty: systemd drops an empty variable from an ExecStart entirely, # so an absent flag is absent rather than being an empty argument the CLI has to interpret. P2P_PORT_FLAG= PEERS_FLAG= ADVERTISE_FLAG= CLASS_FLAG= if [ "$P2P_PORT" != 0 ]; then P2P_PORT_FLAG="--port $P2P_PORT"; fi if [ -n "$PEERS" ]; then PEERS_FLAG="--peers $PEERS"; fi if [ -n "$ADVERTISE" ]; then ADVERTISE_FLAG="--advertise $ADVERTISE"; fi if [ -n "$NODE_CLASS" ]; then CLASS_FLAG="--class $NODE_CLASS"; fi if [ "$DRY" = 1 ]; then info "would write $ENV_FILE" info "would write $RUNNER" else ENTRY=$SRCDIR/dist/src/cli/strblk.js BIN_PATH=$BINDIR/$BIN_NAME # A newline cannot be expressed in an EnvironmentFile value, so a path carrying one is refused # rather than written as two lines - the second of which either reader would take as its own # assignment. The secret and the passphrase are checked where they are read. for env_value in "$NETWORK" "$DATADIR" "$ENTRY" "$NODE_BIN" "$BIN_PATH" "$GENESIS" "$PREFIX" "$SRCDIR" "$IMAGE"; do case $env_value in *" "*) die "a path or name for the env file carries a newline, which neither systemd nor this installer can hold in one: $env_value" ;; esac done umask 077 private_file "$ENV_FILE" cat > "$ENV_FILE" </src, found nothing, and # reported the identity check as FAILED against an install that was in fact healthy. SOURCELESS_SOURCE_DIR=$(env_quote "$SRCDIR") SOURCELESS_IMAGE=$(env_quote "$IMAGE") SOURCELESS_SEAL=$(env_quote "$SEAL") # The console's shared secret, read by the node from this name (src/cli/strblk.ts reads # process.env.SOURCELESS_DASHBOARD_SECRET before it reads --dashboard-secret). It is HERE and # not on the ExecStart line on purpose: an argument is in the process list of every account on # the host, and this file is 0600. Section 5b says what it does and does not protect. $DASH_SECRET_ENV=$(env_quote "$DASH_SECRET") EOF if [ "$SEAL" = file ]; then # RESOLVED here, not written as shell syntax. # # This line used to write the literal characters $(cat /etc/sourceless/...pass) into the # env file. systemd's EnvironmentFile parser is a NAME=VALUE reader with quoting, not a # shell: it performs no substitution. So the node received those characters AS its # passphrase, could not open a keystore sealed with the real one, and failed to start with # a decryption error naming nothing an operator could act on. Every systemd install using # --seal file was affected. The identical bug in the four node flags was found and fixed a # dozen lines above; this branch was missed. # # A passphrase carrying a newline cannot be expressed in an EnvironmentFile at all, so it # is refused rather than silently truncated into a different passphrase. PASS_VALUE=$(cat "$PASS_FILE") case $PASS_VALUE in *" "*) die "the passphrase in $PASS_FILE carries a newline, which systemd cannot hold in an EnvironmentFile. Re-seal with one that does not." ;; esac printf '%s=%s\n' "$KEY_ENV" "$(env_quote "$PASS_VALUE")" >> "$ENV_FILE" unset PASS_VALUE fi narrow "$ENV_FILE" "keystore passphrase and console secret" ok "wrote $ENV_FILE" # The runner is a FIXED body - see runnerSh in scripts/brokkr.mjs - that reads this env file and # rebuilds the node's arguments from it, every value one quoted word. The env-file path is the one # install value written into it, single-quoted by sh_quote. Pasting values in as text is what let # a --source-dir or SOURCELESS_NODE_BIN carrying $(...) run as a command at every start. { printf '#!/bin/sh\n' printf '# Written by brokkr %s. Every value below comes from the env file, read as data.\n' "$BROKKR_VERSION" printf 'ENV_FILE=%s\n' "$(sh_quote "$ENV_FILE")" cat <<'BROKKR_RUNNER' set -euf read_env_file() { # A file saved with CRLF line ends - an editor on Windows, a copy through one - reads the same as # with LF: systemd takes the carriage return as trailing whitespace and drops it, so this does too, # rather than keep it in a port, a path or a secret, and leave a quoted value unrecognised. env_cr=$(printf '\r') while IFS= read -r env_line || [ -n "$env_line" ]; do case $env_line in *"$env_cr") env_line=$(printf '%s\n' "$env_line" | sed "s/$env_cr\$//") ;; esac case $env_line in ''|'#'*|';'*) continue ;; *=*) ;; *) continue ;; esac env_name=$(printf '%s\n' "$env_line" | sed 's/=.*//') # SOURCELESS_ names only. The file configures this node and nothing else: a PATH, IFS or # LD_PRELOAD line in it - typed by hand, or left by some other tool - is not this reader's # to set in a shell that is about to exec the node. case $env_name in SOURCELESS_*) ;; *) continue ;; esac case $env_name in *[!A-Za-z0-9_]*) continue ;; esac env_value=$(printf '%s\n' "$env_line" | sed 's/^[^=]*=//') case $env_value in '"'*'"') env_value=$(printf '%s\n' "$env_value" | sed 's/^"//; s/"$//; s/\\\([\\"`$]\)/\1/g') ;; "'"*"'") env_value=$(printf '%s\n' "$env_value" | sed "s/^'//; s/'\$//") ;; esac IFS= read -r "$env_name" </dev/null 2>&1 || true docker_env=$(mktemp) trap 'rm -f "$docker_env"' EXIT INT TERM HUP umask 077 : > "$docker_env" # printenv rather than the variable: set -u makes an unset one fatal, and with --seal none # there is no passphrase at all. An absent secret writes no line. key_value=$(printenv SOURCELESS_KEY_PASSPHRASE 2>/dev/null || printf '') if [ -n "$key_value" ]; then printf '%s=%s\n' SOURCELESS_KEY_PASSPHRASE "$key_value" >> "$docker_env"; fi dash_value=$(printenv SOURCELESS_DASHBOARD_SECRET 2>/dev/null || printf '') if [ -n "$dash_value" ]; then printf '%s=%s\n' SOURCELESS_DASHBOARD_SECRET "$dash_value" >> "$docker_env"; fi unset key_value dash_value docker run -d --name "$SOURCELESS_CONTAINER" -v "$SOURCELESS_DATA_DIR:/data" --env-file "$docker_env" "$SOURCELESS_IMAGE" node "$@" ;; *) printf 'strblk runner: the env file %s names no channel this runner knows\n' "$ENV_FILE" >&2; exit 2 ;; esac BROKKR_RUNNER } > "$RUNNER" chmod 700 "$RUNNER" ok "wrote $RUNNER" fi if [ "$CHANNEL" = docker ]; then info "command docker run -d --name $CONTAINER -v $DATADIR:/data $IMAGE node $NODE_ARGS" else info "command $STRBLK node $NODE_ARGS" fi # --------------------------------------------------------------------------------------------- # 9. Service # --------------------------------------------------------------------------------------------- step "service" # Already read at the top, where the architecture gate needs it. One read, one value: two # separate calls to uname in one script is two things that could disagree. UNAME=$UNAME_S # --service auto was resolved before anything was written, where the path and chown checks need # to know which service this install writes. See "Which service this install writes" above. case $SERVICE in systemd) [ "$UNAME" = Linux ] || die "--service systemd on $UNAME" have systemctl || die "--service systemd, but systemctl is not on PATH" [ "$AM_ROOT" = 1 ] || die "--service systemd needs root (--service systemd-user needs none)" [ "$CHANNEL" != docker ] || die "--service systemd with the docker channel: use the container runtime's own restart policy" run mkdir -p /etc/sourceless if [ "$DRY" = 1 ]; then info "would write $UNIT_FILE (ExecStart for the $CHANNEL channel)" info "would write $UNIT_ENV" info "would enable $UNIT" else # With --class this is the TEMPLATE unit and the instance is the class, so three classes # share one file. Without it, the single-instance unit every existing install names. if [ -n "$NODE_CLASS" ]; then if [ "$CHANNEL" = binary ]; then cat > "$UNIT_FILE" <<'UNIT_TEMPLATE_BINARY' # Generated by scripts/pharos.mjs. Do not edit; edit the script. # # ONE INSTANCE PER STARW CLASS. The instance name after the @ is the class, and it selects # the environment file: strblk-node@pulsar reads /etc/sourceless/strblk-node-pulsar.env. # # Install: # sudo cp deploy/systemd/strblk-node@.service /etc/systemd/system/ # sudo cp deploy/systemd/strblk-node-pulsar.env /etc/sourceless/ # edit it first # sudo systemctl daemon-reload # sudo systemctl enable --now strblk-node@pulsar # # All three at once, which is the whole point of the template: # sudo systemctl enable --now strblk-node@pulsar strblk-node@quasar strblk-node@supernova # # Each instance needs its OWN data directory and its OWN ports. The generated env files # carry both, in a block per class, so three instances on one host do not collide. # # REASONED, not measured: there is no systemd on the host this was generated on, so nothing here # has been started by systemd. What is measured is what the node does when it is signalled, and # every directive below is chosen against one of those measurements. See # docs/RUNBOOK_OBSERVABILITY.md, which labels each claim. [Unit] Description=SourceLess chain node (strblk), STARW class %i Documentation=file:///opt/sourceless/docs/RUNBOOK_OBSERVABILITY.md After=network-online.target Wants=network-online.target # The burst limiter, and it is in [Unit] because that is where systemd reads it. # # MEASURED, 2026-09-08: these two directives were in [Service], where `systemd-analyze verify` # (systemd 252, debian:bookworm-slim) reports # Unknown key 'StartLimitIntervalSec' in section [Service], ignoring. # They moved to [Unit] in systemd 229 and the old spelling is silently ignored, so for as long as # this unit has existed its documented burst limiter has done NOTHING: a node that cannot start # would have restarted every 5 s for ever, flooding the journal with the reason nobody could # then find. Nothing had ever parsed this file until it was run through systemd-analyze. # # What they do: after 5 failures inside 10 minutes systemd gives up and leaves the unit failed, # which is a state the deploy/prometheus/ absence rule sees. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=simple EnvironmentFile=/etc/sourceless/strblk-node-%i.env WorkingDirectory=/opt/sourceless # Exec'd directly rather than through a shell or through npm. A shell wrapper becomes the main # process, systemd signals IT, and the node underneath is orphaned — which matters here more # than usual: an orphaned node keeps the Cerberus lease on its data directory, so the restart # this unit performs is then REFUSED by the lock, and the operator sees "another process holds # this directory" naming a pid nobody knows about. ExecStart=/opt/sourceless/bin/strblk node \ --dir ${SOURCELESS_DATA_DIR} \ --network ${SOURCELESS_NETWORK} \ --ops-port ${SOURCELESS_OPS_PORT} \ --rpc-port ${SOURCELESS_RPC_PORT} \ --dashboard-port ${SOURCELESS_DASHBOARD_PORT} \ --block-interval ${SOURCELESS_BLOCK_INTERVAL_MS} \ $SOURCELESS_P2P_PORT_FLAG \ $SOURCELESS_PEERS_FLAG \ $SOURCELESS_ADVERTISE_FLAG \ $SOURCELESS_CLASS_FLAG # SIGTERM, and let it finish. It spends that time snapshotting local state and releasing the # Cerberus lease rather than abandoning them. # # MEASURED: stop() + release() took 3.2-3.8 ms across three runs on an EMPTY chain # (docs/RUNBOOK_BACKUP.md section 3). That is a floor, and at Asgard's size it is NOT the cost: # on 2026-11-16 six of the seven asgard-vps genesis seats - this node, over the same chain - were # still in their shutdown at 90 s and were killed with SIGKILL ("State 'stop-sigterm' timed # out"), so the node's own shutdown deadline did not end them first either (OPS-2). Why is not # yet measured. 300s since 2026-11-18, the same as the seat units # (deploy/strblk-seat@.service): size it from the first timed clean stop. # # The headroom is not politeness. Draupnir writes a snapshot to a temp file, fsyncs it, renames # it over the target, and THEN trims the log the snapshot covers. A SIGKILL between the rename # and the trim leaves a snapshot that has been published and a log that still holds the records # it covers — and recovery reads that as a sequence gap, stops at it, and REWRITES the log # without the records after it. That is measured in docs/RUNBOOK_BACKUP.md section 5: silent # loss, with the node reporting a clean start afterwards. A stop timeout shorter than a snapshot # takes is therefore a data-loss setting, and it is the one an operator tightens first. KillSignal=SIGTERM TimeoutStopSec=300 # Every process in this unit's control group gets the signal, and gets the SIGKILL at the end of # the timeout if it is still there. # # This is systemd's default and it is written out anyway, for two reasons. It makes a future # change to it a deliberate edit rather than an inherited one. And it is the directive # docs/RUNBOOK_ROLLBACK.md's stop step depends on being true: that runbook's preflight decides # "the node is stopped" by the ABSENCE of a lock file, and a lock file is left behind by exactly # one thing — a node process that outlived the stop. KillMode=process would leave one on every # rollback where anything had been wrapped around ExecStart. KillMode=control-group # Restart always, and wait 5 s between attempts. # # `always` rather than `on-failure` deliberately. A node that exits 0 has still stopped being a # validator, and this unit's job is that a validator is running — `systemctl stop` is how an # operator says otherwise, and it is not affected by this. # # The burst limiter is what keeps a node that cannot start from becoming a restart loop that # hides its own reason in a flood of journal lines. After 5 failures in 10 minutes systemd gives # up and leaves the unit failed, which is a state the alert rule below sees as absence. Restart=always RestartSec=5 # A validator holds signing keys. Nothing here needs root, a writable /usr, or a device. User=sourceless Group=sourceless NoNewPrivileges=yes PrivateTmp=yes ProtectSystem=strict ProtectHome=yes # A LITERAL path, because ReadWritePaths= does not expand environment variables. # # MEASURED, 2026-09-08: with ${SOURCELESS_DATA_DIR} here, `systemd-analyze verify` reports # ReadWritePaths= path is not absolute, ignoring: ${SOURCELESS_DATA_DIR} # and the directive is dropped. Dropped, under ProtectSystem=strict, means the node has NO # writable path at all: it would fail on its first write to its own data directory. So the unit # as it stood could not have run a node, and nothing would have discovered that until an # operator installed it. # # The literal is the default in deploy/systemd/strblk-node.env. A data directory anywhere else # needs the path added, and `brokkr.sh --service systemd` writes exactly that as a drop-in at # /etc/systemd/system/strblk-node.service.d/10-datadir.conf rather than editing this file. # The `-` prefix is load-bearing and was added on 2026-09-09, the first time this unit was # ever STARTED by systemd rather than parsed by it. # # MEASURED on Debian 12, systemd 252: the node failed every start with # Failed to set up mount namespacing: /run/systemd/unit-root/var/lib/sourceless: # No such file or directory # Failed at step NAMESPACE spawning /usr/bin/node # exit 226/NAMESPACE, five restarts, then start-request-repeated-too-quickly. ReadWritePaths= # is ADDITIVE, so brokkr's drop-in appends the real data directory rather than replacing this # line - and under ProtectSystem=strict systemd must bind-mount EVERY path listed. This default # is not created by anything when the data directory is elsewhere, which is the ordinary case # and the one brokkr writes. # # A leading dash means ignore-if-absent (systemd.exec(5)). The previous comment # below is the same directive's PREVIOUS defect, found by systemd-analyze verify. That check # parses and does not run, which is exactly why it could not have found this one. # Both, and both ignore-if-absent. The per-instance directory is where an instance of this # template keeps its chain; the parent is kept because ProtectSystem=strict must bind-mount # every path listed and an operator who points SOURCELESS_DATA_DIR elsewhere gets a drop-in # from brokkr rather than an edit here. ReadWritePaths=-/var/lib/sourceless/%i ReadWritePaths=-/var/lib/sourceless ProtectKernelTunables=yes ProtectKernelModules=yes ProtectControlGroups=yes RestrictSUIDSGID=yes RestrictRealtime=yes LockPersonality=yes # Alerts go to stderr, which systemd captures with no configuration and no network. That is the # whole reason the sink is stderr — see hermod.ts. It is also NOT a pager: journald keeps the # line, and nothing reads journald at 3am unless something outside is shipping it. StandardOutput=journal StandardError=journal SyslogIdentifier=strblk@%i [Install] WantedBy=multi-user.target UNIT_TEMPLATE_BINARY else cat > "$UNIT_FILE" <<'UNIT_TEMPLATE_NODE' # Generated by scripts/pharos.mjs. Do not edit; edit the script. # # ONE INSTANCE PER STARW CLASS. The instance name after the @ is the class, and it selects # the environment file: strblk-node@pulsar reads /etc/sourceless/strblk-node-pulsar.env. # # Install: # sudo cp deploy/systemd/strblk-node@.service /etc/systemd/system/ # sudo cp deploy/systemd/strblk-node-pulsar.env /etc/sourceless/ # edit it first # sudo systemctl daemon-reload # sudo systemctl enable --now strblk-node@pulsar # # All three at once, which is the whole point of the template: # sudo systemctl enable --now strblk-node@pulsar strblk-node@quasar strblk-node@supernova # # Each instance needs its OWN data directory and its OWN ports. The generated env files # carry both, in a block per class, so three instances on one host do not collide. # # REASONED, not measured: there is no systemd on the host this was generated on, so nothing here # has been started by systemd. What is measured is what the node does when it is signalled, and # every directive below is chosen against one of those measurements. See # docs/RUNBOOK_OBSERVABILITY.md, which labels each claim. [Unit] Description=SourceLess chain node (strblk), STARW class %i Documentation=file:///opt/sourceless/docs/RUNBOOK_OBSERVABILITY.md After=network-online.target Wants=network-online.target # The burst limiter, and it is in [Unit] because that is where systemd reads it. # # MEASURED, 2026-09-08: these two directives were in [Service], where `systemd-analyze verify` # (systemd 252, debian:bookworm-slim) reports # Unknown key 'StartLimitIntervalSec' in section [Service], ignoring. # They moved to [Unit] in systemd 229 and the old spelling is silently ignored, so for as long as # this unit has existed its documented burst limiter has done NOTHING: a node that cannot start # would have restarted every 5 s for ever, flooding the journal with the reason nobody could # then find. Nothing had ever parsed this file until it was run through systemd-analyze. # # What they do: after 5 failures inside 10 minutes systemd gives up and leaves the unit failed, # which is a state the deploy/prometheus/ absence rule sees. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=simple EnvironmentFile=/etc/sourceless/strblk-node-%i.env WorkingDirectory=/opt/sourceless # Exec'd directly rather than through a shell or through npm. A shell wrapper becomes the main # process, systemd signals IT, and the node underneath is orphaned — which matters here more # than usual: an orphaned node keeps the Cerberus lease on its data directory, so the restart # this unit performs is then REFUSED by the lock, and the operator sees "another process holds # this directory" naming a pid nobody knows about. ExecStart=/usr/bin/node ${SOURCELESS_ENTRY} node \ --dir ${SOURCELESS_DATA_DIR} \ --network ${SOURCELESS_NETWORK} \ --ops-port ${SOURCELESS_OPS_PORT} \ --rpc-port ${SOURCELESS_RPC_PORT} \ --dashboard-port ${SOURCELESS_DASHBOARD_PORT} \ --block-interval ${SOURCELESS_BLOCK_INTERVAL_MS} \ $SOURCELESS_P2P_PORT_FLAG \ $SOURCELESS_PEERS_FLAG \ $SOURCELESS_ADVERTISE_FLAG \ $SOURCELESS_CLASS_FLAG # SIGTERM, and let it finish. It spends that time snapshotting local state and releasing the # Cerberus lease rather than abandoning them. # # MEASURED: stop() + release() took 3.2-3.8 ms across three runs on an EMPTY chain # (docs/RUNBOOK_BACKUP.md section 3). That is a floor, and at Asgard's size it is NOT the cost: # on 2026-11-16 six of the seven asgard-vps genesis seats - this node, over the same chain - were # still in their shutdown at 90 s and were killed with SIGKILL ("State 'stop-sigterm' timed # out"), so the node's own shutdown deadline did not end them first either (OPS-2). Why is not # yet measured. 300s since 2026-11-18, the same as the seat units # (deploy/strblk-seat@.service): size it from the first timed clean stop. # # The headroom is not politeness. Draupnir writes a snapshot to a temp file, fsyncs it, renames # it over the target, and THEN trims the log the snapshot covers. A SIGKILL between the rename # and the trim leaves a snapshot that has been published and a log that still holds the records # it covers — and recovery reads that as a sequence gap, stops at it, and REWRITES the log # without the records after it. That is measured in docs/RUNBOOK_BACKUP.md section 5: silent # loss, with the node reporting a clean start afterwards. A stop timeout shorter than a snapshot # takes is therefore a data-loss setting, and it is the one an operator tightens first. KillSignal=SIGTERM TimeoutStopSec=300 # Every process in this unit's control group gets the signal, and gets the SIGKILL at the end of # the timeout if it is still there. # # This is systemd's default and it is written out anyway, for two reasons. It makes a future # change to it a deliberate edit rather than an inherited one. And it is the directive # docs/RUNBOOK_ROLLBACK.md's stop step depends on being true: that runbook's preflight decides # "the node is stopped" by the ABSENCE of a lock file, and a lock file is left behind by exactly # one thing — a node process that outlived the stop. KillMode=process would leave one on every # rollback where anything had been wrapped around ExecStart. KillMode=control-group # Restart always, and wait 5 s between attempts. # # `always` rather than `on-failure` deliberately. A node that exits 0 has still stopped being a # validator, and this unit's job is that a validator is running — `systemctl stop` is how an # operator says otherwise, and it is not affected by this. # # The burst limiter is what keeps a node that cannot start from becoming a restart loop that # hides its own reason in a flood of journal lines. After 5 failures in 10 minutes systemd gives # up and leaves the unit failed, which is a state the alert rule below sees as absence. Restart=always RestartSec=5 # A validator holds signing keys. Nothing here needs root, a writable /usr, or a device. User=sourceless Group=sourceless NoNewPrivileges=yes PrivateTmp=yes ProtectSystem=strict ProtectHome=yes # A LITERAL path, because ReadWritePaths= does not expand environment variables. # # MEASURED, 2026-09-08: with ${SOURCELESS_DATA_DIR} here, `systemd-analyze verify` reports # ReadWritePaths= path is not absolute, ignoring: ${SOURCELESS_DATA_DIR} # and the directive is dropped. Dropped, under ProtectSystem=strict, means the node has NO # writable path at all: it would fail on its first write to its own data directory. So the unit # as it stood could not have run a node, and nothing would have discovered that until an # operator installed it. # # The literal is the default in deploy/systemd/strblk-node.env. A data directory anywhere else # needs the path added, and `brokkr.sh --service systemd` writes exactly that as a drop-in at # /etc/systemd/system/strblk-node.service.d/10-datadir.conf rather than editing this file. # The `-` prefix is load-bearing and was added on 2026-09-09, the first time this unit was # ever STARTED by systemd rather than parsed by it. # # MEASURED on Debian 12, systemd 252: the node failed every start with # Failed to set up mount namespacing: /run/systemd/unit-root/var/lib/sourceless: # No such file or directory # Failed at step NAMESPACE spawning /usr/bin/node # exit 226/NAMESPACE, five restarts, then start-request-repeated-too-quickly. ReadWritePaths= # is ADDITIVE, so brokkr's drop-in appends the real data directory rather than replacing this # line - and under ProtectSystem=strict systemd must bind-mount EVERY path listed. This default # is not created by anything when the data directory is elsewhere, which is the ordinary case # and the one brokkr writes. # # A leading dash means ignore-if-absent (systemd.exec(5)). The previous comment # below is the same directive's PREVIOUS defect, found by systemd-analyze verify. That check # parses and does not run, which is exactly why it could not have found this one. # Both, and both ignore-if-absent. The per-instance directory is where an instance of this # template keeps its chain; the parent is kept because ProtectSystem=strict must bind-mount # every path listed and an operator who points SOURCELESS_DATA_DIR elsewhere gets a drop-in # from brokkr rather than an edit here. ReadWritePaths=-/var/lib/sourceless/%i ReadWritePaths=-/var/lib/sourceless ProtectKernelTunables=yes ProtectKernelModules=yes ProtectControlGroups=yes RestrictSUIDSGID=yes RestrictRealtime=yes LockPersonality=yes # Alerts go to stderr, which systemd captures with no configuration and no network. That is the # whole reason the sink is stderr — see hermod.ts. It is also NOT a pager: journald keeps the # line, and nothing reads journald at 3am unless something outside is shipping it. StandardOutput=journal StandardError=journal SyslogIdentifier=strblk@%i [Install] WantedBy=multi-user.target UNIT_TEMPLATE_NODE fi elif [ "$CHANNEL" = binary ]; then cat > "$UNIT_FILE" <<'UNIT_BINARY' # Generated by scripts/pharos.mjs. Do not edit; edit the script. # # Install: # sudo cp deploy/systemd/strblk-node.service /etc/systemd/system/ # sudo cp deploy/systemd/strblk-node.env /etc/sourceless/strblk-node.env # edit it first # sudo systemctl daemon-reload && sudo systemctl enable --now strblk-node # # REASONED, not measured: there is no systemd on the host this was generated on, so nothing here # has been started by systemd. What is measured is what the node does when it is signalled, and # every directive below is chosen against one of those measurements. See # docs/RUNBOOK_OBSERVABILITY.md, which labels each claim. [Unit] Description=SourceLess chain node (strblk) Documentation=file:///opt/sourceless/docs/RUNBOOK_OBSERVABILITY.md After=network-online.target Wants=network-online.target # The burst limiter, and it is in [Unit] because that is where systemd reads it. # # MEASURED, 2026-09-08: these two directives were in [Service], where `systemd-analyze verify` # (systemd 252, debian:bookworm-slim) reports # Unknown key 'StartLimitIntervalSec' in section [Service], ignoring. # They moved to [Unit] in systemd 229 and the old spelling is silently ignored, so for as long as # this unit has existed its documented burst limiter has done NOTHING: a node that cannot start # would have restarted every 5 s for ever, flooding the journal with the reason nobody could # then find. Nothing had ever parsed this file until it was run through systemd-analyze. # # What they do: after 5 failures inside 10 minutes systemd gives up and leaves the unit failed, # which is a state the deploy/prometheus/ absence rule sees. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=simple EnvironmentFile=/etc/sourceless/strblk-node.env WorkingDirectory=/opt/sourceless # Exec'd directly rather than through a shell or through npm. A shell wrapper becomes the main # process, systemd signals IT, and the node underneath is orphaned — which matters here more # than usual: an orphaned node keeps the Cerberus lease on its data directory, so the restart # this unit performs is then REFUSED by the lock, and the operator sees "another process holds # this directory" naming a pid nobody knows about. ExecStart=/opt/sourceless/bin/strblk node \ --dir ${SOURCELESS_DATA_DIR} \ --network ${SOURCELESS_NETWORK} \ --ops-port ${SOURCELESS_OPS_PORT} \ --rpc-port ${SOURCELESS_RPC_PORT} \ --dashboard-port ${SOURCELESS_DASHBOARD_PORT} \ --block-interval ${SOURCELESS_BLOCK_INTERVAL_MS} \ $SOURCELESS_P2P_PORT_FLAG \ $SOURCELESS_PEERS_FLAG \ $SOURCELESS_ADVERTISE_FLAG \ $SOURCELESS_CLASS_FLAG # SIGTERM, and let it finish. It spends that time snapshotting local state and releasing the # Cerberus lease rather than abandoning them. # # MEASURED: stop() + release() took 3.2-3.8 ms across three runs on an EMPTY chain # (docs/RUNBOOK_BACKUP.md section 3). That is a floor, and at Asgard's size it is NOT the cost: # on 2026-11-16 six of the seven asgard-vps genesis seats - this node, over the same chain - were # still in their shutdown at 90 s and were killed with SIGKILL ("State 'stop-sigterm' timed # out"), so the node's own shutdown deadline did not end them first either (OPS-2). Why is not # yet measured. 300s since 2026-11-18, the same as the seat units # (deploy/strblk-seat@.service): size it from the first timed clean stop. # # The headroom is not politeness. Draupnir writes a snapshot to a temp file, fsyncs it, renames # it over the target, and THEN trims the log the snapshot covers. A SIGKILL between the rename # and the trim leaves a snapshot that has been published and a log that still holds the records # it covers — and recovery reads that as a sequence gap, stops at it, and REWRITES the log # without the records after it. That is measured in docs/RUNBOOK_BACKUP.md section 5: silent # loss, with the node reporting a clean start afterwards. A stop timeout shorter than a snapshot # takes is therefore a data-loss setting, and it is the one an operator tightens first. KillSignal=SIGTERM TimeoutStopSec=300 # Every process in this unit's control group gets the signal, and gets the SIGKILL at the end of # the timeout if it is still there. # # This is systemd's default and it is written out anyway, for two reasons. It makes a future # change to it a deliberate edit rather than an inherited one. And it is the directive # docs/RUNBOOK_ROLLBACK.md's stop step depends on being true: that runbook's preflight decides # "the node is stopped" by the ABSENCE of a lock file, and a lock file is left behind by exactly # one thing — a node process that outlived the stop. KillMode=process would leave one on every # rollback where anything had been wrapped around ExecStart. KillMode=control-group # Restart always, and wait 5 s between attempts. # # `always` rather than `on-failure` deliberately. A node that exits 0 has still stopped being a # validator, and this unit's job is that a validator is running — `systemctl stop` is how an # operator says otherwise, and it is not affected by this. # # The burst limiter is what keeps a node that cannot start from becoming a restart loop that # hides its own reason in a flood of journal lines. After 5 failures in 10 minutes systemd gives # up and leaves the unit failed, which is a state the alert rule below sees as absence. Restart=always RestartSec=5 # A validator holds signing keys. Nothing here needs root, a writable /usr, or a device. User=sourceless Group=sourceless NoNewPrivileges=yes PrivateTmp=yes ProtectSystem=strict ProtectHome=yes # A LITERAL path, because ReadWritePaths= does not expand environment variables. # # MEASURED, 2026-09-08: with ${SOURCELESS_DATA_DIR} here, `systemd-analyze verify` reports # ReadWritePaths= path is not absolute, ignoring: ${SOURCELESS_DATA_DIR} # and the directive is dropped. Dropped, under ProtectSystem=strict, means the node has NO # writable path at all: it would fail on its first write to its own data directory. So the unit # as it stood could not have run a node, and nothing would have discovered that until an # operator installed it. # # The literal is the default in deploy/systemd/strblk-node.env. A data directory anywhere else # needs the path added, and `brokkr.sh --service systemd` writes exactly that as a drop-in at # /etc/systemd/system/strblk-node.service.d/10-datadir.conf rather than editing this file. # The `-` prefix is load-bearing and was added on 2026-09-09, the first time this unit was # ever STARTED by systemd rather than parsed by it. # # MEASURED on Debian 12, systemd 252: the node failed every start with # Failed to set up mount namespacing: /run/systemd/unit-root/var/lib/sourceless: # No such file or directory # Failed at step NAMESPACE spawning /usr/bin/node # exit 226/NAMESPACE, five restarts, then start-request-repeated-too-quickly. ReadWritePaths= # is ADDITIVE, so brokkr's drop-in appends the real data directory rather than replacing this # line - and under ProtectSystem=strict systemd must bind-mount EVERY path listed. This default # is not created by anything when the data directory is elsewhere, which is the ordinary case # and the one brokkr writes. # # A leading dash means ignore-if-absent (systemd.exec(5)). The previous comment # below is the same directive's PREVIOUS defect, found by systemd-analyze verify. That check # parses and does not run, which is exactly why it could not have found this one. ReadWritePaths=-/var/lib/sourceless ProtectKernelTunables=yes ProtectKernelModules=yes ProtectControlGroups=yes RestrictSUIDSGID=yes RestrictRealtime=yes LockPersonality=yes # Alerts go to stderr, which systemd captures with no configuration and no network. That is the # whole reason the sink is stderr — see hermod.ts. It is also NOT a pager: journald keeps the # line, and nothing reads journald at 3am unless something outside is shipping it. StandardOutput=journal StandardError=journal SyslogIdentifier=strblk [Install] WantedBy=multi-user.target UNIT_BINARY else cat > "$UNIT_FILE" <<'UNIT_NODE' # Generated by scripts/pharos.mjs. Do not edit; edit the script. # # Install: # sudo cp deploy/systemd/strblk-node.service /etc/systemd/system/ # sudo cp deploy/systemd/strblk-node.env /etc/sourceless/strblk-node.env # edit it first # sudo systemctl daemon-reload && sudo systemctl enable --now strblk-node # # REASONED, not measured: there is no systemd on the host this was generated on, so nothing here # has been started by systemd. What is measured is what the node does when it is signalled, and # every directive below is chosen against one of those measurements. See # docs/RUNBOOK_OBSERVABILITY.md, which labels each claim. [Unit] Description=SourceLess chain node (strblk) Documentation=file:///opt/sourceless/docs/RUNBOOK_OBSERVABILITY.md After=network-online.target Wants=network-online.target # The burst limiter, and it is in [Unit] because that is where systemd reads it. # # MEASURED, 2026-09-08: these two directives were in [Service], where `systemd-analyze verify` # (systemd 252, debian:bookworm-slim) reports # Unknown key 'StartLimitIntervalSec' in section [Service], ignoring. # They moved to [Unit] in systemd 229 and the old spelling is silently ignored, so for as long as # this unit has existed its documented burst limiter has done NOTHING: a node that cannot start # would have restarted every 5 s for ever, flooding the journal with the reason nobody could # then find. Nothing had ever parsed this file until it was run through systemd-analyze. # # What they do: after 5 failures inside 10 minutes systemd gives up and leaves the unit failed, # which is a state the deploy/prometheus/ absence rule sees. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=simple EnvironmentFile=/etc/sourceless/strblk-node.env WorkingDirectory=/opt/sourceless # Exec'd directly rather than through a shell or through npm. A shell wrapper becomes the main # process, systemd signals IT, and the node underneath is orphaned — which matters here more # than usual: an orphaned node keeps the Cerberus lease on its data directory, so the restart # this unit performs is then REFUSED by the lock, and the operator sees "another process holds # this directory" naming a pid nobody knows about. ExecStart=/usr/bin/node ${SOURCELESS_ENTRY} node \ --dir ${SOURCELESS_DATA_DIR} \ --network ${SOURCELESS_NETWORK} \ --ops-port ${SOURCELESS_OPS_PORT} \ --rpc-port ${SOURCELESS_RPC_PORT} \ --dashboard-port ${SOURCELESS_DASHBOARD_PORT} \ --block-interval ${SOURCELESS_BLOCK_INTERVAL_MS} \ $SOURCELESS_P2P_PORT_FLAG \ $SOURCELESS_PEERS_FLAG \ $SOURCELESS_ADVERTISE_FLAG \ $SOURCELESS_CLASS_FLAG # SIGTERM, and let it finish. It spends that time snapshotting local state and releasing the # Cerberus lease rather than abandoning them. # # MEASURED: stop() + release() took 3.2-3.8 ms across three runs on an EMPTY chain # (docs/RUNBOOK_BACKUP.md section 3). That is a floor, and at Asgard's size it is NOT the cost: # on 2026-11-16 six of the seven asgard-vps genesis seats - this node, over the same chain - were # still in their shutdown at 90 s and were killed with SIGKILL ("State 'stop-sigterm' timed # out"), so the node's own shutdown deadline did not end them first either (OPS-2). Why is not # yet measured. 300s since 2026-11-18, the same as the seat units # (deploy/strblk-seat@.service): size it from the first timed clean stop. # # The headroom is not politeness. Draupnir writes a snapshot to a temp file, fsyncs it, renames # it over the target, and THEN trims the log the snapshot covers. A SIGKILL between the rename # and the trim leaves a snapshot that has been published and a log that still holds the records # it covers — and recovery reads that as a sequence gap, stops at it, and REWRITES the log # without the records after it. That is measured in docs/RUNBOOK_BACKUP.md section 5: silent # loss, with the node reporting a clean start afterwards. A stop timeout shorter than a snapshot # takes is therefore a data-loss setting, and it is the one an operator tightens first. KillSignal=SIGTERM TimeoutStopSec=300 # Every process in this unit's control group gets the signal, and gets the SIGKILL at the end of # the timeout if it is still there. # # This is systemd's default and it is written out anyway, for two reasons. It makes a future # change to it a deliberate edit rather than an inherited one. And it is the directive # docs/RUNBOOK_ROLLBACK.md's stop step depends on being true: that runbook's preflight decides # "the node is stopped" by the ABSENCE of a lock file, and a lock file is left behind by exactly # one thing — a node process that outlived the stop. KillMode=process would leave one on every # rollback where anything had been wrapped around ExecStart. KillMode=control-group # Restart always, and wait 5 s between attempts. # # `always` rather than `on-failure` deliberately. A node that exits 0 has still stopped being a # validator, and this unit's job is that a validator is running — `systemctl stop` is how an # operator says otherwise, and it is not affected by this. # # The burst limiter is what keeps a node that cannot start from becoming a restart loop that # hides its own reason in a flood of journal lines. After 5 failures in 10 minutes systemd gives # up and leaves the unit failed, which is a state the alert rule below sees as absence. Restart=always RestartSec=5 # A validator holds signing keys. Nothing here needs root, a writable /usr, or a device. User=sourceless Group=sourceless NoNewPrivileges=yes PrivateTmp=yes ProtectSystem=strict ProtectHome=yes # A LITERAL path, because ReadWritePaths= does not expand environment variables. # # MEASURED, 2026-09-08: with ${SOURCELESS_DATA_DIR} here, `systemd-analyze verify` reports # ReadWritePaths= path is not absolute, ignoring: ${SOURCELESS_DATA_DIR} # and the directive is dropped. Dropped, under ProtectSystem=strict, means the node has NO # writable path at all: it would fail on its first write to its own data directory. So the unit # as it stood could not have run a node, and nothing would have discovered that until an # operator installed it. # # The literal is the default in deploy/systemd/strblk-node.env. A data directory anywhere else # needs the path added, and `brokkr.sh --service systemd` writes exactly that as a drop-in at # /etc/systemd/system/strblk-node.service.d/10-datadir.conf rather than editing this file. # The `-` prefix is load-bearing and was added on 2026-09-09, the first time this unit was # ever STARTED by systemd rather than parsed by it. # # MEASURED on Debian 12, systemd 252: the node failed every start with # Failed to set up mount namespacing: /run/systemd/unit-root/var/lib/sourceless: # No such file or directory # Failed at step NAMESPACE spawning /usr/bin/node # exit 226/NAMESPACE, five restarts, then start-request-repeated-too-quickly. ReadWritePaths= # is ADDITIVE, so brokkr's drop-in appends the real data directory rather than replacing this # line - and under ProtectSystem=strict systemd must bind-mount EVERY path listed. This default # is not created by anything when the data directory is elsewhere, which is the ordinary case # and the one brokkr writes. # # A leading dash means ignore-if-absent (systemd.exec(5)). The previous comment # below is the same directive's PREVIOUS defect, found by systemd-analyze verify. That check # parses and does not run, which is exactly why it could not have found this one. ReadWritePaths=-/var/lib/sourceless ProtectKernelTunables=yes ProtectKernelModules=yes ProtectControlGroups=yes RestrictSUIDSGID=yes RestrictRealtime=yes LockPersonality=yes # Alerts go to stderr, which systemd captures with no configuration and no network. That is the # whole reason the sink is stderr — see hermod.ts. It is also NOT a pager: journald keeps the # line, and nothing reads journald at 3am unless something outside is shipping it. StandardOutput=journal StandardError=journal SyslogIdentifier=strblk [Install] WantedBy=multi-user.target UNIT_NODE fi # Not cp: cp onto an existing file keeps that file's mode while the secrets go in. private_file "$UNIT_ENV" cat "$ENV_FILE" > "$UNIT_ENV" narrow "$UNIT_ENV" "keystore passphrase and console secret" # ReadWritePaths= takes no environment variables - MEASURED with systemd-analyze, see the # comment on it in the unit - so a data directory outside the unit's literal default is # granted here, as a drop-in. A drop-in rather than an edit, so that a later # 'node scripts/pharos.mjs' can rewrite the unit without losing this machine's path. # The drop-in goes on the INSTANCE with --class, not on the template: a per-instance # directory is exactly what must not be shared, and a drop-in on strblk-node@.service.d # would grant every class the same one. DROPIN_DIR=/etc/systemd/system/$UNIT.service.d mkdir -p "$DROPIN_DIR" printf '%s ' '# Written by brokkr. ReadWritePaths= does not expand variables, so this' '# machine'"'"'s data directory is granted literally.' '[Service]' "ReadWritePaths=$DATADIR" > "$DROPIN_DIR/10-datadir.conf" fi # The unit runs as User=sourceless, so the account has to exist and the data directory has to # belong to it - the data directory ONLY, as chown_plan decided before anything was written. # ETCDIR stays root's: systemd reads the unit's env file as root, and nothing the node does # needs to write there. if ! id sourceless >/dev/null 2>&1; then run useradd --system --home-dir /opt/sourceless --shell /usr/sbin/nologin sourceless fi case $DATADIR_CHOWN in recursive) run chown -R sourceless:sourceless "$DATADIR" ;; *) run chown sourceless:sourceless "$DATADIR" ;; esac run systemctl daemon-reload if [ "$START" = 1 ]; then run systemctl enable --now "$UNIT"; else run systemctl enable "$UNIT"; fi ok "unit installed. REASONED, not measured: nothing in this repository has ever been" info " started by systemd - there is no systemd on the machine this installer" info " was generated on. What is measured is what the node does when it is" info " signalled; see docs/RUNBOOK_OBSERVABILITY.md, which labels each claim." info " systemctl status $UNIT journalctl -u $UNIT -f" if [ -n "$NODE_CLASS" ]; then info " one of every class on this host, once each is installed:" info " systemctl enable --now strblk-node@pulsar strblk-node@quasar strblk-node@supernova" fi ;; systemd-user) # No root, no /etc, no User=, and no confinement that needs privilege. Everything that makes # a service a service - Restart=always, RestartSec, the burst limiter, the SIGTERM policy and # the stop timeout that keeps a SIGKILL out of a snapshot - is kept, because none of it needs # root. What is dropped is listed in the generator beside the filter that drops it. [ "$UNAME" = Linux ] || die "--service systemd-user on $UNAME (launchd is the macOS equivalent)" have systemctl || die "--service systemd-user, but systemctl is not on PATH" [ "$CHANNEL" != docker ] || die "--service systemd-user with the docker channel: use the container runtime's own restart policy" # The interpreter this installer resolved, and not the /usr/bin/node the unit is generated # with. MEASURED on a GitHub ubuntu-26.04 runner, 2026-11-19: node was on PATH at # /opt/hostedtoolcache/node/22.23.4/x64/bin/node, nothing was at /usr/bin/node, and every start # of this unit failed with 203/EXEC "Unable to locate executable '/usr/bin/node'" until the # burst limiter gave up - while the runner, which execs SOURCELESS_NODE_BIN, would have started # the same node. The executable of an ExecStart= cannot be a variable, so it is written in # literally, and checked here, before the unit exists, for what systemd would misread. if [ -n "$NODE_BIN" ]; then unit_path_ok "$NODE_BIN" || die "$NODE_BIN carries whitespace, a quote, a backslash or a %, which a systemd unit does not read back as the same path. Set SOURCELESS_NODE_BIN to a node without them." fi XDG_CONFIG=$(printenv XDG_CONFIG_HOME 2>/dev/null || printf '') if [ -z "$XDG_CONFIG" ]; then XDG_CONFIG=$HOME/.config; fi USER_UNIT_DIR=$XDG_CONFIG/systemd/user USER_UNIT_NAME=strblk-node-$INSTANCE.service if [ "$DRY" = 1 ]; then info "would write $USER_UNIT_DIR/$USER_UNIT_NAME" info "would run systemctl --user daemon-reload && systemctl --user enable --now $USER_UNIT_NAME" else mkdir -p "$USER_UNIT_DIR" cat > "$USER_UNIT_DIR/$USER_UNIT_NAME" <<'UNIT_USER' # Generated by scripts/pharos.mjs. Do not edit; edit the script. # # Install: # sudo cp deploy/systemd/strblk-node.service /etc/systemd/system/ # sudo cp deploy/systemd/strblk-node.env /etc/sourceless/strblk-node.env # edit it first # sudo systemctl daemon-reload && sudo systemctl enable --now strblk-node # # REASONED, not measured: there is no systemd on the host this was generated on, so nothing here # has been started by systemd. What is measured is what the node does when it is signalled, and # every directive below is chosen against one of those measurements. See # docs/RUNBOOK_OBSERVABILITY.md, which labels each claim. [Unit] Description=SourceLess chain node (strblk) @INSTANCE@ Documentation=file:///opt/sourceless/docs/RUNBOOK_OBSERVABILITY.md After=network-online.target Wants=network-online.target # The burst limiter, and it is in [Unit] because that is where systemd reads it. # # MEASURED, 2026-09-08: these two directives were in [Service], where `systemd-analyze verify` # (systemd 252, debian:bookworm-slim) reports # Unknown key 'StartLimitIntervalSec' in section [Service], ignoring. # They moved to [Unit] in systemd 229 and the old spelling is silently ignored, so for as long as # this unit has existed its documented burst limiter has done NOTHING: a node that cannot start # would have restarted every 5 s for ever, flooding the journal with the reason nobody could # then find. Nothing had ever parsed this file until it was run through systemd-analyze. # # What they do: after 5 failures inside 10 minutes systemd gives up and leaves the unit failed, # which is a state the deploy/prometheus/ absence rule sees. StartLimitIntervalSec=600 StartLimitBurst=5 [Service] Type=simple EnvironmentFile=@ENV_FILE@ WorkingDirectory=@PREFIX@ # Exec'd directly rather than through a shell or through npm. A shell wrapper becomes the main # process, systemd signals IT, and the node underneath is orphaned — which matters here more # than usual: an orphaned node keeps the Cerberus lease on its data directory, so the restart # this unit performs is then REFUSED by the lock, and the operator sees "another process holds # this directory" naming a pid nobody knows about. ExecStart=/usr/bin/node ${SOURCELESS_ENTRY} node \ --dir ${SOURCELESS_DATA_DIR} \ --network ${SOURCELESS_NETWORK} \ --ops-port ${SOURCELESS_OPS_PORT} \ --rpc-port ${SOURCELESS_RPC_PORT} \ --dashboard-port ${SOURCELESS_DASHBOARD_PORT} \ --block-interval ${SOURCELESS_BLOCK_INTERVAL_MS} \ $SOURCELESS_P2P_PORT_FLAG \ $SOURCELESS_PEERS_FLAG \ $SOURCELESS_ADVERTISE_FLAG \ $SOURCELESS_CLASS_FLAG # SIGTERM, and let it finish. It spends that time snapshotting local state and releasing the # Cerberus lease rather than abandoning them. # # MEASURED: stop() + release() took 3.2-3.8 ms across three runs on an EMPTY chain # (docs/RUNBOOK_BACKUP.md section 3). That is a floor, and at Asgard's size it is NOT the cost: # on 2026-11-16 six of the seven asgard-vps genesis seats - this node, over the same chain - were # still in their shutdown at 90 s and were killed with SIGKILL ("State 'stop-sigterm' timed # out"), so the node's own shutdown deadline did not end them first either (OPS-2). Why is not # yet measured. 300s since 2026-11-18, the same as the seat units # (deploy/strblk-seat@.service): size it from the first timed clean stop. # # The headroom is not politeness. Draupnir writes a snapshot to a temp file, fsyncs it, renames # it over the target, and THEN trims the log the snapshot covers. A SIGKILL between the rename # and the trim leaves a snapshot that has been published and a log that still holds the records # it covers — and recovery reads that as a sequence gap, stops at it, and REWRITES the log # without the records after it. That is measured in docs/RUNBOOK_BACKUP.md section 5: silent # loss, with the node reporting a clean start afterwards. A stop timeout shorter than a snapshot # takes is therefore a data-loss setting, and it is the one an operator tightens first. KillSignal=SIGTERM TimeoutStopSec=300 # Every process in this unit's control group gets the signal, and gets the SIGKILL at the end of # the timeout if it is still there. # # This is systemd's default and it is written out anyway, for two reasons. It makes a future # change to it a deliberate edit rather than an inherited one. And it is the directive # docs/RUNBOOK_ROLLBACK.md's stop step depends on being true: that runbook's preflight decides # "the node is stopped" by the ABSENCE of a lock file, and a lock file is left behind by exactly # one thing — a node process that outlived the stop. KillMode=process would leave one on every # rollback where anything had been wrapped around ExecStart. KillMode=control-group # Restart always, and wait 5 s between attempts. # # `always` rather than `on-failure` deliberately. A node that exits 0 has still stopped being a # validator, and this unit's job is that a validator is running — `systemctl stop` is how an # operator says otherwise, and it is not affected by this. # # The burst limiter is what keeps a node that cannot start from becoming a restart loop that # hides its own reason in a flood of journal lines. After 5 failures in 10 minutes systemd gives # up and leaves the unit failed, which is a state the alert rule below sees as absence. Restart=always RestartSec=5 # A validator holds signing keys. Nothing here needs root, a writable /usr, or a device. # A LITERAL path, because ReadWritePaths= does not expand environment variables. # # MEASURED, 2026-09-08: with ${SOURCELESS_DATA_DIR} here, `systemd-analyze verify` reports # ReadWritePaths= path is not absolute, ignoring: ${SOURCELESS_DATA_DIR} # and the directive is dropped. Dropped, under ProtectSystem=strict, means the node has NO # writable path at all: it would fail on its first write to its own data directory. So the unit # as it stood could not have run a node, and nothing would have discovered that until an # operator installed it. # # The literal is the default in deploy/systemd/strblk-node.env. A data directory anywhere else # needs the path added, and `brokkr.sh --service systemd` writes exactly that as a drop-in at # /etc/systemd/system/strblk-node.service.d/10-datadir.conf rather than editing this file. # The `-` prefix is load-bearing and was added on 2026-09-09, the first time this unit was # ever STARTED by systemd rather than parsed by it. # # MEASURED on Debian 12, systemd 252: the node failed every start with # Failed to set up mount namespacing: /run/systemd/unit-root/var/lib/sourceless: # No such file or directory # Failed at step NAMESPACE spawning /usr/bin/node # exit 226/NAMESPACE, five restarts, then start-request-repeated-too-quickly. ReadWritePaths= # is ADDITIVE, so brokkr's drop-in appends the real data directory rather than replacing this # line - and under ProtectSystem=strict systemd must bind-mount EVERY path listed. This default # is not created by anything when the data directory is elsewhere, which is the ordinary case # and the one brokkr writes. # # A leading dash means ignore-if-absent (systemd.exec(5)). The previous comment # below is the same directive's PREVIOUS defect, found by systemd-analyze verify. That check # parses and does not run, which is exactly why it could not have found this one. # Alerts go to stderr, which systemd captures with no configuration and no network. That is the # whole reason the sink is stderr — see hermod.ts. It is also NOT a pager: journald keeps the # line, and nothing reads journald at 3am unless something outside is shipping it. StandardOutput=journal StandardError=journal SyslogIdentifier=strblk [Install] WantedBy=default.target UNIT_USER if [ -n "$NODE_BIN" ]; then sed -i.bak "s|^ExecStart=/usr/bin/node |ExecStart=$(unit_value "$NODE_BIN") |" "$USER_UNIT_DIR/$USER_UNIT_NAME" fi # The three site-specific lines. Written as placeholders because the unit is full of # SOURCELESS_* expansions that systemd must perform and a shell must not, so it cannot # come out of an unquoted heredoc. -i.bak is the spelling both GNU and BSD sed accept. # Every value through unit_value: escaped for sed, and % doubled for systemd. sed -i.bak "s|@ENV_FILE@|$(unit_value "$ENV_FILE")|; s|@PREFIX@|$(unit_value "$PREFIX")|; s|@INSTANCE@|$(unit_value "$INSTANCE")|" "$USER_UNIT_DIR/$USER_UNIT_NAME" rm -f "$USER_UNIT_DIR/$USER_UNIT_NAME.bak" systemctl --user daemon-reload if [ "$START" = 1 ]; then systemctl --user enable --now "$USER_UNIT_NAME"; else systemctl --user enable "$USER_UNIT_NAME"; fi fi ok "user unit installed at $USER_UNIT_DIR/$USER_UNIT_NAME" info " systemctl --user status $USER_UNIT_NAME" info " journalctl --user -u $USER_UNIT_NAME -f" warn "a USER unit stops when your session ends, unless the account lingers:" info " sudo loginctl enable-linger $(id -un)" info " Without that, this node stops at logout and does not come back at boot." info " It is still a service - Restart=always, RestartSec=5 and the burst" info " limiter are all here - and it is not the root unit's confinement:" info " User=, ProtectSystem=strict and the namespace directives were dropped" info " rather than left in to fail, because a unit that refuses to start is" info " worse than one with less hardening." ;; launchd) [ "$UNAME" = Darwin ] || die "--service launchd on $UNAME" PLIST=$HOME/Library/LaunchAgents/com.sourceless.strblk-node.$NETWORK.plist if [ "$DRY" = 1 ]; then info "would write $PLIST and bootstrap it" else mkdir -p "$HOME/Library/LaunchAgents" # launchd's PATH is /usr/bin:/bin:/usr/sbin:/sbin and node is on none of them. The runner # execs an absolute interpreter already, so this is belt to that braces — it is here because # a "node" reached from inside the node process (a child, a worker) has the job's PATH and # not the runner's. # Empty on the binary and docker channels, which have no interpreter to find. An empty value # through dirname is ".", and a relative entry in a service manager's PATH resolves against # its working directory — so the whole element is dropped rather than written wrong. PLIST_PATH=/usr/bin:/bin:/usr/sbin:/sbin if [ -n "$NODE_BIN" ]; then PLIST_PATH=$(dirname "$NODE_BIN"):$PLIST_PATH; fi # Paths as XML text, never as markup. See xml_escape. X_RUNNER=$(xml_escape "$RUNNER") X_PREFIX=$(xml_escape "$PREFIX") X_PLIST_PATH=$(xml_escape "$PLIST_PATH") cat > "$PLIST" < Labelcom.sourceless.strblk-node.$NETWORK ProgramArguments$X_RUNNER RunAtLoad KeepAlive EnvironmentVariables PATH$X_PLIST_PATH ThrottleInterval60 SoftResourceLimitsNumberOfFiles8192 HardResourceLimitsNumberOfFiles8192 WorkingDirectory$X_PREFIX StandardOutPath$X_PREFIX/strblk-$NETWORK.log StandardErrorPath$X_PREFIX/strblk-$NETWORK.err EOF # plutil is the only thing that says whether launchd will accept this file. A plist with one # bad character loads as NOTHING and reports nothing: launchctl bootstrap returns 0 and the # job does not exist. Checked before bootstrapping, and the file is removed if it is bad, so # a later run does not bootstrap a broken plist that is already on disk. if have plutil && ! plutil -lint "$PLIST" >/dev/null 2>&1; then plutil -lint "$PLIST" 2>&1 | head -3 | sed 's/^/ /' rm -f "$PLIST" die "the LaunchAgent plist this script wrote is not valid and has been removed. Nothing was loaded." fi launchctl bootstrap "gui/$(id -u)" "$PLIST" 2>/dev/null || launchctl load "$PLIST" # VERIFY, because bootstrap succeeding is not the job existing. launchctl print is the only # answer that comes from launchd rather than from the filesystem. if launchctl print "gui/$(id -u)/com.sourceless.strblk-node.$NETWORK" >/dev/null 2>&1; then ok "launchd holds com.sourceless.strblk-node.$NETWORK" else bad "launchd does NOT hold com.sourceless.strblk-node.$NETWORK after bootstrap. The plist is at $PLIST; nothing is running from it." fi fi warn "This is a LaunchAgent, and an Agent runs ONLY while someone is logged into the GUI." info " For a single node you are watching, that is fine. For an Asgard SEAT it is" info " not: a validator that stops when the screen locks is not a validator." info " Use launch/scripts/install-launchd-mac.sh instead, which writes" info " LaunchDaemons from the seat manifest and has been loaded by launchd on" info " a real Mac - plist linted, env file read, node started, same PID after" info " 50 s, and SoftResourceLimits raising the descriptor limit from this" info " machine's default of 256 to 8192, all verified 2026-10-06." info " KeepAlive restarts on exit; it is not the burst limiter systemd gives," info " so a node that cannot start will loop here rather than stop." ;; none) info "no service manager wired. Run it with:" info " $RUNNER" warn "that is a FOREGROUND process and it is not a service. Nothing restarts it, nothing" info " records why it stopped, and nothing outside it knows it is gone. An" info " earlier deployment ran a block generator this way, under nohup; it died" info " and block production stopped with no signal at all. Use a service." if [ "$UNAME" = Linux ] && [ "$AM_ROOT" != 1 ]; then info " --service systemd needs root; --service systemd-user needs none and" info " keeps Restart=always and the burst limiter." fi ;; *) die "unknown --service '$SERVICE'" ;; esac # --------------------------------------------------------------------------------------------- # 10. Start # --------------------------------------------------------------------------------------------- step "start" if [ "$START" != 1 ]; then info "not starting (--no-start). $RUNNER when you are ready." elif [ "$DRY" = 1 ]; then info "would start the node and wait for its endpoints to answer" elif [ "$SERVICE" = systemd ] || [ "$SERVICE" = systemd-user ] || [ "$SERVICE" = launchd ]; then info "started by the service manager" elif [ "$CHANNEL" = docker ]; then docker rm -f "$CONTAINER" >/dev/null 2>&1 || true # The endpoints bind loopback INSIDE the container and a non-loopback bind is refused without # a TLS statement, so publishing these ports to the host would forward to nothing. That is why # verification below goes through docker exec instead. To reach them from the host you need a # TLS terminator in front and --ops-behind-tls-proxy, which is an assertion this installer will # not make on your behalf. DOCKER_ENV_FILE= if [ "$SEAL" != none ] || [ -n "$DASH_SECRET" ]; then # --env-file, NOT -e. The passphrase used to be an argument to docker run, which put it in # this host's process list for the life of the call - readable by EVERY account on the box # with a plain ps, no privileges at all - and in the shell history of whoever ran it. # # mktemp creates the file 0600; the umask makes that the worst case rather than the intent. # It is removed immediately after the call returns, on the failure path as well as the # success one, and a trap covers a Ctrl-C landing between the write and the run. DOCKER_ENV_FILE=$(mktemp 2>/dev/null || printf '%s' "$PREFIX/.brokkr-docker-env.$$") # Guarded on empty: the normal path clears the variable after removing the file, and an # unguarded rm on an empty argument returns non-zero from an EXIT trap under set -e. trap '[ -z "$DOCKER_ENV_FILE" ] || rm -f "$DOCKER_ENV_FILE"' EXIT INT TERM HUP ( umask 077 : > "$DOCKER_ENV_FILE" if [ "$SEAL" != none ]; then printf '%s=%s\n' "$KEY_ENV" "$PASSPHRASE" >> "$DOCKER_ENV_FILE"; fi # The console secret goes in whether or not the keystore is sealed: an unsealed keystore # is a key theft and an open console is a live operator session, and neither implies the # other. Section 5b generated it. if [ -n "$DASH_SECRET" ]; then printf '%s=%s\n' "$DASH_SECRET_ENV" "$DASH_SECRET" >> "$DOCKER_ENV_FILE"; fi ) narrow "$DOCKER_ENV_FILE" "keystore passphrase and console secret" warn "MEASURED, 2026-09-19, docker 27.5.1: --env-file keeps these secrets off this host's" info " process list and out of your shell history. It does NOT keep them out of" info " 'docker inspect'. A container's environment is part of its config" info " whichever flag put it there, and" info " docker inspect --format '{{json .Config.Env}}' printed the value back" info " verbatim in the test that produced this sentence. It will keep doing so" info " for as long as the container exists. So this run closes the ps and the" info " history exposure and nothing else. Closing the inspect exposure needs a" info " node that reads its secrets from mounted files rather than from its" info " environment, or a secrets store; neither is this installer's to choose." fi # Every value one argument: the network flags are rebuilt here rather than word-split from # network_flags, which printed them for reading. if [ -n "$GENESIS" ] && [ "$NETWORK" != custom ]; then set -- --network "$NETWORK" --genesis "$GENESIS" elif [ -n "$GENESIS" ]; then set -- --genesis "$GENESIS" else set -- --network "$NETWORK"; fi if [ -n "$DOCKER_ENV_FILE" ]; then set -- --env-file "$DOCKER_ENV_FILE" "$IMAGE" node --dir /data "$@" else set -- "$IMAGE" node --dir /data "$@"; fi if docker run -d --name "$CONTAINER" -v "$DATADIR:/data" "$@" --block-interval "$BLOCK_INTERVAL" >/dev/null; then DOCKER_STARTED=1 else DOCKER_STARTED=0 fi # Removed BEFORE the die below, so a failed start does not leave a passphrase in a temp file. if [ -n "$DOCKER_ENV_FILE" ]; then rm -f "$DOCKER_ENV_FILE"; DOCKER_ENV_FILE=; fi [ "$DOCKER_STARTED" = 1 ] || die "docker run failed; the passphrase file was removed" ok "container $CONTAINER started" else if [ "$SEAL" = none ]; then "$RUNNER" > "$PREFIX/strblk-$NETWORK.log" 2>&1 & else "$RUNNER" > "$PREFIX/strblk-$NETWORK.log" 2>&1 & fi NODE_PID=$! printf '%s' "$NODE_PID" > "$PREFIX/strblk-$NETWORK.pid" ok "started, pid $NODE_PID, log $PREFIX/strblk-$NETWORK.log" fi if [ "$START" = 1 ] && [ "$DRY" != 1 ]; then # Wait for the endpoint rather than sleeping a fixed time. A fixed sleep is a test that passes # on a fast machine and fails on a slow one, which is how a flaky installer is built. waited=0 probe=http://$LOOPBACK:$OPS_PORT/health if [ "$CHANNEL" = docker ]; then probe=http://$LOOPBACK:$OPS_PORT_DEFAULT/health; fi while [ $waited -lt 90 ]; do if [ "$(http_status "$probe")" = 200 ]; then break; fi sleep 1 waited=$((waited + 1)) done info "waited $waited seconds for the operator endpoint" fi # --------------------------------------------------------------------------------------------- # 11. Verify # --------------------------------------------------------------------------------------------- if [ "$DRY" = 1 ]; then step "verify" info "would run the six checks: identity pin, astrolabe /health, iris /health, the chain the" info " running node serves, gungnir, and peers" say "" say "Dry run complete. Nothing was changed." exit 0 fi if [ "$START" != 1 ]; then say "" say "Installed, not started. Verify after you start it:" say " sh $0 --network $NETWORK --prefix $PREFIX --verify" exit 0 fi VERIFY_RC=0 verify_install || VERIFY_RC=1 step "summary" info "network $NETWORK (chain id $REALM_CHAINID, $REALM_MODE)" info "data $DATADIR" info "ops http://$LOOPBACK:$OPS_PORT/" info "rpc http://$LOOPBACK:$RPC_PORT/rpc" info "dashboard http://$LOOPBACK:$DASH_PORT/" info "re-verify sh $0 --network $NETWORK --prefix $PREFIX --verify" say "" if [ "$VERIFY_RC" != 0 ]; then say "VERIFICATION FAILED: $FAILURES failure(s), $WARNINGS warning(s). The node may be running;" say "it is not the node you asked for. Read the FAIL lines above." exit 1 fi say "Installed and verified: $FAILURES failure(s), $WARNINGS warning(s)." exit 0