Skip to content

Systemd

Run the p2pstream release binary as a Linux systemd service, or operate an agent installed by the generated Linux installer.

Use This When

Use systemd when you install the release binary directly on a host, or when managing an agent installed from the Agent Setup modal opened from Agents.

Prerequisites

  • Linux with systemd.
  • /usr/local/bin/p2pstream installed.
  • A persistent server data directory such as /var/lib/p2pstream, or an agent env file generated by the installer.

Steps

  1. Create server directories:

    bash
    sudo install -d -m 0700 /var/lib/p2pstream
    sudo install -d -m 0755 /etc/p2pstream
  2. Create /etc/p2pstream/server.env:

    ini
    CONFIG_DIR=/var/lib/p2pstream
    MANAGEMENT_PORT=8081
    MANAGEMENT_PUBLIC_URL=https://proxy.example.com:8081
    ENV=production
  3. Create /etc/systemd/system/p2pstream.service:

    ini
    [Unit]
    Description=p2pstream reverse proxy
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    EnvironmentFile=/etc/p2pstream/server.env
    ExecStart=/usr/local/bin/p2pstream server
    Restart=always
    RestartSec=5s
    User=root
    
    [Install]
    WantedBy=multi-user.target
  4. Enable the server:

    bash
    sudo systemctl daemon-reload
    sudo systemctl enable --now p2pstream
    sudo systemctl status p2pstream

Root is required when binding privileged ports such as 80 or 443. If you only use high ports, run as a dedicated user and adjust ownership of /var/lib/p2pstream.

Agent Service

The generated Linux installer writes:

text
/etc/p2pstream/agent.env
/etc/systemd/system/p2pstream-agent.service

The service runs:

ini
[Service]
EnvironmentFile=/etc/p2pstream/agent.env
ExecStart=/usr/local/bin/p2pstream agent
Restart=always
RestartSec=5s
User=p2pstream
Group=p2pstream
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/lib/p2pstream-agent

Operate it with:

bash
sudo systemctl status p2pstream-agent
sudo systemctl restart p2pstream-agent
sudo journalctl -u p2pstream-agent -f

After rotating an agent token, run the generated Linux reinstall command on the existing agent host. The installer rewrites /etc/p2pstream/agent.env, refreshes installer-managed management CA material, and restarts p2pstream-agent so the new token and TLS settings are loaded. A locally configured AGENT_ALLOW_TARGETS or AGENT_ALLOW_ANY_TARGET policy is preserved when the reinstall command does not provide a replacement. If the existing environment file cannot be read or contains unsupported or multiline assignment syntax, the reinstall stops instead of risking a policy change; provide a replacement explicitly or add AGENT_CLEAR_ALLOW_TARGETS=true to discard the old policy and revert to loopback-only.

The installer also creates /var/lib/p2pstream-agent/management-ca.pem as the service-owned durable trust bundle. Management certificate rotation updates this file atomically. If forced activation strands an otherwise current agent, use the trust-repair command shown under Settings → Management TLS. If the agent version is incompatible or its configuration is damaged, rerun the full generated install command instead.

Uninstall Agent

Use this only for agents installed with the generated Linux systemd installer. Docker Compose agents should be removed with your Compose workflow instead.

The full-purge uninstall removes the agent service, service drop-ins, /etc/p2pstream, /var/lib/p2pstream-agent, /usr/local/bin/p2pstream, and the p2pstream service user and group. Do not run it on a host where those paths or that user are shared with a p2pstream server or another install you want to keep.

Generated command:

bash
curl -fsSL https://raw.githubusercontent.com/Kirari04/p2pstream/main/scripts/uninstall-agent.sh | sudo env P2PSTREAM_UNINSTALL_CONFIRM=full-purge bash

Preview without changing the host:

bash
curl -fsSL https://raw.githubusercontent.com/Kirari04/p2pstream/main/scripts/uninstall-agent.sh | env P2PSTREAM_UNINSTALL_DRY_RUN=true P2PSTREAM_UNINSTALL_CONFIRM=full-purge bash

Uninstalling the host service does not remove the management record. After the remote host is removed, open the agent row's More menu under Agents and delete or disable the management record.

Verification

Check server or agent status:

bash
sudo systemctl status p2pstream
sudo journalctl -u p2pstream -f
sudo systemctl status p2pstream-agent

Troubleshooting

SymptomCheck
Server cannot bind low portsRun as root or use capabilities/high ports.
Agent fails after token rotationRun the generated Linux reinstall command on the existing agent host.
Uninstall refuses to runSet P2PSTREAM_UNINSTALL_CONFIRM=full-purge; unsafe paths are intentionally rejected.

Next Steps

Operations documentation for self-hosted p2pstream deployments.