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:
trannapbinary that you downloaded- If it is Linux, use
systemctl --versionand 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
YOUR_DEVICE_TOKEN with the actual values you obtained earlier. This can be
viewed
after you create the device in the console.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
.exe fromthe 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