How to Configure Portwarp CLI to Start Automatically on Boot (Linux) - (Updated)
If you are running Portwarp on a Linux distribution that uses systemd
(such as Ubuntu, Debian, Fedora, or Arch Linux), you can configure Portwarp to
start at boot and keep running as a service.
After completing this guide:
- Portwarp starts automatically whenever the system boots.
- All of your enabled tunnels reconnect in the background.
- systemd restarts Portwarp if the daemon exits unexpectedly, then reconnects
Requirements
- A Linux distribution withsystemd
- Portwarp CLI installed
- Logged in withpwrp loginas the Linux user that will run the service
Before creating the service, verify that the CLI can connect your tunnels as
that user:
pwrp connect --all --detach
pwrp psStop those test sessions before continuing:
pwrp stop --allStep 1: Create the service file
Create a templated service file:
sudo nano /etc/systemd/system/[email protected]The @ is important: it lets the service run as the Linux user supplied when
it is enabled. In this guide, %i means that service-instance username; it is
not a tunnel name.
Step 2: Paste the service configuration
Paste the following into the file:
[Unit]
Description=Portwarp tunnels for %i
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=%i
Environment=HOME=/home/%i
WorkingDirectory=/home/%i
# Start the daemon, wait until its local socket is ready, then connect every
# enabled tunnel. The shell remains running while the daemon is running, so
# systemd can restart the whole service if the daemon exits.
ExecStart=/bin/sh -c '/usr/local/bin/pwrp daemon & daemon_pid=$!; until [ -S "$HOME/.portwarp/daemon.sock" ]; do sleep 0.1; done; /usr/local/bin/pwrp connect --all --detach || { kill "$daemon_pid"; wait "$daemon_pid"; exit 1; }; wait "$daemon_pid"'
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=pwrp
[Install]
WantedBy=multi-user.targetIf which pwrp reports a path other than /usr/local/bin/pwrp, replace both
occurrences of /usr/local/bin/pwrp in ExecStart with that path.
Save the file and exit your editor. In Nano, press Ctrl+O, Enter, thenCtrl+X.
Step 3: Reload systemd
Tell systemd to reload its service definitions:
sudo systemctl daemon-reloadStep 4: Enable the service
Enable the service for your current Linux user so it starts automatically after
every boot:
sudo systemctl enable pwrp@$(whoami)Step 5: Start the service
Start Portwarp now, without waiting for the next reboot:
sudo systemctl start pwrp@$(whoami)Verify it is running
Check the service and its tunnel sessions:
sudo systemctl status pwrp@$(whoami)
pwrp psTo follow the service logs:
sudo journalctl -u pwrp@$(whoami) -fDone
Portwarp now starts automatically at boot and connects every enabled tunnel.
To connect only selected tunnels instead, replace --all in the ExecStart
line with their exact tunnel IDs or names, for example:
pwrp connect 6fc2dc65 "Minecraft Java" --detachAfter changing the service file, run:
sudo systemctl daemon-reload
sudo systemctl restart pwrp@$(whoami)