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:
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 (usuallyvenv).
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¶
3. Enable Service¶
Enable the service to start on boot:
4. Start Service¶
5. Check Status¶
The service should show as:
6. View Logs¶
Restart & Stop Commands¶
Restart:
Stop: