Keep TranNAP Running

While TranNAP can be run directly with its command line interface, there are numerous advantages to using a service manager to keep it running, such as ensuring it starts automatically when the system reboots and to capture stdout/stderr logs.

We offer two ways to achieve this goal, namely automatic (recommendation) and manual.

Automatic

This is the recommended method. You only need to perform a few operations, and the rest will be automatically completed by trannapctl. This supports the mainstream operating systems such as Windows, macOS and Linux. If you are using Linux and your distribution is particularly unique, for example if it does not include systemctl, then you may need to do it manually .

Requirements:

  • trannap binary that you downloaded
  • If it is Linux, use systemctl --version and the version number should be 232 or higher.
  • You need to be able to use the command line of the operating system you are using, as some commands will require your permission next.

First, go to the directory where you have downloaded trannap, and then run the following command

Replace YOUR_DEVICE_TOKEN with the actual values you obtained earlier. This can be viewed after you create the device in the console.

If there are no unforeseen circumstances, everything will be completed.

Manual

Linux Service

The recommended way to run TranNAP on Linux distributions with systemd is with our official systemd unit files.

Requirements:

  • trannap binary that you downloaded
  • systemctl --version 232 or newer
  • sudo privileges or root user

Steps

Move the trannap binary into your $PATH, for example:
sudo mv trannap /usr/local/bin/

Test that it worked:

trannap version
Create and save the systemd unit file

Double-check the ExecStart and ExecReload directives. Make sure the binary’s location and command line arguments are correct for your installation! For example: change your --device-token to your actual device token.

/etc/systemd/system/trannap.service
# trannap.service
#
# For using TranNAP.

[Unit]
Description=TranNAP
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/trannap run --device-token your_device_token
TimeoutStopSec=10s
LimitNOFILE=1048576
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
Start the service for the first time
sudo systemctl daemon-reload
sudo systemctl enable --now trannap
Verify that it is running
systemctl status trannap
Now you’re ready to use the service .!

Using the Service

To verify that the service is running:

systemctl status trannap

The status command will also show the location of the currently running service file.

When running with our official service file, TranNAP’s output will be redirected to journalctl. To read your full logs and to avoid lines being truncated:

journalctl -u trannap --no-pager | less +G

You can stop the service with:

sudo systemctl stop trannap

Overrides

The best way to override aspects of the service files is with this command:

sudo systemctl edit trannap

This will open a blank file with your default terminal text editor in which you can override or add directives to the unit definition. This is called a “drop-in” file.

Restart on crash

If you’d like trannap to restart itself after 5s if it ever crashes unexpectedly:

[Service]
# Automatically restart trannap if it crashes except if the exit code was 1
RestartPreventExitStatus=1
Restart=on-failure
RestartSec=5s

Then, save the file and exit the text editor, and restart the service for it to take effect:

sudo systemctl restart trannap

Windows service

There are two ways to run TranNAP as a service on Windows: sc.exe or WinSW .

sc.exe

To create the service, run:

sc.exe create trannap start=auto binPath="YOURPATH\trannap.exe run --device-token YOUR_DEVICE_TOKEN"

(replace YOURPATH with the actual path to your trannap.exe, and YOUR_DEVICE_TOKEN with your actual device token)

To start:

sc.exe start trannap

To stop:

sc.exe stop trannap

WinSW

Install TranNAP as a service on Windows with these instructions.

Requirements:
  • trannap.exe binary that you downloaded
  • Any .exe from the latest release of the WinSW service wrapper (the below service config is written for v2.x releases)

Steps

Put all files into a service directory. In the following examples, we use C:\trannap.

Rename the WinSW-x64.exe file to trannap-service.exe.

Add a trannap-service.xml in the same directory:
<service>
  <id>trannap</id>
  <!-- Display name of the service -->
  <name>TranNAP (powered by WinSW)</name>
  <!-- Service description -->
  <description>TranNAP (https://trannap.com/)</description>
  <executable>%BASE%\trannap.exe</executable>
  <arguments>run --device-token YOUR_DEVICE_TOKEN</arguments>
  <log mode="roll-by-time">
    <pattern>yyyy-MM-dd</pattern>
  </log>
</service>
You can now install the service using:
trannap-service install

You might want to start the Windows Services Console to see if the service is running correctly:

services.msc
Restarting is possible via the normal Windows services commands, for example via the Task Manager’s “Services” tab.

For customizing the service wrapper, see the WinSW documentation