Skip to content

Bare-Metal Packaging Reference

Reference documentation for the internal/packaging module, which handles installing and managing plexd as a systemd service on bare-metal Linux servers.

InstallConfig

Configuration struct for packaging and installing plexd.

FieldTypeDefaultDescription
BinaryPathstring/usr/local/bin/plexdPath to install the plexd binary
ConfigDirstring/etc/plexdConfiguration directory
DataDirstring/var/lib/plexdData directory
RunDirstring/var/run/plexdRuntime directory
UnitFilePathstring/etc/systemd/system/plexd.servicePath for the systemd unit file
ServiceNamestringplexdSystemd service name
APIBaseURLstring(empty)Control plane API URL (optional)
TokenValuestring(empty)Bootstrap token value (optional)
TokenFilestring(empty)Path to token file to copy from (optional)

Methods

  • ApplyDefaults() — Sets default values for zero-valued fields.
  • Validate() error — Returns an error if any required field (BinaryPath, ConfigDir, DataDir, RunDir, ServiceName, UnitFilePath) is empty.

GenerateUnitFile

go
func GenerateUnitFile(cfg InstallConfig) string

Produces a complete systemd unit file. Calls cfg.ApplyDefaults() before generating output.

Unit file directives

SectionDirectiveValuePurpose
[Unit]Descriptionplexd node agentService description
Afternetwork-online.targetStart after network is available
Wantsnetwork-online.targetDeclare network dependency
StartLimitBurst5Max restart attempts in interval
StartLimitIntervalSec60Crash loop protection window (seconds)
[Service]TypesimpleProcess type
ExecStart{BinaryPath} up --config {ConfigDir}/config.yamlStart command
RestartalwaysRestart unconditionally
RestartSec5sDelay between restarts
LimitNOFILE65536File descriptor limit for WireGuard tunnels
EnvironmentFile-{ConfigDir}/environmentOptional environment file (dash = optional)
AmbientCapabilitiesCAP_NET_ADMIN CAP_NET_RAWNetwork capabilities for WireGuard and ICMP
CapabilityBoundingSetCAP_NET_ADMIN CAP_NET_RAWLimit capabilities to required set
ProtectSystemfullMake /usr, /boot, /efi read-only
ProtectHometrueMake /home, /root, /run/user inaccessible
ReadWritePaths{DataDir} {RunDir}Allow writes to data and runtime dirs
[Install]WantedBymulti-user.targetEnable at boot in multi-user mode

GenerateDefaultConfig

go
func GenerateDefaultConfig(apiBaseURL string) string

Produces a minimal default config.yaml. When apiBaseURL is empty, writes a commented-out placeholder.

Output fields

FieldValueDescription
api.base_urlProvided URL or # api: base_url: …Control plane API URL
data_dir/var/lib/plexdData directory
log_levelinfoLog verbosity
registration.token_file/etc/plexd/bootstrap-tokenBootstrap token file path

Installer

go
func NewInstaller(cfg InstallConfig, systemd SystemdController, root RootChecker, logger *slog.Logger) *Installer

Install() error

Installs plexd as a systemd service. Steps:

  1. Verify root privileges (RootChecker.IsRoot())
  2. Verify systemd is available (SystemdController.IsAvailable())
  3. Create directories: ConfigDir (0755), DataDir (0700), RunDir (0755)
  4. Copy the running binary to BinaryPath (0755)
  5. Write default config.yaml if absent (preserves existing)
  6. Write bootstrap token if TokenValue or TokenFile is set (0600)
  7. Write systemd unit file to UnitFilePath (0644)
  8. Execute systemctl daemon-reload

Uninstall(purge bool) error

Removes the plexd systemd service. Steps:

  1. Verify root privileges
  2. If unit file does not exist, return nil (idempotent)
  3. Stop service (errors tolerated — service may not be running)
  4. Disable service
  5. Remove unit file
  6. Execute systemctl daemon-reload
  7. Remove binary
  8. If purge is true, remove DataDir and ConfigDir recursively

Interfaces

SystemdController

go
type SystemdController interface {
    IsAvailable() bool
    DaemonReload() error
    Enable(service string) error
    Disable(service string) error
    Stop(service string) error
    IsActive(service string) bool
}

Production implementation (NewSystemdController()) uses os/exec to call systemctl.

RootChecker

go
type RootChecker interface {
    IsRoot() bool
}

Production implementation (NewRootChecker()) uses os.Getuid() == 0.

File paths and permissions

PathPermissionCreated byDescription
/usr/local/bin/plexd0755Installplexd binary
/etc/plexd/0755InstallConfiguration directory
/etc/plexd/config.yaml0644InstallService configuration
/etc/plexd/bootstrap-token0600InstallBootstrap token
/etc/plexd/environment(user)OperatorOptional env vars
/var/lib/plexd/0700InstallData directory
/var/run/plexd/0755InstallRuntime directory
/etc/systemd/system/plexd.service0644InstallSystemd unit file

Token validation

Bootstrap tokens are validated with the same rules as internal/registration/token.go:

  • Maximum length: 512 bytes
  • Characters: printable ASCII only (0x20–0x7E)
  • Token priority: TokenValue > TokenFile
  • Written to {ConfigDir}/bootstrap-token with 0600 permissions

Install script

The install script (deploy/install.sh) is a POSIX-compatible shell script.

Usage

sh
curl -fsSL https://get.plexsphere.com/install.sh | sh -s -- [OPTIONS]

Flags

FlagDescriptionDefault
--token VALUEBootstrap token for enrollment(none)
--api-url URLControl plane API URL(none)
--version VERSIONVersion to installlatest
--no-startDon't start the service after install(start)

Behavior

  1. Detects OS (Linux required)
  2. Detects architecture (x86_64amd64, aarch64arm64)
  3. Downloads binary from artifact URL
  4. Downloads and verifies SHA-256 checksum
  5. Runs plexd install with passthrough flags
  6. Enables and starts the service (unless --no-start)
  7. Cleans up temporary files on exit

Environment variables

VariableDescriptionDefault
PLEXD_ARTIFACT_URLBase URL for binary artifactshttps://artifacts.plexsphere.com/plexd