Skip to content

Setup systemd Service (Production Deployment)

This section explains how to configure TG-FileStream using systemd for:

  • Automatic startup on boot
  • Automatic restart on crash
  • Proper process isolation

This guide follows the recommended production setup.


1. Create Main Service File

Create the service file:

sudo nano /etc/systemd/system/tgfs.service

Paste the following:

[Unit]
Description=TG-FileStream
After=network.target

[Service]
Type=simple
User=<username>
Group=<group>

WorkingDirectory=<TG-FileStream Clone Path>

ExecStart=<TG-FileStream Clone Path>/<virtual-env-dir>/bin/python -m tgfs

Restart=always
RestartSec=3

NoNewPrivileges=true
PrivateTmp=true

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

Adjust:

  • Replace <username> with your system username.
  • Replace <group> with your group name (often same as username).
  • Replace <TG-FileStream Clone Path> with the absolute path to your cloned TG-FileStream directory.
  • Replace <virtual-env-dir> with the name of your virtual environment directory (usually venv).

Example
[Unit]
Description=TG-FileStream
After=network.target

[Service]
Type=simple
User=ubuntu
Group=ubuntu

WorkingDirectory=/home/ubuntu/tg-filestream

ExecStart=/home/ubuntu/tg-filestream/venv/bin/python -m tgfs

Restart=always
RestartSec=3

NoNewPrivileges=true
PrivateTmp=true

StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

2. Reload systemd

sudo systemctl daemon-reload

3. Enable Service

Enable the service to start on boot:

sudo systemctl enable tgfs

4. Start Service

sudo systemctl start tgfs

5. Check Status

sudo systemctl status tgfs

The service should show as:

Active: active (running)

6. View Logs

sudo journalctl -u tgfs -f

Restart & Stop Commands

Restart:

sudo systemctl restart tgfs

Stop:

sudo systemctl stop tgfs