Wiki-Quellcode von Anleitung Automatisierung

Zuletzt geändert von René Schmidt am 2025/10/12 08:43

Zeige letzte Bearbeiter
1
2
3 == 1. Was du JETZT eintragen musst ==
4
5 **Öffne bot.py:**
6
7 {{{nano ~/matrix_bot/bot.py
8 }}}
9
10 **Ändere diese Zeilen:**
11
12 **Zeile 40:** Access Token
13
14 {{{ACCESS_TOKEN = "syt_dGVycnk_..." # Dein Token hier
15 }}}
16
17 **Zeile 48:** Ollama URL (falls anders)
18
19 {{{OLLAMA_URL = "http://192.168.10.210:11434" # Deine Ollama-IP
20 }}}
21
22 **Zeile 27:** Webhook Secret (ändere zu eigenem)
23
24 {{{WEBHOOK_SECRET = "mein-super-secret-key-xyz"
25 }}}
26
27 **Speichern:** STRG+O → ENTER → STRG+X
28
29 ----
30
31 == 2. Autostart mit systemd einrichten ==
32
33 **Erstelle Service-Datei:**
34
35 {{{sudo nano /etc/systemd/system/matrix-bot.service
36 }}}
37
38 **Füge ein:**
39
40 {{{[Unit]
41 Description=Terry Matrix Bot with AI
42 After=network.target matrix-synapse.service
43
44 [Service]
45 Type=simple
46 User=root
47 WorkingDirectory=/root/matrix_bot
48 Environment="PATH=/root/matrix_bot/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
49 ExecStart=/root/matrix_bot/venv/bin/python /root/matrix_bot/bot.py
50 Restart=always
51 RestartSec=10
52
53 # Logging
54 StandardOutput=journal
55 StandardError=journal
56 SyslogIdentifier=matrix-bot
57
58 [Install]
59 WantedBy=multi-user.target
60 }}}
61
62 **Speichern:** STRG+O → ENTER → STRG+X
63
64 **Aktiviere und starte:**
65
66 {{{# Service neu laden
67 sudo systemctl daemon-reload
68
69 # Autostart aktivieren
70 sudo systemctl enable matrix-bot
71
72 # Jetzt starten
73 sudo systemctl start matrix-bot
74
75 # Status prüfen
76 sudo systemctl status matrix-bot
77
78 # Logs ansehen
79 journalctl -u matrix-bot -f
80 }}}
81
82 ----
83
84 == 3. Pakete installieren ==
85
86 {{{cd ~/matrix_bot
87 source venv/bin/activate
88
89 # Basis-Pakete
90 pip install matrix-nio aiohttp
91
92 # Multimedia-Pakete
93 pip install PyPDF2 python-docx pandas pillow openpyxl
94
95 # Optional: Whisper für Sprache
96 pip install openai-whisper
97 }}}
98
99 ----
100
101 == 4. Ollama Vision installieren ==
102
103 **Auf dem Ollama-Server:**
104
105 {{{# Vision Model
106 ollama pull llama3.2-vision
107
108 # Prüfen
109 ollama list
110 }}}
111
112 ----
113
114 == 5. Nützliche Befehle ==
115
116 {{{# Bot starten
117 sudo systemctl start matrix-bot
118
119 # Bot stoppen
120 sudo systemctl stop matrix-bot
121
122 # Bot neu starten
123 sudo systemctl restart matrix-bot
124
125 # Status
126 sudo systemctl status matrix-bot
127
128 # Logs live ansehen
129 journalctl -u matrix-bot -f
130
131 # Logs der letzten Stunde
132 journalctl -u matrix-bot --since "1 hour ago"
133
134 # Autostart deaktivieren
135 sudo systemctl disable matrix-bot
136 }}}
137
138 ----
139
140 == 6. Test-Checklist ==
141
142 Nach dem Start teste:
143
144 {{{✅ /status → Bot antwortet
145 ✅ hey terry → Aktiviert Konversation
146 ✅ wie geht's? → KI antwortet
147 ✅ (Bild senden) → Bildanalyse
148 ✅ (Datei senden) → Dokument-Analyse
149 ✅ stop → Deaktiviert
150 }}}
151
152 ----
153
154 == 7. Automatisches Backup (Optional) ==
155
156 {{{# Backup-Script
157 nano ~/backup_bot.sh
158 }}}
159
160 {{{#!/bin/bash
161 DATE=$(date +%Y%m%d_%H%M%S)
162 tar -czf /root/backups/matrix_bot_$DATE.tar.gz /root/matrix_bot
163 find /root/backups -name "matrix_bot_*.tar.gz" -mtime +7 -delete
164 }}}
165
166 {{{chmod +x ~/backup_bot.sh
167
168 # Cronjob (täglich um 3 Uhr)
169 crontab -e
170 }}}
171
172 Füge hinzu:
173
174 {{{0 3 * * * /root/backup_bot.sh
175 }}}
176
177 ----
178
179 == 8. Bei Proxmox Container-Neustart ==
180
181 Der Bot startet automatisch mit dem Container! ✅
182
183 **Falls nicht, prüfe:**
184
185 {{{sudo systemctl is-enabled matrix-bot
186 # Sollte "enabled" zeigen
187
188 # Falls nicht:
189 sudo systemctl enable matrix-bot
190 }}}
191
192 ----
193
194 == Zusammenfassung - Was du machen musst: ==
195
196 1. ✅ **Access Token** in bot.py eintragen (Zeile 40)
197 1. ✅ **Pakete installieren** (pip install ...)
198 1. ✅ **Ollama Vision** installieren (ollama pull llama3.2-vision)
199 1. ✅ **Systemd Service** erstellen und aktivieren
200 1. ✅ **Bot starten** (systemctl start matrix-bot)
201
202 **Fertig! Bot läuft jetzt permanent!** 🚀
203
204