Update deployment script to improve application restart and database schema handling
Modify deploy.sh to correctly use drizzle-kit for database migrations, load .env variables for PM2, and integrate with ecosystem.config.js for application management. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/eg9yHD6
This commit is contained in:
parent
64e58f2612
commit
62f3593624
@ -0,0 +1,135 @@
|
|||||||
|
sudo bash deploy/deploy.sh
|
||||||
|
Deployment VigilanzaTurni - Thu Oct 16 11:15:14 EDT 2025
|
||||||
|
Pull ultime modifiche da GitLab...
|
||||||
|
From https://git.alfacom.it/marco/VigilanzaTurni
|
||||||
|
* branch main -> FETCH_HEAD
|
||||||
|
Already up to date.
|
||||||
|
Backup database pre-deployment...
|
||||||
|
✅ Backup salvato: /var/backups/vigilanza-turni/backup_20251016_111514.sql
|
||||||
|
✅ Backup compresso: /var/backups/vigilanza-turni/backup_20251016_111514.sql.gz
|
||||||
|
粒 Backup vecchi eliminati (retention: 30 giorni)
|
||||||
|
Installazione dipendenze (include devDependencies)...
|
||||||
|
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is
|
||||||
|
much more comprehensive and powerful.
|
||||||
|
npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported
|
||||||
|
|
||||||
|
added 521 packages, and audited 522 packages in 11s
|
||||||
|
|
||||||
|
74 packages are looking for funding
|
||||||
|
run `npm fund` for details
|
||||||
|
|
||||||
|
2 moderate severity vulnerabilities
|
||||||
|
|
||||||
|
To address all issues (including breaking changes), run:
|
||||||
|
npm audit fix --force
|
||||||
|
|
||||||
|
Run `npm audit` for details.
|
||||||
|
️ Build frontend Vite...
|
||||||
|
|
||||||
|
> rest-express@1.0.0 build
|
||||||
|
> vite build && esbuild server/index.ts --platform=node --packages=external --bundle --format=esm --outdir=dist
|
||||||
|
|
||||||
|
vite v6.4.0 building for production...
|
||||||
|
|
||||||
|
A PostCSS plugin did not pass the `from` option to `postcss.parse`. This may cause imported assets to be incorrectly transformed. If you've recently added a PostCSS plugin that raised this warning, please
|
||||||
|
contact the package author to fix the issue.
|
||||||
|
✓ 2683 modules transformed.
|
||||||
|
../dist/public/index.html 1.49 kB │ gzip: 0.63 kB
|
||||||
|
../dist/public/assets/index-DqscHyOA.css 75.10 kB │ gzip: 12.16 kB
|
||||||
|
../dist/public/assets/index-VRh79lEQ.js 597.11 kB │ gzip: 175.56 kB
|
||||||
|
|
||||||
|
(!) Some chunks are larger than 500 kB after minification. Consider:
|
||||||
|
- Using dynamic import() to code-split the application
|
||||||
|
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
|
||||||
|
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
|
||||||
|
✓ built in 8.40s
|
||||||
|
|
||||||
|
dist/index.js 56.6kb
|
||||||
|
|
||||||
|
⚡ Done in 13ms
|
||||||
|
️ Verifica database schema...
|
||||||
|
|
||||||
|
> rest-express@1.0.0 db:push
|
||||||
|
> drizzle-kit push
|
||||||
|
|
||||||
|
error: unknown command 'push'
|
||||||
|
粒 Pulizia devDependencies (mantiene solo production)...
|
||||||
|
Restart applicazione...
|
||||||
|
[PM2] Starting /bin/npm in fork_mode (1 instance)
|
||||||
|
[PM2] Done.
|
||||||
|
┌────┬────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
|
||||||
|
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
|
||||||
|
├────┼────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
|
||||||
|
│ 0 │ vigilanza-turni │ default │ N/A │ fork │ 28225 │ 0s │ 0 │ online │ 0% │ 4.6mb │ root │ disabled │
|
||||||
|
└────┴────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
|
||||||
|
[PM2] Saving current process list...
|
||||||
|
[PM2] Successfully saved in /root/.pm2/dump.pm2
|
||||||
|
Health check...
|
||||||
|
✅ Deployment completato con successo!
|
||||||
|
[TAILING] Tailing last 20 lines for [vigilanza-turni] process (change the value with --lines option)
|
||||||
|
/root/.pm2/logs/vigilanza-turni-error.log last 20 lines:
|
||||||
|
0|vigilanz | ^
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | Error: DATABASE_URL must be set. Did you forget to provision a database?
|
||||||
|
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:578:9
|
||||||
|
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
|
||||||
|
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
|
||||||
|
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | Node.js v20.19.2
|
||||||
|
0|vigilanz | file:///var/www/vigilanza-turni/dist/index.js:578
|
||||||
|
0|vigilanz | throw new Error(
|
||||||
|
0|vigilanz | ^
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | Error: DATABASE_URL must be set. Did you forget to provision a database?
|
||||||
|
0|vigilanz | at file:///var/www/vigilanza-turni/dist/index.js:578:9
|
||||||
|
0|vigilanz | at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
|
||||||
|
0|vigilanz | at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
|
||||||
|
0|vigilanz | at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | Node.js v20.19.2
|
||||||
|
|
||||||
|
/root/.pm2/logs/vigilanza-turni-out.log last 20 lines:
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | > rest-express@1.0.0 start
|
||||||
|
0|vigilanz | > NODE_ENV=production node dist/index.js
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | > rest-express@1.0.0 start
|
||||||
|
0|vigilanz | > NODE_ENV=production node dist/index.js
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | > rest-express@1.0.0 start
|
||||||
|
0|vigilanz | > NODE_ENV=production node dist/index.js
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | > rest-express@1.0.0 start
|
||||||
|
0|vigilanz | > NODE_ENV=production node dist/index.js
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz |
|
||||||
|
0|vigilanz | > rest-express@1.0.0 start
|
||||||
|
0|vigilanz | > NODE_ENV=production node dist/index.js
|
||||||
|
0|vigilanz |
|
||||||
|
|
||||||
|
|
||||||
|
Status PM2:
|
||||||
|
┌────┬────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
|
||||||
|
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
|
||||||
|
├────┼────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
|
||||||
|
│ 0 │ vigilanza-turni │ default │ N/A │ fork │ 28322 │ 1s │ 4 │ online │ 0% │ 65.3mb │ root │ disabled │
|
||||||
|
└────┴────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
|
||||||
|
|
||||||
|
Ultimi backup disponibili:
|
||||||
|
-rw-r--r-- 1 root root 3.4K Oct 16 11:15 /var/backups/vigilanza-turni/backup_20251016_111514.sql.gz
|
||||||
|
-rw-r--r-- 1 root root 3.4K Oct 16 11:10 /var/backups/vigilanza-turni/backup_20251016_111020.sql.gz
|
||||||
|
-rw-r--r-- 1 root root 3.4K Oct 16 11:07 /var/backups/vigilanza-turni/backup_20251016_110701.sql.gz
|
||||||
|
-rw-r--r-- 1 root root 3.4K Oct 16 10:31 /var/backups/vigilanza-turni/backup_20251016_103129.sql.gz
|
||||||
|
-rw-r--r-- 1 root root 3.4K Oct 16 10:28 /var/backups/vigilanza-turni/backup_20251016_102815.sql.gz
|
||||||
|
|
||||||
|
Applicazione disponibile su: https://vt.alfacom.it
|
||||||
|
[root@localhost vigilanza-turni]# pm2 list
|
||||||
|
┌────┬────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
|
||||||
|
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
|
||||||
|
├────┼────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
|
||||||
|
│ 0 │ vigilanza-turni │ default │ N/A │ fork │ 29021 │ 0s │ 34 │ online │ 0% │ 59.1mb │ root │ disabled │
|
||||||
|
└────┴────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
|
||||||
@ -62,7 +62,7 @@ npm run build
|
|||||||
|
|
||||||
# Database migrations (serve Drizzle che è devDependency)
|
# Database migrations (serve Drizzle che è devDependency)
|
||||||
echo "🗄️ Verifica database schema..."
|
echo "🗄️ Verifica database schema..."
|
||||||
npm run db:push || true
|
npx drizzle-kit push --force || echo "⚠️ Schema push skipped (database già aggiornato)"
|
||||||
|
|
||||||
# NOTA: NON facciamo npm prune perché Vite serve a runtime per il middleware
|
# NOTA: NON facciamo npm prune perché Vite serve a runtime per il middleware
|
||||||
# Il server Express usa Vite per servire il frontend anche in produzione
|
# Il server Express usa Vite per servire il frontend anche in produzione
|
||||||
@ -79,14 +79,25 @@ fi
|
|||||||
|
|
||||||
echo "🔍 Usando PM2: $PM2_CMD"
|
echo "🔍 Usando PM2: $PM2_CMD"
|
||||||
|
|
||||||
|
# Carica variabili .env per PM2
|
||||||
|
if [ -f .env ]; then
|
||||||
|
source .env
|
||||||
|
export DATABASE_URL PGDATABASE PGUSER PGPASSWORD PGHOST PGPORT SESSION_SECRET NODE_ENV PORT
|
||||||
|
fi
|
||||||
|
|
||||||
# Restart applicazione con PM2
|
# Restart applicazione con PM2
|
||||||
echo "🔄 Restart applicazione..."
|
echo "🔄 Restart applicazione..."
|
||||||
if $PM2_CMD show $APP_NAME > /dev/null 2>&1; then
|
if $PM2_CMD show $APP_NAME > /dev/null 2>&1; then
|
||||||
$PM2_CMD reload $APP_NAME --update-env
|
$PM2_CMD delete $APP_NAME
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Usa ecosystem.config.js se esiste, altrimenti comando diretto
|
||||||
|
if [ -f ecosystem.config.js ]; then
|
||||||
|
$PM2_CMD start ecosystem.config.js
|
||||||
else
|
else
|
||||||
$PM2_CMD start npm --name $APP_NAME -- start
|
$PM2_CMD start npm --name $APP_NAME -- start
|
||||||
$PM2_CMD save
|
|
||||||
fi
|
fi
|
||||||
|
$PM2_CMD save
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
echo "🏥 Health check..."
|
echo "🏥 Health check..."
|
||||||
|
|||||||
21
ecosystem.config.js
Normal file
21
ecosystem.config.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// PM2 Ecosystem config per VigilanzaTurni
|
||||||
|
// Le variabili .env vengono caricate dallo script deploy.sh e passate tramite 'export'
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
apps: [{
|
||||||
|
name: 'vigilanza-turni',
|
||||||
|
script: 'npm',
|
||||||
|
args: 'start',
|
||||||
|
cwd: '/var/www/vigilanza-turni',
|
||||||
|
instances: 1,
|
||||||
|
autorestart: true,
|
||||||
|
watch: false,
|
||||||
|
max_memory_restart: '1G',
|
||||||
|
error_file: '/root/.pm2/logs/vigilanza-turni-error.log',
|
||||||
|
out_file: '/root/.pm2/logs/vigilanza-turni-out.log',
|
||||||
|
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
|
||||||
|
kill_timeout: 3000,
|
||||||
|
wait_ready: false,
|
||||||
|
listen_timeout: 3000
|
||||||
|
}]
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user