230 lines
5.9 KiB
Markdown
230 lines
5.9 KiB
Markdown
# Saludut
|
|
|
|
Frontend Angular (`saludut-inpec`) + backend Node.js (`backend`) + PostgreSQL + Python + LibreOffice.
|
|
|
|
## Produccion (Alpine 3.21)
|
|
|
|
### 1) Preparar servidor
|
|
```bash
|
|
apk add nginx certbot certbot-nginx nftables rsync nodejs npm \
|
|
postgresql postgresql-client python3 py3-pip libreoffice
|
|
rc-update add postgresql default
|
|
rc-service postgresql setup
|
|
rc-service postgresql start
|
|
```
|
|
|
|
### 2) Crear BD y usuario
|
|
```bash
|
|
su - postgres
|
|
psql -c "CREATE USER saludut_user WITH PASSWORD 'jhyutfgv7745676tfbhjgf687yu87';"
|
|
psql -c "CREATE DATABASE saludut_db OWNER saludut_user;"
|
|
exit
|
|
psql -U postgres -d postgres -c "ALTER ROLE postgres WITH PASSWORD 'JKHUG9876hBhjhvjjhldfuy345trgfdf';"
|
|
HBA=$(psql -U postgres -d postgres -Atc "show hba_file"); cp "$HBA" "$HBA.bak"; sed -i 's/\btrust\b/scram-sha-256/g' "$HBA"; rc-service postgresql reload
|
|
```
|
|
|
|
### 3) Subir codigo
|
|
```bash
|
|
mkdir -p /opt/saludut/backend
|
|
tar -czf backend.tar.gz \
|
|
--exclude="node_modules" \
|
|
--exclude=".env" \
|
|
--exclude="backend.tar.gz" \
|
|
.
|
|
|
|
scp -C backend.tar.gz root@autorizacion.saludut.com:/opt/saludut/
|
|
```
|
|
|
|
En el servidor:
|
|
```bash
|
|
tar -xzf /opt/saludut/backend.tar.gz -C /opt/saludut/
|
|
```
|
|
|
|
### 4) Inicializar esquema minimo
|
|
Ejecuta el script minimo (schema + roles base):
|
|
```bash
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/insert.sql
|
|
```
|
|
|
|
El admin se crea automaticamente al iniciar el backend si defines
|
|
`ADMIN_USER` y `ADMIN_PASS` en el `.env`.
|
|
|
|
Opcional: cargar datos masivos desde archivos:
|
|
```bash
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/establecimiento.sql
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/paciente.sql
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/ingreso.sql
|
|
```
|
|
|
|
Opcional (solo si quieres cargar CUPS por SQL y no por la UI):
|
|
```bash
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/cups_schema.sql
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/cups_referencia.sql
|
|
psql -U saludut_user -d saludut_db -f /opt/saludut/backend/src/cups_cubiertos.sql
|
|
```
|
|
|
|
### 5) Backend (.env)
|
|
Crear `backend/.env` en el servidor:
|
|
```
|
|
DB_HOST=127.0.0.1
|
|
DB_PORT=5432
|
|
DB_USER=saludut_user
|
|
DB_PASSWORD=jhyutfgv7745676tfbhjgf687yu87
|
|
DB_NAME=saludut_db
|
|
JWT_SECRET=jhyutfgv7745676tfbhjgf687yu87
|
|
JWT_EXPIRES_IN=24h
|
|
PORT=3000
|
|
SOFFICE_PATH=/usr/bin/soffice
|
|
PYTHON_PATH=python3
|
|
ADMIN_USER=admin
|
|
ADMIN_PASS=admin123
|
|
ADMIN_EMAIL=admin@saludut.com
|
|
ADMIN_NAME=Administrador Sistema
|
|
```
|
|
|
|
### 6) Crear usuario admin (automatico)
|
|
Si defines `ADMIN_USER` y `ADMIN_PASS` en `.env`, el backend crea/actualiza el admin automaticamente al iniciar.
|
|
|
|
### 7) Backend (instalar y correr)
|
|
```bash
|
|
cd /opt/saludut/backend
|
|
npm ci --omit=dev
|
|
node src/server.js
|
|
```
|
|
|
|
#### OpenRC (servicio backend)
|
|
```bash
|
|
cat <<'EOF' > /etc/init.d/saludut-backend
|
|
#!/sbin/openrc-run
|
|
|
|
name="saludut-backend"
|
|
description="Backend Node para Saludut"
|
|
directory="/opt/saludut/backend"
|
|
command="/usr/bin/node"
|
|
command_args="src/server.js"
|
|
command_background="yes"
|
|
pidfile="/run/${RC_SVCNAME}.pid"
|
|
output_log="/var/log/saludut-backend.log"
|
|
error_log="/var/log/saludut-backend.err"
|
|
|
|
depend() {
|
|
need net
|
|
}
|
|
EOF
|
|
|
|
chmod +x /etc/init.d/saludut-backend
|
|
rc-update add saludut-backend default
|
|
rc-service saludut-backend start
|
|
```
|
|
|
|
### Frontend
|
|
|
|
```bash
|
|
sed -i 's/#Port 22/Port 48952/g' /etc/ssh/sshd_config
|
|
rc-service sshd restart
|
|
ssh -p 48952 root@autorizacion.saludut.com
|
|
apk add nginx certbot certbot-nginx nftables rsync
|
|
|
|
#Ejecutar publishNftables.sh
|
|
head -n1 ./scripts/publishNftables.sh | cat -A
|
|
sed -i 's/\r$//' ./scripts/publishNftables.sh
|
|
sed -i '1s|^.*$|#!/usr/bin/env bash|' ./scripts/publishNftables.sh
|
|
chmod +x ./scripts/publishNftables.sh
|
|
file ./scripts/publishNftables.sh
|
|
bash ./scripts/publishNftables.sh
|
|
|
|
#Ejecutar publish.sh
|
|
head -n1 ./scripts/publish.sh | cat -A
|
|
sed -i 's/\r$//' ./scripts/publish.sh
|
|
sed -i '1s|^.*$|#!/usr/bin/env bash|' ./scripts/publish.sh
|
|
chmod +x ./scripts/publish.sh
|
|
file ./scripts/publish.sh
|
|
bash ./scripts/publish.sh
|
|
|
|
#Ejecutar el nginx de autorizacion.saludut.com
|
|
scp -P 48952 scripts/vhost/autorizacion.saludut.com.conf root@autorizacion.saludut.com:/etc/nginx/http.d/
|
|
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
|
|
server_name autorizacion.saludut.com;
|
|
|
|
client_max_body_size 60m;
|
|
|
|
root /var/www/autorizacion.saludut.com/htdocs;
|
|
index index.html;
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
location /api/ {
|
|
client_max_body_size 60m;
|
|
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 600;
|
|
proxy_send_timeout 600;
|
|
}
|
|
|
|
error_page 404 /index.html;
|
|
}
|
|
|
|
rc-service nginx start
|
|
sudo certbot --nginx -d autorizacion.saludut.com
|
|
|
|
scp -P 48952 scripts/vhost/autorizacion.saludut.com.conf root@autorizacion.saludut.com:/etc/nginx/http.d/
|
|
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name autorizacion.saludut.com;
|
|
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
|
|
server {
|
|
http2 on;
|
|
listen 443 ssl;
|
|
listen [::]:443 ssl;
|
|
|
|
server_name autorizacion.saludut.com;
|
|
|
|
client_max_body_size 60m;
|
|
|
|
# ✅ Angular está dentro de /browser
|
|
root /var/www/autorizacion.saludut.com/htdocs/browser;
|
|
index index.html;
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
location /api/ {
|
|
client_max_body_size 60m;
|
|
|
|
proxy_pass http://127.0.0.1:3000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 600;
|
|
proxy_send_timeout 600;
|
|
}
|
|
|
|
error_page 404 /index.html;
|
|
|
|
ssl_certificate /etc/letsencrypt/live/autorizacion.saludut.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/autorizacion.saludut.com/privkey.pem;
|
|
}
|
|
|
|
nginx -t && rc-service nginx restart
|
|
|
|
```
|