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 Agents setup dialog.

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

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, update /etc/p2pstream/agent.env and restart the agent.

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, /etc/p2pstream, /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, delete or disable the agent from Agents.

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 rotationUpdate /etc/p2pstream/agent.env and restart.
Uninstall refuses to runSet P2PSTREAM_UNINSTALL_CONFIRM=full-purge; unsafe paths are intentionally rejected.

Next Steps

Operations documentation for self-hosted p2pstream deployments.