Skip to content

Running WebTunnelAgent as User with systemd

Günter Obiltschnig edited this page Jul 19, 2023 · 1 revision

Running WebTunnelAgent as User with Systemd

It's possible to run WebTunnelAgent as a normal user as a systemd service, without requiring sudo privileges. The following instructions are for an Ubuntu 22.04 system, but should work on other systemd-based distributions.

1. Create directories bin, etc, and var/log in your home directory.

mkdir -p bin etc var/log

2. Download WebTunnelAgent executable, extract (gunzip) and copy it into ~/bin.

curl https://macchina.io/downloads/RemoteManager/SDK/ubuntu/22.04/x86_64/WebTunnelAgent.gz >bin/WebTunnelAgent.gz
gunzip bin/WebTunnelAgent.gz
chmod +x bin/WebTunnelAgent

3. Create WebTunnelAgent.properties configuration file and copy it to ~/etc.

Enable logging to file in the configuration file:

logging.loggers.root.channel = file
logging.channels.file.class = FileChannel
logging.channels.file.pattern = %Y-%m-%d %H:%M:%S.%i [%p] %s<%I>: %t
logging.channels.file.path = ${system.homeDir}var/log/${application.baseName}.log
logging.channels.file.rotation = 100K
logging.channels.file.archive = number
logging.channels.file.purgeCount = 3

4. Create .service file ~/.config/systemd/user/WebTunnelAgent.service

[Unit]
Description=WebTunnelAgent
After=syslog.target network.target 
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/home/user/bin/WebTunnelAgent --config=/home/user/etc/WebTunnelAgent.properties 

[Install]
WantedBy=default.target

Note: replace /home/user with your home directory.

5. Reload systemd daemon

systemctl --user daemon-reload

6. Enable the user-specific daemon to run all the time

Without this, the service will only run while the user is logged in, which is not what we want.

loginctl enable-linger $LOGNAME

7. Enable and start service

systemctl --user enable --now WebTunnelAgent.service