Add core Python agent with configuration management, environment setup, and deployment documentation. Includes user/agent profiles, startup scripts, and dependency management for the psagentia system.
177 lines
3.9 KiB
Markdown
Executable File
177 lines
3.9 KiB
Markdown
Executable File
# Deploy — PsAgentIA no Debian 12
|
|
|
|
Este documento descreve como colocar o sistema PsAgentIA para rodar de forma contínua em um servidor Debian 12 (Bookworm), com auto-start no boot e logs centralizados.
|
|
|
|
---
|
|
|
|
## 1. Pré-requisitos no servidor
|
|
|
|
```bash
|
|
sudo apt update
|
|
sudo apt install -y python3 python3-venv python3-pip git curl
|
|
```
|
|
|
|
Acesse o servidor como usuário comum (ex: `marco` ou `ubuntu`). NÃO execute como root a menos que saiba o que está fazendo.
|
|
|
|
---
|
|
|
|
## 2. Clonar o repositório
|
|
|
|
```bash
|
|
cd ~
|
|
git clone <URL_DO_REPOSITORIO> PsAgentIA
|
|
cd PsAgentIA/app
|
|
```
|
|
|
|
---
|
|
|
|
## 3. Configurar o ambiente
|
|
|
|
```bash
|
|
chmod +x iniciar.sh
|
|
cp .env.example .env
|
|
nano .env # edite com suas chaves
|
|
```
|
|
|
|
Preencha obrigatoriamente:
|
|
- `TELEGRAM_BOT_TOKEN`
|
|
- `TELEGRAM_CHAT_ID`
|
|
- pelo menos uma chave de IA (`OPENROUTER_API_KEY`, `STEPFUN_API_KEY` ou `QWENCLOUD_API_KEY`)
|
|
|
|
---
|
|
|
|
## 4. Testar manualmente antes do deploy
|
|
|
|
```bash
|
|
./iniciar.sh
|
|
```
|
|
|
|
Envie uma mensagem no Telegram para o bot. Se responder, pare o processo com `CTRL+C` e prossiga.
|
|
|
|
---
|
|
|
|
## 5. Criar usuário de serviço dedicado (recomendado)
|
|
|
|
```bash
|
|
sudo useradd -r -s /bin/bash -m -d /home/psagentia psagentia
|
|
sudo chown -R marco:marco /home/marco/PsAgentIA
|
|
```
|
|
|
|
Ajuste permissões:
|
|
|
|
```bash
|
|
sudo chmod 600 .env
|
|
```
|
|
|
|
---
|
|
|
|
## 6. Criar serviço systemd
|
|
|
|
Crie o arquivo `/etc/systemd/system/psagentia.service`:
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=PsAgentIA - Personal Agent IA Conversacional
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=marco
|
|
WorkingDirectory=/opt/PsAgentIAMarco/app
|
|
Environment="PATH=/opt/PsAgentIAMarco/app/venv/bin:/usr/bin:/bin"
|
|
ExecStart=/opt/PsAgentIAMarco/app/venv/bin/python3 /opt/PsAgentIAMarco/app/psagentia_agent.py
|
|
Restart=always
|
|
RestartSec=10
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
Ajuste `User` e `WorkingDirectory` conforme seu cenário.
|
|
|
|
---
|
|
|
|
## 7. Ativar e iniciar o serviço
|
|
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable psagentiamarco.service
|
|
sudo systemctl start psagentiamarco.service
|
|
```
|
|
|
|
Comandos úteis:
|
|
|
|
```bash
|
|
sudo systemctl status psagentia.service # status
|
|
sudo journalctl -u psagentia.service -f # logs em tempo real
|
|
sudo systemctl restart psagentia.service # reiniciar após alterações
|
|
```
|
|
|
|
---
|
|
|
|
## 8. Verificar se está funcionando
|
|
|
|
```bash
|
|
sudo systemctl status psagentia.service
|
|
```
|
|
|
|
Envie uma mensagem no Telegram para o bot. Se não houver resposta, verifique os logs:
|
|
|
|
```bash
|
|
sudo journalctl -u psagentia.service -n 100 --no-pager
|
|
```
|
|
|
|
### Possíveis causas se não responder
|
|
|
|
1. **Você está mandando mensagem para o bot errado** — confira o username do bot (ex: `@hermesjogo1000_bot`).
|
|
2. **Chat ID errado** — use `/debug` no bot para ver o chat ID da mensagem e compare com `TELEGRAM_CHAT_ID` no `.env`.
|
|
3. **Token inválido** — o bot pode ter sido revogado no @BotFather.
|
|
4. **Firewall bloqueando saída** — teste: `curl -s https://api.telegram.org` deve funcionar.
|
|
5. **Chave de IA ausente ou inválida** — o bot recebe a mensagem mas não consegue responder; verifique os logs.
|
|
|
|
---
|
|
|
|
## 9. Atualizações
|
|
|
|
```bash
|
|
cd /home/marco/PsAgentIA
|
|
git pull
|
|
cd app
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt -q
|
|
sudo systemctl restart psagentia.service
|
|
```
|
|
|
|
---
|
|
|
|
## 10. Segurança
|
|
|
|
- Nunca comite o arquivo `.env` em repositórios públicos.
|
|
- Restrinja permissões: `chmod 600 .env`.
|
|
- Revogue tokens expostos e gere novos no @BotFather ou nos provedores de IA.
|
|
- Considere usar um `.env` fora do diretório do projeto se o servidor for compartilhado.
|
|
|
|
---
|
|
|
|
## 11. Estrutura final no servidor
|
|
|
|
```
|
|
/home/marco/PsAgentIA/
|
|
├── app/
|
|
│ ├── psagentia_agent.py
|
|
│ ├── iniciar.sh
|
|
│ ├── .env
|
|
│ ├── requirements.txt
|
|
│ ├── user_profile.json
|
|
│ ├── contexts/
|
|
│ │ └── YYYY-MM-DD.json
|
|
│ ├── README.md
|
|
│ └── LICENSE
|
|
├── venv/ # ambiente virtual local
|
|
└── .git/
|
|
```
|
|
|
|
Serviço: `/etc/systemd/system/psagentia.service`
|