Use the auto-updating Blacktip, Bamboo and Reef; add the -auto-update option
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09f4f30984
commit
719449f6fa
8 files changed
+49
-13
No files matched your search
@@ -38,3 +38,7 @@ HAMMERHEAD_MASTER_KEY=
|
||||
# Token from Sites -> Show command.
|
||||
#BAMBOO_HAMMERHEAD=https://hammerhead.example.com
|
||||
#BAMBOO_TOKEN=
|
||||
|
||||
# Check for new releases every few hours and update and restart by itself (Linux and macOS).
|
||||
# setup.sh turns this on; remove it to update by hand.
|
||||
#HAMMERHEAD_AUTO_UPDATE=1
|
||||
@@ -69,6 +69,10 @@ sudo systemctl start hammerhead
|
||||
|
||||
Use `linux_arm64` or `linux_arm` for Raspberry Pi and other ARM machines. To upgrade, repeat the same steps: your settings and data are kept. `sudo ./install.sh --uninstall` removes the service and binary but leaves `/etc/hammerhead` and `/var/lib/hammerhead` alone. `hammerhead -version` tells you which build is running.
|
||||
|
||||
**Updates**
|
||||
|
||||
Set `HAMMERHEAD_AUTO_UPDATE=1` (or pass `-auto-update`) and Hammerhead checks this server for a newer release every few hours, verifies it against `SHA256SUMS`, checks that the new binary runs, swaps it in and restarts itself. It only follows full releases (never pre-releases), never downgrades, and keeps the old binary if anything looks wrong. `setup.sh` turns it on. It is not available on Windows, and it is for the systemd and plain-binary installs: with Docker, pull a new image instead.
|
||||
|
||||
**With Docker**
|
||||
|
||||
```
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"git.veillax.com/Veillax/hammerhead"
|
||||
"git.veillax.com/Veillax/hammerhead/internal/secretbox"
|
||||
"git.veillax.com/Veillax/reef/dotenv"
|
||||
"git.veillax.com/Veillax/reef/selfupdate"
|
||||
)
|
||||
|
||||
// version is set at build time (deploy/build.sh).
|
||||
@@ -39,6 +41,7 @@ func main() {
|
||||
url := flag.String("url", env("HAMMERHEAD_URL", ""), "public URL people reach hammerhead at (used for login redirects and SSO); can also be set in Settings")
|
||||
flag.String("env", ".env", "file to read secrets and settings from")
|
||||
genkey := flag.Bool("genkey", false, "print a new random HAMMERHEAD_MASTER_KEY and exit")
|
||||
autoUpdate := flag.Bool("auto-update", os.Getenv("HAMMERHEAD_AUTO_UPDATE") == "1", "check for new releases every few hours and update and restart by itself (Linux and macOS)")
|
||||
showVersion := flag.Bool("version", false, "print the version and exit")
|
||||
flag.Parse()
|
||||
if *showVersion {
|
||||
@@ -63,6 +66,9 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer srv.Close()
|
||||
if *autoUpdate {
|
||||
go selfupdate.Run(context.Background(), selfupdate.Config{Server: "https://git.veillax.com", Repo: "Veillax/hammerhead", App: "hammerhead", Current: version, Logf: log.Printf, Restart: func(exe string) error { srv.Close(); return selfupdate.Restart(exe) }})
|
||||
}
|
||||
log.Printf("hammerhead %s listening on %s (open it in a browser to finish setup)", version, *listen)
|
||||
hs := &http.Server{Addr: *listen, Handler: srv.Handler(), ReadHeaderTimeout: 10 * time.Second}
|
||||
log.Fatal(hs.ListenAndServe())
|
||||
|
||||
@@ -8,7 +8,7 @@ Wants=network-online.target
|
||||
User=hammerhead
|
||||
Group=hammerhead
|
||||
EnvironmentFile=-/etc/hammerhead/hammerhead.env
|
||||
ExecStart=/usr/local/bin/hammerhead -listen :8080 -data /var/lib/hammerhead
|
||||
ExecStart=/usr/local/lib/hammerhead/hammerhead -listen :8080 -data /var/lib/hammerhead
|
||||
WorkingDirectory=/var/lib/hammerhead
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
@@ -16,7 +16,7 @@ RestartSec=3
|
||||
# It only needs its own data folder and the network.
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ReadWritePaths=/var/lib/hammerhead
|
||||
ReadWritePaths=/var/lib/hammerhead /usr/local/lib/hammerhead
|
||||
ProtectHome=true
|
||||
PrivateTmp=true
|
||||
ProtectKernelTunables=true
|
||||
|
||||
+12
-6
@@ -5,7 +5,7 @@
|
||||
# sudo ./install.sh --start the same, then start (or restart) the service
|
||||
# sudo ./install.sh --uninstall remove the service and binary (keeps the settings and data)
|
||||
#
|
||||
# Files: /usr/local/bin/hammerhead, /etc/systemd/system/hammerhead.service,
|
||||
# Files: /usr/local/lib/hammerhead/hammerhead (linked from /usr/local/bin/hammerhead), /etc/systemd/system/hammerhead.service,
|
||||
# /etc/hammerhead/hammerhead.env (your settings and secrets), /var/lib/hammerhead (data).
|
||||
# Set DESTDIR=/some/dir to stage everything there without touching the system.
|
||||
set -eu
|
||||
@@ -17,6 +17,7 @@ UNIT=$ROOT/etc/systemd/system/$NAME.service
|
||||
CONF=$ROOT/etc/$NAME
|
||||
ENVFILE=$CONF/$NAME.env
|
||||
DATA=$ROOT/var/lib/$NAME
|
||||
LIB=$ROOT/usr/local/lib/$NAME # the program lives here, owned by the service, so auto-update can replace it
|
||||
|
||||
say() { printf '%s\n' "$*"; }
|
||||
real() { [ -z "${DESTDIR:-}" ]; } # are we touching the real system?
|
||||
@@ -30,7 +31,7 @@ if [ "${1:-}" = "--uninstall" ]; then
|
||||
if real; then
|
||||
systemctl disable --now "$NAME" > /dev/null 2>&1 || true
|
||||
fi
|
||||
rm -f "$UNIT" "$BIN"
|
||||
rm -f "$UNIT" "$BIN" "$LIB/$NAME"
|
||||
if real; then
|
||||
systemctl daemon-reload || true
|
||||
fi
|
||||
@@ -46,15 +47,20 @@ if real && ! id "$NAME" > /dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
mkdir -p "$ROOT/usr/local/bin" "$ROOT/etc/systemd/system" "$CONF" "$DATA"
|
||||
install -m 0755 "$HERE/$NAME" "$BIN.new"
|
||||
mv -f "$BIN.new" "$BIN" # atomic, so upgrading a running service is safe
|
||||
mkdir -p "$LIB"
|
||||
install -m 0755 "$HERE/$NAME" "$LIB/$NAME.new"
|
||||
mv -f "$LIB/$NAME.new" "$LIB/$NAME" # atomic, so upgrading a running service is safe
|
||||
rm -f "$BIN"
|
||||
LINK=/usr/local/lib/$NAME/$NAME
|
||||
[ -z "${DESTDIR:-}" ] || LINK=$LIB/$NAME # staging: point inside the staging folder
|
||||
ln -s "$LINK" "$BIN"
|
||||
install -m 0644 "$HERE/$NAME.service" "$UNIT"
|
||||
if [ ! -f "$ENVFILE" ]; then
|
||||
install -m 0600 "$HERE/.env.example" "$ENVFILE"
|
||||
say "Created $ENVFILE. Edit it before starting."
|
||||
fi
|
||||
if real; then
|
||||
chown -R "$NAME:$NAME" "$DATA"
|
||||
chown -R "$NAME:$NAME" "$DATA" "$LIB"
|
||||
fi
|
||||
|
||||
if real; then
|
||||
@@ -66,7 +72,7 @@ if real; then
|
||||
fi
|
||||
fi
|
||||
|
||||
say "Installed $("$BIN" -version 2> /dev/null || echo "$NAME")."
|
||||
say "Installed $("$LIB/$NAME" -version 2> /dev/null || echo "$NAME")."
|
||||
say "Next:"
|
||||
say " 1. edit $ENVFILE"
|
||||
say " 2. systemctl start $NAME (or run this again with --start)"
|
||||
|
||||
+12
-2
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# One-shot setup for a VPS. Run as root.
|
||||
#
|
||||
# sh setup.sh [--domain hh.example.com] [--version v0.1.0] Hammerhead (dashboard and API)
|
||||
# sh setup.sh [--domain hh.example.com] [--version v0.1.0] [--no-auto-update] Hammerhead (dashboard and API)
|
||||
# sh setup.sh edge --hammerhead URL --token TOKEN [--ports 25565,30000-30100] [--version V]
|
||||
# sh setup.sh agent --hammerhead URL --token TOKEN [--version V]
|
||||
#
|
||||
@@ -20,7 +20,7 @@ set -eu
|
||||
BASE=${SHARKS_BASE:-https://git.veillax.com/Veillax}
|
||||
MODE=hammerhead
|
||||
case "${1:-}" in edge | agent) MODE=$1; shift ;; esac
|
||||
DOMAIN= VERSION= HH= TOKEN= PORTS=
|
||||
DOMAIN= VERSION= HH= TOKEN= PORTS= AUTOUP=1
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--domain) DOMAIN=$2; shift 2 ;;
|
||||
@@ -28,11 +28,18 @@ while [ $# -gt 0 ]; do
|
||||
--hammerhead) HH=$2; shift 2 ;;
|
||||
--token) TOKEN=$2; shift 2 ;;
|
||||
--ports) PORTS=$2; shift 2 ;;
|
||||
--no-auto-update) AUTOUP=0; shift ;;
|
||||
-h | --help) sed -n '2,16p' "$0"; exit 0 ;;
|
||||
*) echo "unknown option $1 (see --help)" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# auto_update <file> <PREFIX>: lets the program update itself unless --no-auto-update was given
|
||||
auto_update() {
|
||||
[ "$AUTOUP" = 1 ] && set_env "$1" "$2_AUTO_UPDATE" 1
|
||||
return 0
|
||||
}
|
||||
|
||||
say() { printf '\n== %s\n' "$*"; }
|
||||
die() { echo "error: $*" >&2; exit 1; }
|
||||
[ "$(id -u)" = 0 ] || die "run as root: sudo sh $0 $*"
|
||||
@@ -123,6 +130,7 @@ case $MODE in
|
||||
hammerhead)
|
||||
fetch_install hammerhead
|
||||
ENVF=/etc/hammerhead/hammerhead.env
|
||||
auto_update "$ENVF" HAMMERHEAD
|
||||
if ! grep -q '^HAMMERHEAD_MASTER_KEY=.' "$ENVF"; then
|
||||
say "generating the master key"
|
||||
set_env "$ENVF" HAMMERHEAD_MASTER_KEY "$(/usr/local/bin/hammerhead -genkey)"
|
||||
@@ -166,6 +174,7 @@ edge)
|
||||
ENVF=/etc/blacktip/blacktip.env
|
||||
set_env "$ENVF" BLACKTIP_HAMMERHEAD "$HH"
|
||||
set_env "$ENVF" BLACKTIP_TOKEN "$TOKEN"
|
||||
auto_update "$ENVF" BLACKTIP
|
||||
chmod 600 "$ENVF"
|
||||
say "network"
|
||||
# WireGuard moves a lot of UDP; the stock socket buffers are small
|
||||
@@ -202,6 +211,7 @@ agent)
|
||||
ENVF=/etc/bamboo/bamboo.env
|
||||
set_env "$ENVF" BAMBOO_HAMMERHEAD "$HH"
|
||||
set_env "$ENVF" BAMBOO_TOKEN "$TOKEN"
|
||||
auto_update "$ENVF" BAMBOO
|
||||
chmod 600 "$ENVF"
|
||||
if command -v docker > /dev/null 2>&1 && getent group docker > /dev/null 2>&1; then
|
||||
usermod -aG docker bamboo
|
||||
|
||||
@@ -3,9 +3,9 @@ module git.veillax.com/Veillax/hammerhead
|
||||
go 1.27.3
|
||||
|
||||
require (
|
||||
git.veillax.com/Veillax/bamboo v0.1.0
|
||||
git.veillax.com/Veillax/blacktip v0.1.0
|
||||
git.veillax.com/Veillax/reef v0.1.0
|
||||
git.veillax.com/Veillax/bamboo v0.1.3
|
||||
git.veillax.com/Veillax/blacktip v0.1.4
|
||||
git.veillax.com/Veillax/reef v0.1.3
|
||||
github.com/emersion/go-msgauth v0.7.0
|
||||
golang.org/x/crypto v0.58.0
|
||||
modernc.org/sqlite v1.61.0
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
git.veillax.com/Veillax/bamboo v0.1.0 h1:16BG1P8982dIkHA2l0LPS0xYQc8d86PruVAGxc8BP84=
|
||||
git.veillax.com/Veillax/bamboo v0.1.0/go.mod h1:i4l4uJgG6Ymfwbjnlz0xeTt3qW/+1W1L2JBToMw50n0=
|
||||
git.veillax.com/Veillax/bamboo v0.1.3 h1:A66gz9GmmtUq1iIGUAL2ItIeC6iTy5pvqJOoIjRHjFg=
|
||||
git.veillax.com/Veillax/bamboo v0.1.3/go.mod h1:UuHV6aNHmV9jpow0xeGlXX0QhMB9glPJUGzgIM7S1MM=
|
||||
git.veillax.com/Veillax/blacktip v0.1.0 h1:L8WpW56gqtvZ1IAapE95Ynl6NKjqTA98WwmEH01kFFk=
|
||||
git.veillax.com/Veillax/blacktip v0.1.0/go.mod h1:sj+mr8393rajzWbl0+RRZrstGyDtZ/GHsut6ebScVxg=
|
||||
git.veillax.com/Veillax/blacktip v0.1.4 h1:o3uNoA0ucB/qcN9ccofysdFA6RTEU4jKdgeTWuE2Uw0=
|
||||
git.veillax.com/Veillax/blacktip v0.1.4/go.mod h1:f7zXCYlQf/9ffDLjPrMHylKAyXX4Nb+aQ7kErmOOhqI=
|
||||
git.veillax.com/Veillax/reef v0.1.0 h1:O0OhEKFx2CsvACJ20sfzJNjGsngomtfDdKdxu4ROpCs=
|
||||
git.veillax.com/Veillax/reef v0.1.0/go.mod h1:ZBUd/BARO5kkpUNTP81TTY1aQXLHFR6bKDhCxckjHso=
|
||||
git.veillax.com/Veillax/reef v0.1.3 h1:RxSq2xwaup1+MieAkhlvOTZnYwPf19thFHEAe/7VxsI=
|
||||
git.veillax.com/Veillax/reef v0.1.3/go.mod h1:ZBUd/BARO5kkpUNTP81TTY1aQXLHFR6bKDhCxckjHso=
|
||||
github.com/Microsoft/go-winio v0.6.4 h1:kJF2pamtYCWXf0xAT8sAkwKC0pMl2HYBrRPHAqyUc+g=
|
||||
github.com/Microsoft/go-winio v0.6.4/go.mod h1:1xl5JXG4ze/m74GH6Dc4Mwxfc3VL5siRVQjIAlHH07U=
|
||||
github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg=
|
||||
|
||||
Reference in new issue
Block a user