429 lines
9.4 KiB
Markdown
429 lines
9.4 KiB
Markdown
# TeamSpeak Echoion Bot - Systemd Service
|
|
|
|
This directory contains systemd service files and scripts for running TeamSpeak 3 client with Echoion bot in headless mode using Weston Wayland compositor with RDP backend.
|
|
|
|
## Files
|
|
|
|
- `teamspeak-echoion.service` - System-wide systemd service (runs as root/system)
|
|
- `teamspeak-echoion-user.service` - User systemd service (runs as user)
|
|
- `run-teamspeak-headless.sh` - Wrapper script for manual execution
|
|
- `install-service.sh` - Installation script
|
|
- `start-echoion.sh` - Quick start helper script (handles DBus session issues)
|
|
- `diagnose-echoion.sh` - Diagnostic tool for troubleshooting
|
|
- `start-with-tmux.sh` - Alternative startup using tmux
|
|
|
|
## Prerequisites
|
|
|
|
1. **Weston** - Wayland compositor
|
|
```bash
|
|
sudo pacman -S weston
|
|
```
|
|
|
|
2. **DBus** - For session management
|
|
```bash
|
|
sudo pacman -S dbus
|
|
```
|
|
|
|
3. **TeamSpeak 3 Client** - Installed in `/home/bot/TeamSpeak3-Client-linux_amd64`
|
|
|
|
4. **TLS Certificates** - For RDP connections
|
|
```bash
|
|
# Generate self-signed certificates
|
|
openssl req -x509 -newkey rsa:4096 \
|
|
-keyout ~/.config/EchoionTsBot.key \
|
|
-out ~/.config/EchoionTsBot.crt \
|
|
-days 365 -nodes
|
|
```
|
|
|
|
## Quick Install
|
|
|
|
### Option 1: User Service (Recommended)
|
|
|
|
Run as your bot user:
|
|
```bash
|
|
cd ~/echoion/scripts
|
|
./install-service.sh user
|
|
```
|
|
|
|
This creates a user service that runs as the bot user.
|
|
|
|
**⚠️ Important: DBus Session Error**
|
|
|
|
If you get an error like:
|
|
```
|
|
Failed to connect to user scope bus via local transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined
|
|
```
|
|
|
|
This happens when running from a minimal shell without a full user session. This is **normal** and the service files are still installed correctly. See the [DBus Session section](#dbus-session-setup) below for solutions.
|
|
|
|
### Option 2: System Service
|
|
|
|
Run as root:
|
|
```bash
|
|
cd /path/to/echoion/scripts
|
|
sudo ./install-service.sh system
|
|
```
|
|
|
|
## Manual Installation
|
|
|
|
### User Service
|
|
|
|
1. Copy service file:
|
|
```bash
|
|
mkdir -p ~/.config/systemd/user
|
|
cp teamspeak-echoion-user.service ~/.config/systemd/user/teamspeak-echoion.service
|
|
```
|
|
|
|
2. Copy wrapper script:
|
|
```bash
|
|
mkdir -p ~/echoion/scripts
|
|
cp run-teamspeak-headless.sh ~/echoion/scripts/
|
|
chmod +x ~/echoion/scripts/run-teamspeak-headless.sh
|
|
```
|
|
|
|
3. Reload systemd:
|
|
```bash
|
|
systemctl --user daemon-reload
|
|
```
|
|
|
|
4. Start service:
|
|
```bash
|
|
systemctl --user start teamspeak-echoion
|
|
```
|
|
|
|
5. Enable on login:
|
|
```bash
|
|
systemctl --user enable teamspeak-echoion
|
|
```
|
|
|
|
6. Enable on boot (without login):
|
|
```bash
|
|
sudo loginctl enable-linger $(whoami)
|
|
```
|
|
|
|
### System Service
|
|
|
|
1. Copy service file:
|
|
```bash
|
|
sudo cp teamspeak-echoion.service /etc/systemd/system/
|
|
```
|
|
|
|
2. Edit service file to match your user:
|
|
```bash
|
|
sudo systemctl edit --full teamspeak-echoion
|
|
```
|
|
|
|
3. Reload systemd:
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
```
|
|
|
|
4. Start service:
|
|
```bash
|
|
sudo systemctl start teamspeak-echoion
|
|
```
|
|
|
|
5. Enable on boot:
|
|
```bash
|
|
sudo systemctl enable teamspeak-echoion
|
|
```
|
|
|
|
## DBus Session Setup
|
|
|
|
When running the install script or systemd commands via SSH or a minimal shell, you may encounter:
|
|
```
|
|
Failed to connect to user scope bus via local transport: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined
|
|
```
|
|
|
|
This is normal and the service files are still installed correctly. Here are the solutions:
|
|
|
|
### Solution 1: Use SSH with PTY (Easiest)
|
|
|
|
Connect with a pseudo-terminal allocation:
|
|
```bash
|
|
ssh -t bot@your-server bash
|
|
```
|
|
|
|
Then run systemd commands normally:
|
|
```bash
|
|
systemctl --user daemon-reload
|
|
systemctl --user start teamspeak-echoion
|
|
```
|
|
|
|
### Solution 2: Enable Lingering and Reboot
|
|
|
|
Enable lingering so the user services start on boot without needing a login session:
|
|
```bash
|
|
sudo loginctl enable-linger bot
|
|
```
|
|
|
|
Then reboot the server. After reboot, the service will start automatically.
|
|
|
|
### Solution 3: Manual Start (No systemd)
|
|
|
|
If you just want to test or can't get systemd working:
|
|
```bash
|
|
~/echoion/scripts/run-teamspeak-headless.sh
|
|
```
|
|
|
|
Or use the helper script:
|
|
```bash
|
|
~/echoion/scripts/start-echoion.sh
|
|
```
|
|
|
|
### Solution 4: Use tmux/screen
|
|
|
|
Run in a persistent terminal session:
|
|
```bash
|
|
tmux new-session -d -s teamspeak '~/echoion/scripts/run-teamspeak-headless.sh'
|
|
```
|
|
|
|
To view: `tmux attach -t teamspeak`
|
|
To detach: Press `Ctrl+B` then `D`
|
|
|
|
### Solution 5: System Service (No DBus needed)
|
|
|
|
Install as a system service instead (requires root):
|
|
```bash
|
|
sudo ~/echoion/scripts/install-service.sh system
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Check Service Status
|
|
|
|
**User service:**
|
|
```bash
|
|
systemctl --user status teamspeak-echoion
|
|
```
|
|
|
|
**System service:**
|
|
```bash
|
|
sudo systemctl status teamspeak-echoion
|
|
```
|
|
|
|
### View Logs
|
|
|
|
**User service:**
|
|
```bash
|
|
journalctl --user -u teamspeak-echoion -f
|
|
```
|
|
|
|
**System service:**
|
|
```bash
|
|
sudo journalctl -u teamspeak-echoion -f
|
|
```
|
|
|
|
### Stop Service
|
|
|
|
**User service:**
|
|
```bash
|
|
systemctl --user stop teamspeak-echoion
|
|
```
|
|
|
|
**System service:**
|
|
```bash
|
|
sudo systemctl stop teamspeak-echoion
|
|
```
|
|
|
|
### Restart Service
|
|
|
|
**User service:**
|
|
```bash
|
|
systemctl --user restart teamspeak-echoion
|
|
```
|
|
|
|
**System service:**
|
|
```bash
|
|
sudo systemctl restart teamspeak-echoion
|
|
```
|
|
|
|
## RDP Connection
|
|
|
|
Once the service is running, you can connect via RDP to manage TeamSpeak:
|
|
|
|
**Default port is now 3390** (changed from 3389 to avoid conflicts):
|
|
|
|
```bash
|
|
xfreerdp3 /v:localhost:3390 /u:bot /p: /cert:ignore
|
|
```
|
|
|
|
Or use any RDP client with:
|
|
- **Host**: Your server IP or localhost
|
|
- **Port**: 3390 (default, or change in service file)
|
|
- **Username**: bot (or your configured user)
|
|
- **TLS**: Enabled (uses the certificates you provided)
|
|
|
|
**To use a different port**, edit the service:
|
|
```bash
|
|
systemctl --user edit --full teamspeak-echoion
|
|
```
|
|
|
|
Change `RDP_PORT=3390` to your preferred port.
|
|
|
|
## Configuration
|
|
|
|
Edit the service file to customize:
|
|
|
|
- **User/Group**: Change `bot` to your bot user
|
|
- **Paths**: Update paths to TeamSpeak, certificates, and scripts
|
|
- **Environment**: Add or modify environment variables
|
|
- **Resources**: Adjust `LimitNOFILE` and `LimitNPROC`
|
|
- **Restart policy**: Change `Restart` and `RestartSec` values
|
|
|
|
## Troubleshooting
|
|
|
|
### Service fails to start
|
|
|
|
1. Check logs:
|
|
```bash
|
|
journalctl -u teamspeak-echoion --no-pager -n 50
|
|
```
|
|
|
|
2. Verify certificates exist:
|
|
```bash
|
|
ls -la ~/.config/EchoionTsBot.*
|
|
```
|
|
|
|
3. Test wrapper script manually:
|
|
```bash
|
|
~/echoion/scripts/run-teamspeak-headless.sh
|
|
```
|
|
|
|
### Weston/RDP issues
|
|
|
|
#### Error: "RDP unable to bind socket"
|
|
|
|
This is the most common error. Several things can cause this:
|
|
|
|
**1. Port already in use or permission denied**
|
|
```bash
|
|
# Check if port is in use
|
|
sudo ss -tlnp | grep 3389
|
|
|
|
# Try a different port (edit service file to use port 3390 or higher)
|
|
export RDP_PORT=3390
|
|
~/echoion/scripts/run-teamspeak-headless.sh
|
|
```
|
|
|
|
**2. Certificate issues**
|
|
```bash
|
|
# Check certificates exist and are readable
|
|
ls -la ~/.config/EchoionTsBot.*
|
|
|
|
# Generate new certificates if needed
|
|
openssl req -x509 -newkey rsa:4096 \
|
|
-keyout ~/.config/EchoionTsBot.key \
|
|
-out ~/.config/EchoionTsBot.crt \
|
|
-days 365 -nodes
|
|
|
|
# Fix permissions
|
|
chmod 600 ~/.config/EchoionTsBot.key
|
|
chmod 644 ~/.config/EchoionTsBot.crt
|
|
```
|
|
|
|
**3. Missing weston RDP backend**
|
|
```bash
|
|
# Check if RDP backend is installed
|
|
ls -la /usr/lib/libweston-*/rdp-backend.so
|
|
|
|
# If missing, install weston properly
|
|
sudo pacman -S weston
|
|
```
|
|
|
|
**4. Test weston without TeamSpeak**
|
|
```bash
|
|
# Create test directory
|
|
mkdir -p /tmp/test-weston
|
|
export XDG_RUNTIME_DIR=/tmp/test-weston
|
|
|
|
# Test weston only
|
|
dbus-run-session -- weston --backend=rdp --rdp-port=3390
|
|
|
|
# If this works, the issue is with the full setup
|
|
```
|
|
|
|
**5. Use alternative port (3390 instead of 3389)**
|
|
The service now defaults to port 3390 to avoid conflicts. To change the port:
|
|
|
|
Edit the service file:
|
|
```bash
|
|
systemctl --user edit --full teamspeak-echoion
|
|
```
|
|
|
|
Change:
|
|
```ini
|
|
Environment="RDP_PORT=3390"
|
|
```
|
|
|
|
To your preferred port (e.g., 3391, 3392, etc.)
|
|
|
|
#### Other RDP issues
|
|
|
|
1. Check weston configuration:
|
|
```bash
|
|
cat ~/.config/weston.ini
|
|
```
|
|
|
|
2. Run diagnostic script:
|
|
```bash
|
|
~/echoion/scripts/diagnose-echoion.sh
|
|
```
|
|
|
|
3. Check weston logs:
|
|
```bash
|
|
journalctl --user -u teamspeak-echoion --no-pager -n 100
|
|
```
|
|
|
|
### Permission issues
|
|
|
|
1. Check file ownership:
|
|
```bash
|
|
ls -la ~/TeamSpeak3-Client-linux_amd64/
|
|
ls -la ~/.config/EchoionTsBot.*
|
|
```
|
|
|
|
2. Fix permissions:
|
|
```bash
|
|
sudo chown -R bot:bot ~/TeamSpeak3-Client-linux_amd64/
|
|
sudo chown bot:bot ~/.config/EchoionTsBot.*
|
|
```
|
|
|
|
## Security Notes
|
|
|
|
1. **Firewall**: Restrict RDP port (3389) access to trusted IPs only
|
|
```bash
|
|
sudo ufw allow from 192.168.1.0/24 to any port 3389
|
|
```
|
|
|
|
2. **Certificates**: Use proper TLS certificates in production, not self-signed
|
|
|
|
3. **User permissions**: Run as non-root user with minimal privileges
|
|
|
|
4. **Network isolation**: Consider running in a container or VM for isolation
|
|
|
|
## Uninstallation
|
|
|
|
### User Service
|
|
```bash
|
|
systemctl --user stop teamspeak-echoion
|
|
systemctl --user disable teamspeak-echoion
|
|
rm ~/.config/systemd/user/teamspeak-echoion.service
|
|
systemctl --user daemon-reload
|
|
```
|
|
|
|
### System Service
|
|
```bash
|
|
sudo systemctl stop teamspeak-echoion
|
|
sudo systemctl disable teamspeak-echoion
|
|
sudo rm /etc/systemd/system/teamspeak-echoion.service
|
|
sudo systemctl daemon-reload
|
|
```
|
|
|
|
## See Also
|
|
|
|
- [Weston Documentation](https://wayland.freedesktop.org/weston.html)
|
|
- [systemd Documentation](https://www.freedesktop.org/software/systemd/man/)
|
|
- [TeamSpeak 3 Client](https://www.teamspeak.com/)
|
|
- [Echoion Bot Documentation](../README.md)
|