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 run a single command, and trannap takes care of the rest — registering itself as a system service and starting it. It supports mainstream operating systems: Windows, macOS, and Linux. If you are on a Linux distribution that does not ship systemctl (for example, an unusual init setup), you may need to set things up
manually
.
Requirements
- The
trannapbinary, which you downloaded as a.ziparchive whose name depends on your OS and architecture (for exampletrannap-v3.0.2-linux-arm64.zip). Extract it first. - On Linux,
systemctl --versionshould report 232 or newer. - Command-line access on your operating system (some commands require administrator/root permissions).
First, extract the archive and switch to the folder containing trannap, then run the install command below.
YOUR_DEVICE_TOKEN with the token you copied earlier. You can find it after creating the device in the console (see
Copy the device token
).trannap start manually. If all went well, everything is set up.Manual
Linux Service
The recommended way to run TranNAP on Linux distributions with systemd is with our official systemd unit files.
Requirements:
trannapbinary that you downloadedsystemctl --version232 or newersudoprivileges orrootuser
Steps
Move the trannap binary into your $PATH, for example:
Test that it worked:
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.
# 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.targetStart the service for the first time
Verify that it is running
Using the Service
To verify that the service is running:
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:
You can stop the service with:
Overrides
The best way to override aspects of the service files is with this command:
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=5sThen, save the file and exit the text editor, and restart the service for it to take effect:
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:
To stop:
WinSW
Install TranNAP as a service on Windows with these instructions.
Requirements:
trannap.exebinary that you downloaded- Any
.exefrom 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:
You might want to start the Windows Services Console to see if the service is running correctly:
For customizing the service wrapper, see the WinSW documentation