selfhost

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package selfhost installs the workspace platform on a customer's own server (ADR-0021): Ubuntu 24.04+ with Docker and systemd. PostgreSQL runs as a container with a volume; the platform is the devopus-server binary run by systemd as a system user, with its settings in an environment file only root reads. Every action goes through a Host, so a dry run prints them and tests check them.

Index

Constants

View Source
const (
	EnvFile     = "/etc/devopus/server.env"
	PGEnvFile   = "/etc/devopus/postgres.env"
	UnitFile    = "/etc/systemd/system/devopus-server.service"
	Service     = "devopus-server"
	DataDir     = "/var/lib/devopus-server"
	BackupDir   = "/var/backups/devopus-server"
	User        = "devopus"
	PGContainer = "devopus-server-postgres"
	PGVolume    = "devopus-server-pgdata"
	PGImage     = "postgres:17-alpine"
	PGPort      = "5439"
	Database    = "devopus"
)

Where things go on the server.

Variables

This section is empty.

Functions

func Backup

func Backup(ctx context.Context, h Host, now time.Time) (string, error)

Backup dumps the database into the backup folder and returns the file.

func Download

func Download(ctx context.Context, base string) ([]byte, error)

Download fetches the devopus-server binary of a release for this machine, checked against the release's checksums.

func Health

func Health(ctx context.Context, url string) error

Health asks the running server whether it and its database answer.

func Install

func Install(ctx context.Context, h Host, o Options) error

Install sets the server up, or updates an installed one: the database password and data stay.

func ReadEnv

func ReadEnv(h Host) (map[string]string, error)

ReadEnv reads the settings of an installed server.

func ReleaseURL

func ReleaseURL(version string) string

ReleaseURL is where releases are: $DEVOPUS_BASE_URL, as for install.sh.

func Replace

func Replace(binary string, data []byte) error

Replace puts a new binary in place of the running one with a rename: the running server keeps its file until it restarts.

func Restore

func Restore(ctx context.Context, h Host, file string) error

Restore loads a backup into the database, with the server stopped meanwhile.

func Uninstall

func Uninstall(ctx context.Context, h Host, purge bool) error

Uninstall removes the service; purge removes the database with its data too.

func Unit

func Unit(binary string) string

Unit is the systemd service.

Types

type DryRun

type DryRun struct{ Out io.Writer }

DryRun prints what would be done and does nothing; reads find nothing.

func (DryRun) MkdirAll

func (d DryRun) MkdirAll(p string, perm os.FileMode) error

func (DryRun) ReadFile

func (d DryRun) ReadFile(string) ([]byte, error)

func (DryRun) Remove

func (d DryRun) Remove(p string) error

func (DryRun) Run

func (d DryRun) Run(_ context.Context, name string, args ...string) (string, error)

func (DryRun) RunInput

func (d DryRun) RunInput(ctx context.Context, _ io.Reader, name string, args ...string) (string, error)

func (DryRun) WriteFile

func (d DryRun) WriteFile(p string, data []byte, perm os.FileMode) error

type Host

type Host interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
	// RunInput runs a command with stdin (a restore feeds the dump in).
	RunInput(ctx context.Context, in io.Reader, name string, args ...string) (string, error)
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	Remove(path string) error
	MkdirAll(path string, perm os.FileMode) error
}

Host runs commands and writes files on the server.

type Options

type Options struct {
	// Domain the server answers on, with HTTPS from Let's Encrypt; its DNS must point
	// here and ports 80 and 443 be open.
	Domain string
	// Workspace and Owner make the platform's one workspace at its first start: its
	// name and its owner's email. A later install keeps them unless given again.
	Workspace, Owner string
	// Mail sends invites: "log" or smtp://user:password@host:587, from MailFrom.
	Mail, MailFrom string
	// Binary is the devopus-server binary systemd runs.
	Binary string
	Log    io.Writer
}

Options of an install.

type Status

type Status struct {
	Installed bool
	Domain    string
	Service   string // active, inactive, failed…
	Database  string // running, stopped, missing
}

Status describes the installed server.

func ReadStatus

func ReadStatus(ctx context.Context, h Host) Status

type System

type System struct{}

System is the real host.

func (System) MkdirAll

func (System) MkdirAll(p string, perm os.FileMode) error

func (System) ReadFile

func (System) ReadFile(p string) ([]byte, error)

func (System) Remove

func (System) Remove(p string) error

func (System) Run

func (System) Run(ctx context.Context, name string, args ...string) (string, error)

func (System) RunInput

func (System) RunInput(ctx context.Context, in io.Reader, name string, args ...string) (string, error)

func (System) WriteFile

func (System) WriteFile(p string, d []byte, perm os.FileMode) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL