mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 11:55:59 +00:00
chore: clean up project - remove temporary files and add quick setup guide
- Removed 18 temporary/test files (check_data.js, test_db_insert.js, etc.) - Removed old deployment scripts and debug utilities - Added setup.sh for one-command deployment - Rewrote QUICKSTART.md with comprehensive 3-step setup guide - Enhanced ecosystem.config.js with logging and restart config - Project is now clean and deployment-ready
This commit is contained in:
178
CHECKLIST.md
178
CHECKLIST.md
@@ -1,178 +0,0 @@
|
||||
# ✅ Deployment Checklist - Fill This Out
|
||||
|
||||
## 📋 Information Needed
|
||||
|
||||
### 🖥️ Proxmox Server Details
|
||||
- [ ] **Server IP Address**: ___________________
|
||||
- [ ] **SSH Port**: `22` (default)
|
||||
- [ ] **Root Password**: ___________________
|
||||
|
||||
### 🔑 GitHub Credentials
|
||||
- [ ] **GitHub Username**: ___________________
|
||||
- [ ] **Personal Access Token**: ___________________
|
||||
- 📝 Create at: https://github.com/settings/tokens
|
||||
- ✅ Required scope: `repo` (full control of private repositories)
|
||||
- ⏰ Recommended expiration: 90 days or No expiration
|
||||
|
||||
### 📦 Repository Details (Already Set)
|
||||
- [x] **Repository**: `DeNNiiInc/Web-Page-Performance-Test`
|
||||
- [x] **Branch**: `main`
|
||||
|
||||
---
|
||||
|
||||
## 🎯 When You're Ready
|
||||
|
||||
### Step 1: Create Configuration File
|
||||
```powershell
|
||||
# Copy the template
|
||||
Copy-Item deploy-config.TEMPLATE.json deploy-config.json
|
||||
|
||||
# Edit deploy-config.json with notepad or VS Code
|
||||
notepad deploy-config.json
|
||||
```
|
||||
|
||||
### Step 2: Fill in deploy-config.json
|
||||
```json
|
||||
{
|
||||
"host": "PUT_YOUR_SERVER_IP_HERE",
|
||||
"port": 22,
|
||||
"username": "root",
|
||||
"password": "PUT_YOUR_ROOT_PASSWORD_HERE",
|
||||
"remotePath": "/var/www/web-page-performance-test",
|
||||
"appName": "web-page-performance-test",
|
||||
"github": {
|
||||
"username": "PUT_YOUR_GITHUB_USERNAME_HERE",
|
||||
"token": "PUT_YOUR_GITHUB_TOKEN_HERE",
|
||||
"repo": "DeNNiiInc/Web-Page-Performance-Test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Deploy!
|
||||
```powershell
|
||||
.\deploy-local.ps1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Pre-Deployment Checklist
|
||||
|
||||
- [ ] Proxmox container is running
|
||||
- [ ] You can ping the server IP: `ping YOUR_SERVER_IP`
|
||||
- [ ] You can SSH to the server: `ssh root@YOUR_SERVER_IP`
|
||||
- [ ] You have created a GitHub Personal Access Token
|
||||
- [ ] You have copied deploy-config.TEMPLATE.json to deploy-config.json
|
||||
- [ ] You have filled in ALL fields in deploy-config.json
|
||||
- [ ] You have verified deploy-config.json is listed in .gitignore
|
||||
- [ ] You have committed and pushed any local changes to GitHub
|
||||
|
||||
---
|
||||
|
||||
## 📝 Example deploy-config.json
|
||||
|
||||
Here's an example (with fake credentials):
|
||||
|
||||
```json
|
||||
{
|
||||
"host": "192.168.1.100",
|
||||
"port": 22,
|
||||
"username": "root",
|
||||
"password": "MySecurePassword123!",
|
||||
"remotePath": "/var/www/web-page-performance-test",
|
||||
"appName": "web-page-performance-test",
|
||||
"github": {
|
||||
"username": "DeNNiiInc",
|
||||
"token": "ghp_A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8",
|
||||
"repo": "DeNNiiInc/Web-Page-Performance-Test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Post-Deployment Verification
|
||||
|
||||
After running `.\deploy-local.ps1`, verify:
|
||||
|
||||
- [ ] Script shows "✅ Deployment Complete!"
|
||||
- [ ] You can access the site: `http://YOUR_SERVER_IP`
|
||||
- [ ] Git version badge appears in the footer
|
||||
- [ ] SSH into server and check: `systemctl status web-page-performance-test`
|
||||
- [ ] Logs are working: `journalctl -u web-page-performance-test -n 20`
|
||||
- [ ] Auto-sync is scheduled: `crontab -l | grep auto-sync`
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Test Auto-Sync
|
||||
|
||||
1. Make a small change to `index.html` (e.g., change the subtitle)
|
||||
2. Commit and push to GitHub:
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "Test auto-sync"
|
||||
git push
|
||||
```
|
||||
3. Wait 5 minutes (or run manually on server: `./auto-sync.sh`)
|
||||
4. Refresh your browser and see the change!
|
||||
|
||||
---
|
||||
|
||||
## 🆘 If Something Goes Wrong
|
||||
|
||||
### SSH Connection Failed
|
||||
```powershell
|
||||
# Test connection manually
|
||||
ssh root@YOUR_SERVER_IP
|
||||
|
||||
# If prompted for password, type it in
|
||||
# If successful, you'll see the server prompt
|
||||
```
|
||||
|
||||
### PuTTY Tools Not Found
|
||||
The script needs `plink.exe` and `pscp.exe` (part of PuTTY):
|
||||
- Download from: https://www.putty.org/
|
||||
- Add to PATH or copy to project directory
|
||||
|
||||
### GitHub Token Invalid
|
||||
- Token must have `repo` scope
|
||||
- Check if token is expired
|
||||
- Regenerate at: https://github.com/settings/tokens
|
||||
|
||||
### Application Not Accessible
|
||||
```bash
|
||||
# SSH into server
|
||||
ssh root@YOUR_SERVER_IP
|
||||
|
||||
# Check service status
|
||||
systemctl status web-page-performance-test
|
||||
|
||||
# Check if port 3000 is listening
|
||||
netstat -tlnp | grep 3000
|
||||
|
||||
# Check Nginx
|
||||
systemctl status nginx
|
||||
nginx -t
|
||||
|
||||
# View logs
|
||||
journalctl -u web-page-performance-test -n 50
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📞 Ready to Deploy?
|
||||
|
||||
Once you have all the information above filled in:
|
||||
|
||||
1. ✅ Create `deploy-config.json`
|
||||
2. ✅ Fill in all credentials
|
||||
3. ✅ Run `.\deploy-local.ps1`
|
||||
4. ✅ Wait for "Deployment Complete!"
|
||||
5. ✅ Visit `http://YOUR_SERVER_IP`
|
||||
6. ✅ Celebrate! 🎉
|
||||
|
||||
---
|
||||
|
||||
**Need Help?**
|
||||
- Quick Start: [QUICKSTART.md](QUICKSTART.md)
|
||||
- Detailed Guide: [DEPLOYMENT.md](DEPLOYMENT.md)
|
||||
- Full README: [README.md](README.md)
|
||||
279
QUICKSTART.md
279
QUICKSTART.md
@@ -1,163 +1,198 @@
|
||||
# 🎯 Quick Start - Fill This Out First!
|
||||
# Web Performance Test - Quick Start Guide
|
||||
|
||||
## Step 1: Gather Your Information
|
||||
This guide will help you deploy the Web Performance Test application in minutes.
|
||||
|
||||
### 🖥️ Server Details (from Proxmox)
|
||||
- [ ] **Server IP Address**: `_____________________`
|
||||
- [ ] **Root Password**: `_____________________`
|
||||
- [ ] **SSH Port**: `22` (default)
|
||||
## 🚀 Quick Setup (3 Steps)
|
||||
|
||||
### 🔑 GitHub Details
|
||||
- [ ] **GitHub Username**: `_____________________`
|
||||
- [ ] **Personal Access Token**: `_____________________ ` ([Create here](https://github.com/settings/tokens))
|
||||
- ✅ Needs `repo` scope permissions
|
||||
- [ ] **Repository**: `DeNNiiInc/Web-Page-Performance-Test` (already set)
|
||||
### 1. Clone and Install
|
||||
|
||||
---
|
||||
|
||||
## Step 2: Create deploy-config.json
|
||||
|
||||
1. **Copy the template:**
|
||||
```powershell
|
||||
Copy-Item deploy-config.TEMPLATE.json deploy-config.json
|
||||
```
|
||||
|
||||
2. **Edit deploy-config.json** with your information from Step 1:
|
||||
```json
|
||||
{
|
||||
"host": "YOUR_SERVER_IP_HERE",
|
||||
"port": 22,
|
||||
"username": "root",
|
||||
"password": "YOUR_ROOT_PASSWORD_HERE",
|
||||
"remotePath": "/var/www/web-page-performance-test",
|
||||
"appName": "web-page-performance-test",
|
||||
"github": {
|
||||
"username": "YOUR_GITHUB_USERNAME_HERE",
|
||||
"token": "YOUR_GITHUB_TOKEN_HERE",
|
||||
"repo": "DeNNiiInc/Web-Page-Performance-Test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 3: Deploy! (ONE COMMAND)
|
||||
|
||||
```powershell
|
||||
.\deploy-local.ps1
|
||||
```
|
||||
|
||||
That's it! ✅
|
||||
|
||||
---
|
||||
|
||||
## ✅ What This Does Automatically
|
||||
|
||||
1. ✅ Connects to your Proxmox server via SSH
|
||||
2. ✅ Clones your GitHub repository
|
||||
3. ✅ Installs Node.js dependencies
|
||||
4. ✅ Creates a systemd service (auto-start on boot)
|
||||
5. ✅ Configures Nginx reverse proxy (serves on port 80)
|
||||
6. ✅ Sets up auto-sync (checks GitHub every 5 minutes)
|
||||
7. ✅ Removes credentials from the server after setup
|
||||
|
||||
---
|
||||
|
||||
## 🔄 After Deployment (How to Update)
|
||||
|
||||
### Option 1: Automatic (Recommended)
|
||||
Just push to GitHub, wait 5 minutes, it updates automatically! No manual intervention needed.
|
||||
|
||||
### Option 2: Force Update (Immediate)
|
||||
```bash
|
||||
ssh root@YOUR_SERVER_IP
|
||||
cd /var/www/web-page-performance-test
|
||||
./auto-sync.sh
|
||||
git clone https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
|
||||
cd Web-Page-Performance-Test
|
||||
npm install
|
||||
```
|
||||
|
||||
---
|
||||
### 2. Configure Database
|
||||
|
||||
## 📊 Useful Commands (SSH into server first)
|
||||
Create your database configuration file:
|
||||
|
||||
### Check if app is running
|
||||
```bash
|
||||
systemctl status web-page-performance-test
|
||||
cp lib/db-config.template.js lib/db-config.js
|
||||
```
|
||||
|
||||
### View app logs
|
||||
Edit `lib/db-config.js` with your PostgreSQL credentials:
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
host: 'YOUR_DATABASE_HOST', // e.g., 'localhost' or '172.16.69.219'
|
||||
user: 'postgres', // Database username
|
||||
password: 'YOUR_PASSWORD', // Database password
|
||||
database: 'webperformance', // Database name
|
||||
port: 5432, // Default PostgreSQL port
|
||||
};
|
||||
```
|
||||
|
||||
### 3. Initialize Database
|
||||
|
||||
Run the database initialization script:
|
||||
|
||||
```bash
|
||||
journalctl -u web-page-performance-test -f
|
||||
node lib/db.js
|
||||
```
|
||||
|
||||
### View auto-sync logs
|
||||
This will create the required database table and indexes.
|
||||
|
||||
### 4. Start the Application
|
||||
|
||||
#### Development Mode:
|
||||
```bash
|
||||
tail -f /var/log/web-page-performance-test-autosync.log
|
||||
npm start
|
||||
```
|
||||
|
||||
### Restart app manually
|
||||
#### Production Mode (with PM2):
|
||||
```bash
|
||||
systemctl restart web-page-performance-test
|
||||
npm install -g pm2
|
||||
pm2 start ecosystem.config.js
|
||||
pm2 save
|
||||
pm2 startup # Follow the instructions to enable auto-start
|
||||
```
|
||||
|
||||
---
|
||||
The application will be available at `http://localhost:3000`
|
||||
|
||||
## 🆘 Troubleshooting
|
||||
## 📋 Prerequisites
|
||||
|
||||
### "Connection refused" error
|
||||
- Check if server IP is correct
|
||||
- Check if SSH is running: `systemctl status ssh`
|
||||
- Try: `ping YOUR_SERVER_IP`
|
||||
- **Node.js** v14 or higher
|
||||
- **PostgreSQL** v12 or higher
|
||||
- **Chrome/Chromium** (installed automatically with puppeteer)
|
||||
|
||||
### "Authentication failed" error
|
||||
- Double-check root password in `deploy-config.json`
|
||||
- Try manually: `ssh root@YOUR_SERVER_IP`
|
||||
## 🗄️ Database Setup
|
||||
|
||||
### App deployed but not accessible
|
||||
If you need to set up PostgreSQL from scratch:
|
||||
|
||||
### On Ubuntu/Debian:
|
||||
```bash
|
||||
# Check if service is running
|
||||
systemctl status web-page-performance-test
|
||||
|
||||
# Check if Nginx is running
|
||||
systemctl status nginx
|
||||
|
||||
# Test locally on server
|
||||
curl http://localhost
|
||||
sudo apt update
|
||||
sudo apt install postgresql postgresql-contrib
|
||||
sudo systemctl start postgresql
|
||||
sudo systemctl enable postgresql
|
||||
```
|
||||
|
||||
---
|
||||
### Create Database:
|
||||
```bash
|
||||
sudo -u postgres psql
|
||||
```
|
||||
|
||||
## 🎉 Success Checklist
|
||||
```sql
|
||||
CREATE DATABASE webperformance;
|
||||
ALTER USER postgres PASSWORD 'your_password_here';
|
||||
\q
|
||||
```
|
||||
|
||||
After running `.\deploy-local.ps1`, you should see:
|
||||
- ✅ "SSH connection successful!"
|
||||
- ✅ "Deployment Complete!"
|
||||
- ✅ Visit `http://YOUR_SERVER_IP` in browser - your site loads!
|
||||
- ✅ Wait 5 minutes, make a change, push to GitHub, site updates automatically!
|
||||
### Configure Remote Access (if needed):
|
||||
|
||||
---
|
||||
Edit PostgreSQL configuration:
|
||||
```bash
|
||||
sudo nano /etc/postgresql/*/main/postgresql.conf
|
||||
```
|
||||
|
||||
## 📁 Files You'll Edit
|
||||
Add or uncomment:
|
||||
```ini
|
||||
listen_addresses = '*'
|
||||
```
|
||||
|
||||
- `deploy-config.json` - Your credentials (ONE TIME, never commit to Git)
|
||||
- `index.html` - Your HTML content (commit to Git)
|
||||
- `styles.css` - Your styles (commit to Git)
|
||||
- `script.js` - Your JavaScript (commit to Git)
|
||||
Edit access control:
|
||||
```bash
|
||||
sudo nano /etc/postgresql/*/main/pg_hba.conf
|
||||
```
|
||||
|
||||
---
|
||||
Add:
|
||||
```
|
||||
host all all 0.0.0.0/0 scram-sha-256
|
||||
```
|
||||
|
||||
## 🔐 Security Notes
|
||||
Restart PostgreSQL:
|
||||
```bash
|
||||
sudo systemctl restart postgresql
|
||||
```
|
||||
|
||||
- ✅ `deploy-config.json` is in `.gitignore` - will NEVER be pushed to GitHub
|
||||
- ✅ GitHub token is removed from server after initial clone
|
||||
- ✅ Server uses systemd (not PM2) for better security and reliability
|
||||
- ✅ Nginx serves static files (Node.js only handles API)
|
||||
## 🔧 Configuration
|
||||
|
||||
---
|
||||
### Environment Variables (Optional)
|
||||
|
||||
## 📖 Need More Details?
|
||||
You can set these environment variables for additional configuration:
|
||||
|
||||
Read the full guide: `DEPLOYMENT.md`
|
||||
- `PORT` - Server port (default: 3000)
|
||||
- `NODE_ENV` - Environment (development/production)
|
||||
|
||||
---
|
||||
### PM2 Configuration
|
||||
|
||||
**Ready? Let's go! 🚀**
|
||||
The `ecosystem.config.js` file contains PM2 configuration. You can customize:
|
||||
- Instance name
|
||||
- Number of instances
|
||||
- Memory limits
|
||||
- Log locations
|
||||
|
||||
## 📁 Project Structure
|
||||
|
||||
```
|
||||
Web-Page-Performance-Test/
|
||||
├── server.js # Express server
|
||||
├── index.html # Main interface
|
||||
├── waterfall.html # Network waterfall visualization
|
||||
├── images.html # Filmstrip gallery
|
||||
├── compare.html # Test comparison tool
|
||||
├── lib/ # Core modules
|
||||
│ ├── runner.js # Lighthouse test runner
|
||||
│ ├── db.js # Database setup
|
||||
│ └── db-config.js # Database credentials (not in git)
|
||||
├── migrations/ # Database migrations
|
||||
└── docs/ # Additional documentation
|
||||
```
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Database Connection Issues
|
||||
|
||||
**Error: `connect ECONNREFUSED`**
|
||||
- Verify PostgreSQL is running: `systemctl status postgresql`
|
||||
- Check database credentials in `lib/db-config.js`
|
||||
- Verify pg_hba.conf allows connection from your IP
|
||||
|
||||
**Error: `password authentication failed`**
|
||||
- Reset PostgreSQL password:
|
||||
```bash
|
||||
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'new_password';"
|
||||
```
|
||||
|
||||
### Chrome/Puppeteer Issues
|
||||
|
||||
**Error: `Failed to launch chrome`**
|
||||
- Install required dependencies:
|
||||
```bash
|
||||
sudo apt install -y chromium-browser chromium-chromedriver
|
||||
```
|
||||
|
||||
### Port Already in Use
|
||||
|
||||
**Error: `EADDRINUSE: address already in use`**
|
||||
- Change the port in `server.js` or:
|
||||
```bash
|
||||
PORT=3001 npm start
|
||||
```
|
||||
|
||||
## 📚 Additional Documentation
|
||||
|
||||
- **Full Deployment Guide**: See `DEPLOYMENT.md`
|
||||
- **Proxmox Deployment**: See `PROXMOX_DEPLOY_TEMPLATE.md`
|
||||
- **API Documentation**: See `docs/API.md`
|
||||
|
||||
## 🔒 Security Notes
|
||||
|
||||
- Never commit `lib/db-config.js` to version control (it's in `.gitignore`)
|
||||
- Use strong passwords for database access
|
||||
- Consider restricting database access to specific IPs in production
|
||||
- Keep dependencies updated: `npm audit fix`
|
||||
|
||||
## 📝 License
|
||||
|
||||
GPL v3 - See LICENSE file for details
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
APP_NAME="web-page-performance-test"
|
||||
APP_DIR="/var/www/$APP_NAME"
|
||||
LOG_FILE="/var/log/$APP_NAME-autosync.log"
|
||||
LOCK_FILE="/var/lock/$APP_NAME-sync.lock"
|
||||
|
||||
# Singleton execution with flock
|
||||
exec 9>"$LOCK_FILE"
|
||||
if ! flock -n 9; then
|
||||
# Lock is busy, skip this run (logging optional to avoid spam)
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
# Ensure we are in the correct directory
|
||||
cd "$APP_DIR" || { log "❌ Error: Could not change to $APP_DIR"; exit 1; }
|
||||
|
||||
# Fetch remote updates
|
||||
if ! git fetch origin main --quiet; then
|
||||
log "❌ Error: Git fetch failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOCAL=$(git rev-parse HEAD)
|
||||
REMOTE=$(git rev-parse origin/main)
|
||||
|
||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
||||
# No changes, exit silently
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "🔄 Changes detected! Local: ${LOCAL:0:7} -> Remote: ${REMOTE:0:7}"
|
||||
|
||||
# Force update
|
||||
if ! git reset --hard origin/main; then
|
||||
log "❌ Error: Git reset failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for dependency changes
|
||||
RESTART_NEEDED=false
|
||||
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "package.json"; then
|
||||
log "📦 package.json changed. Running npm install..."
|
||||
if npm install --production; then
|
||||
RESTART_NEEDED=true
|
||||
else
|
||||
log "❌ Error: npm install failed"
|
||||
fi
|
||||
else
|
||||
RESTART_NEEDED=true
|
||||
fi
|
||||
|
||||
# Restart service if needed
|
||||
if [ "$RESTART_NEEDED" = true ]; then
|
||||
log "🔄 Restarting service..."
|
||||
if systemctl restart "$APP_NAME"; then
|
||||
log "✅ Service restarted successfully"
|
||||
else
|
||||
log "❌ Error: Failed to restart service"
|
||||
fi
|
||||
fi
|
||||
66
auto-sync.sh
66
auto-sync.sh
@@ -1,66 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# Auto-Sync Script - Run by Cron Every 5 Minutes
|
||||
# ============================================================================
|
||||
# This script:
|
||||
# 1. Checks for changes in Git repository
|
||||
# 2. Pulls updates if available
|
||||
# 3. Restarts the service ONLY if changes were detected
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
APP_NAME="web-page-performance-test"
|
||||
APP_DIR="/var/www/$APP_NAME"
|
||||
LOG_FILE="/var/log/$APP_NAME-autosync.log"
|
||||
|
||||
# Function to log with timestamp
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
log "========================================="
|
||||
log "Starting auto-sync check..."
|
||||
|
||||
cd "$APP_DIR" || exit 1
|
||||
|
||||
# Fetch latest from remote
|
||||
git fetch origin main 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Check if local is behind remote
|
||||
LOCAL=$(git rev-parse HEAD)
|
||||
REMOTE=$(git rev-parse origin/main)
|
||||
|
||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
||||
log "✅ Already up to date. No changes detected."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "🔄 Changes detected! Pulling updates..."
|
||||
|
||||
# Force update (overwrite local changes)
|
||||
log "⚠️ Resetting local changes to match remote..."
|
||||
git reset --hard origin/main 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Install/update dependencies if package.json changed
|
||||
if git diff --name-only $LOCAL $REMOTE | grep -q "package.json"; then
|
||||
log "📦 package.json changed. Running npm install..."
|
||||
npm install 2>&1 | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Restart the service
|
||||
log "🔄 Restarting $APP_NAME service..."
|
||||
systemctl restart "$APP_NAME" 2>&1 | tee -a "$LOG_FILE"
|
||||
|
||||
# Wait a moment and check status
|
||||
sleep 2
|
||||
if systemctl is-active --quiet "$APP_NAME"; then
|
||||
log "✅ Service restarted successfully!"
|
||||
else
|
||||
log "❌ WARNING: Service may have failed to start!"
|
||||
systemctl status "$APP_NAME" --no-pager 2>&1 | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
log "✅ Auto-sync completed!"
|
||||
log "========================================="
|
||||
@@ -1,28 +0,0 @@
|
||||
const { Pool } = require('pg');
|
||||
const config = require('./lib/db-config');
|
||||
const pool = new Pool(config);
|
||||
|
||||
async function checkData() {
|
||||
console.log(`🔎 Checking data in ${config.database}...`);
|
||||
try {
|
||||
const client = await pool.connect();
|
||||
const res = await client.query('SELECT COUNT(*) FROM test_results');
|
||||
console.log(`📊 Total Test Results: ${res.rows[0].count}`);
|
||||
|
||||
if (parseInt(res.rows[0].count) > 0) {
|
||||
const recent = await client.query('SELECT id, url, timestamp FROM test_results ORDER BY timestamp DESC LIMIT 5');
|
||||
console.log('🕒 Most Recent Entries:');
|
||||
console.table(recent.rows);
|
||||
} else {
|
||||
console.warn('⚠️ Table is empty!');
|
||||
}
|
||||
|
||||
client.release();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('❌ Query Failed:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
checkData();
|
||||
@@ -1,92 +0,0 @@
|
||||
# ============================================================================
|
||||
# PowerShell Deployment Script - Run from Local Machine
|
||||
# ============================================================================
|
||||
# This script:
|
||||
# 1. Reads credentials from deploy-config.json
|
||||
# 2. Uploads necessary files to the server via SCP
|
||||
# 3. Connects via SSH and runs the deployment script
|
||||
# ============================================================================
|
||||
|
||||
# Check if deploy-config.json exists
|
||||
if (-not (Test-Path "deploy-config.json")) {
|
||||
Write-Host "❌ ERROR: deploy-config.json not found!" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "Please create deploy-config.json based on deploy-config.TEMPLATE.json" -ForegroundColor Yellow
|
||||
Write-Host "and fill in your credentials." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Read configuration
|
||||
$Config = Get-Content "deploy-config.json" | ConvertFrom-Json
|
||||
$ServerHost = $Config.host
|
||||
$Port = $Config.port
|
||||
$User = $Config.username
|
||||
$Pass = $Config.password
|
||||
$RemotePath = $Config.remotePath
|
||||
$AppName = $Config.appName
|
||||
|
||||
Write-Host "=========================================" -ForegroundColor Cyan
|
||||
Write-Host "🚀 Starting Deployment Process" -ForegroundColor Cyan
|
||||
Write-Host "=========================================" -ForegroundColor Cyan
|
||||
Write-Host "📡 Server: $User@$ServerHost" -ForegroundColor White
|
||||
Write-Host "📁 Remote Path: $RemotePath" -ForegroundColor White
|
||||
Write-Host ""
|
||||
|
||||
# Test SSH connection
|
||||
Write-Host "🔍 Testing SSH connection..." -ForegroundColor Yellow
|
||||
$TestCmd = "echo 'Connection successful'"
|
||||
try {
|
||||
echo y | plink -ssh -P $Port -pw $Pass "$User@$ServerHost" $TestCmd 2>&1 | Out-Null
|
||||
Write-Host "✅ SSH connection successful!" -ForegroundColor Green
|
||||
}
|
||||
catch {
|
||||
Write-Host "❌ Failed to connect to server!" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Create remote directory
|
||||
Write-Host ""
|
||||
Write-Host "📁 Creating remote directory..." -ForegroundColor Yellow
|
||||
$CreateDirCmd = "mkdir -p $RemotePath; apt-get update && apt-get install -y jq git"
|
||||
echo y | plink -ssh -P $Port -pw $Pass "$User@$ServerHost" $CreateDirCmd
|
||||
|
||||
# Upload deploy-config.json (temporarily, will be used then removed)
|
||||
Write-Host ""
|
||||
Write-Host "📤 Uploading configuration..." -ForegroundColor Yellow
|
||||
echo y | pscp -P $Port -pw $Pass "deploy-config.json" "$User@${ServerHost}:${RemotePath}/deploy-config.json"
|
||||
|
||||
# Upload deployment script
|
||||
Write-Host "📤 Uploading deployment script..." -ForegroundColor Yellow
|
||||
echo y | pscp -P $Port -pw $Pass "deploy-server.sh" "$User@${ServerHost}:${RemotePath}/deploy-server.sh"
|
||||
|
||||
# Upload auto-sync script
|
||||
Write-Host "📤 Uploading auto-sync script..." -ForegroundColor Yellow
|
||||
echo y | pscp -P $Port -pw $Pass "auto-sync.sh" "$User@${ServerHost}:${RemotePath}/auto-sync.sh"
|
||||
|
||||
# Make scripts executable and run deployment
|
||||
Write-Host ""
|
||||
Write-Host "🚀 Running deployment on server..." -ForegroundColor Yellow
|
||||
Write-Host "=========================================" -ForegroundColor Cyan
|
||||
|
||||
$DeployCmd = @"
|
||||
cd $RemotePath
|
||||
chmod +x deploy-server.sh auto-sync.sh
|
||||
./deploy-server.sh
|
||||
rm -f deploy-config.json
|
||||
"@
|
||||
|
||||
echo y | plink -ssh -P $Port -t -pw $Pass "$User@$ServerHost" $DeployCmd
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=========================================" -ForegroundColor Cyan
|
||||
Write-Host "✅ Deployment Complete!" -ForegroundColor Green
|
||||
Write-Host "=========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "📊 Next Steps:" -ForegroundColor Yellow
|
||||
Write-Host " 1. Test the application: http://$ServerHost" -ForegroundColor White
|
||||
Write-Host " 2. Check service status: systemctl status $AppName" -ForegroundColor White
|
||||
Write-Host " 3. View auto-sync logs: tail -f /var/log/${AppName}-autosync.log" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "🔄 Auto-sync is now active (every 5 minutes)" -ForegroundColor Green
|
||||
Write-Host " Just push to GitHub and wait - the server will auto-update!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
@@ -1,30 +0,0 @@
|
||||
$Server = "172.16.69.219"
|
||||
$User = "root"
|
||||
$Pass = "Q4dv!Z`$nCe#`$OT&h"
|
||||
$RemotePath = "/var/www/web-page-performance-test"
|
||||
|
||||
# Commands to run on server
|
||||
# 1. Pull latest files
|
||||
# 2. Copy Systemd units to /etc/systemd/system/
|
||||
# 3. Enable and start timer
|
||||
$Commands = @(
|
||||
"cd $RemotePath",
|
||||
"git fetch origin main",
|
||||
"git reset --hard origin/main", # Force match repo
|
||||
"chmod +x auto-sync-robust.sh",
|
||||
"chmod +x fix-ssh-limits.sh",
|
||||
"./fix-ssh-limits.sh", # Apply SSH limits fix first
|
||||
"cp auto-sync-robust.sh auto-sync.sh",
|
||||
"cp web-page-performance-test-sync.service /etc/systemd/system/",
|
||||
"cp web-page-performance-test-sync.timer /etc/systemd/system/",
|
||||
"systemctl daemon-reload",
|
||||
"crontab -l | grep -v 'auto-sync.sh' | crontab -",
|
||||
"systemctl enable web-page-performance-test-sync.timer",
|
||||
"systemctl restart web-page-performance-test-sync.timer",
|
||||
"systemctl list-timers --all | grep web-page",
|
||||
"echo '✅ Systemd Timer (60s) Deployed & SSH Limits Fixed!'"
|
||||
)
|
||||
$CommandStr = $Commands -join " && "
|
||||
|
||||
echo "🚀 Triggering remote deployment (Pull & Apply)..."
|
||||
plink -batch -pw "$Pass" "$User@$Server" $CommandStr
|
||||
@@ -1,48 +0,0 @@
|
||||
$Server = "172.16.69.219"
|
||||
$User = "root"
|
||||
$Pass = "Q4dv!Z`$nCe#`$OT&h"
|
||||
$RemotePath = "/var/www/web-page-performance-test"
|
||||
|
||||
function Send-File-B64 {
|
||||
param($LocalFile, $RemotePath)
|
||||
echo "📄 Sending $LocalFile (Base64)..."
|
||||
|
||||
# Read file bytes and convert to Base64 string (single line)
|
||||
$ContentBytes = [System.IO.File]::ReadAllBytes($LocalFile)
|
||||
$B64 = [Convert]::ToBase64String($ContentBytes)
|
||||
|
||||
# Send command: echo "B64" | base64 -d > path
|
||||
$Command = "echo '$B64' | base64 -d > $RemotePath"
|
||||
|
||||
# Execute via plink (non-interactive)
|
||||
plink -batch -pw "$Pass" "$User@$Server" $Command
|
||||
|
||||
if ($LASTEXITCODE -ne 0) { throw "Failed to send $LocalFile" }
|
||||
}
|
||||
|
||||
try {
|
||||
# Send files using Base64 method
|
||||
Send-File-B64 ".\auto-sync-robust.sh" "$RemotePath/auto-sync.sh"
|
||||
Send-File-B64 ".\web-page-performance-test-sync.service" "/etc/systemd/system/web-page-performance-test-sync.service"
|
||||
Send-File-B64 ".\web-page-performance-test-sync.timer" "/etc/systemd/system/web-page-performance-test-sync.timer"
|
||||
|
||||
# Configure server
|
||||
echo "⚙️ Configuring Systemd Timer on server..."
|
||||
$Commands = @(
|
||||
"chmod +x $RemotePath/auto-sync.sh",
|
||||
"crontab -l | grep -v 'auto-sync.sh' | crontab -", # Remove old cron job
|
||||
"systemctl daemon-reload",
|
||||
"systemctl enable web-page-performance-test-sync.timer",
|
||||
"systemctl start web-page-performance-test-sync.timer",
|
||||
"systemctl status web-page-performance-test-sync.timer --no-pager",
|
||||
"echo '✅ Systemd Timer Upgrade Complete!'"
|
||||
)
|
||||
$CommandStr = $Commands -join " && "
|
||||
|
||||
plink -batch -pw "$Pass" "$User@$Server" $CommandStr
|
||||
|
||||
}
|
||||
catch {
|
||||
echo "❌ Error: $_"
|
||||
exit 1
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
$Server = "172.16.69.219"
|
||||
$User = "root"
|
||||
$Pass = "Q4dv!Z`$nCe#`$OT&h"
|
||||
$RemotePath = "/var/www/web-page-performance-test"
|
||||
|
||||
function Send-File {
|
||||
param($LocalFile, $RemotePath)
|
||||
echo "📄 Sending $LocalFile..."
|
||||
Get-Content -Raw $LocalFile | plink -batch -pw "$Pass" "$User@$Server" "cat > $RemotePath"
|
||||
if ($LASTEXITCODE -ne 0) { throw "Failed to send $LocalFile" }
|
||||
}
|
||||
|
||||
try {
|
||||
# Copy files via plink pipe (more reliable than pscp here)
|
||||
Send-File ".\auto-sync-robust.sh" "$RemotePath/auto-sync.sh"
|
||||
Send-File ".\web-page-performance-test-sync.service" "/etc/systemd/system/web-page-performance-test-sync.service"
|
||||
Send-File ".\web-page-performance-test-sync.timer" "/etc/systemd/system/web-page-performance-test-sync.timer"
|
||||
|
||||
# Configure server
|
||||
echo "⚙️ Configuring Systemd Timer on server..."
|
||||
$Commands = @(
|
||||
"chmod +x $RemotePath/auto-sync.sh",
|
||||
"crontab -l | grep -v 'auto-sync.sh' | crontab -", # Remove old cron job
|
||||
"systemctl daemon-reload",
|
||||
"systemctl enable web-page-performance-test-sync.timer",
|
||||
"systemctl start web-page-performance-test-sync.timer",
|
||||
"systemctl status web-page-performance-test-sync.timer --no-pager",
|
||||
"echo '✅ Systemd Timer Upgrade Complete!'"
|
||||
)
|
||||
$CommandStr = $Commands -join " && "
|
||||
|
||||
plink -batch -pw "$Pass" "$User@$Server" $CommandStr
|
||||
|
||||
}
|
||||
catch {
|
||||
echo "❌ Error: $_"
|
||||
exit 1
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
# fix-ssh-limits.sh
|
||||
# Increases SSH connection limits to prevent "Connection refused" during rapid automation.
|
||||
|
||||
SSHD_CONFIG="/etc/ssh/sshd_config"
|
||||
|
||||
log() {
|
||||
echo "[SSH-FIX] $1"
|
||||
}
|
||||
|
||||
if [ ! -f "$SSHD_CONFIG" ]; then
|
||||
log "Error: $SSHD_CONFIG not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backup config
|
||||
cp "$SSHD_CONFIG" "$SSHD_CONFIG.bak.$(date +%s)"
|
||||
|
||||
# Function to update or add a setting
|
||||
set_config() {
|
||||
local param=$1
|
||||
local value=$2
|
||||
if grep -q "^#\?${param}" "$SSHD_CONFIG"; then
|
||||
sed -i "s/^#\?${param}.*/${param} ${value}/" "$SSHD_CONFIG"
|
||||
else
|
||||
echo "${param} ${value}" >> "$SSHD_CONFIG"
|
||||
fi
|
||||
log "Set ${param} to ${value}"
|
||||
}
|
||||
|
||||
# Apply high limits
|
||||
set_config "MaxStartups" "100:30:200"
|
||||
set_config "MaxSessions" "100"
|
||||
set_config "MaxAuthTries" "20"
|
||||
|
||||
# Reload SSH service
|
||||
if systemctl restart ssh; then
|
||||
log "✅ SSH service restarted successfully with new limits."
|
||||
log "VERIFICATION: $(grep 'MaxStartups' $SSHD_CONFIG)"
|
||||
else
|
||||
log "❌ Failed to restart SSH service."
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,25 +0,0 @@
|
||||
$Server = "172.16.69.219"
|
||||
$User = "root"
|
||||
$Pass = "Q4dv!Z`$nCe#`$OT&h"
|
||||
|
||||
function Remote-Exec {
|
||||
param($Cmd)
|
||||
echo "Running: $Cmd"
|
||||
plink -batch -pw "$Pass" "$User@$Server" $Cmd
|
||||
}
|
||||
|
||||
echo "--- 1. Checking Disk Space ---"
|
||||
Remote-Exec "df -h"
|
||||
|
||||
echo "--- 2. Checking Node Version ---"
|
||||
Remote-Exec "node -v && npm -v"
|
||||
|
||||
echo "--- 3. Re-installing Dependencies (Verbose) ---"
|
||||
Remote-Exec "cd /var/www/web-page-performance-test && npm install --verbose"
|
||||
|
||||
echo "--- 4. Manual Server Start (Crash Test) ---"
|
||||
# Run for 5 seconds then kill, or catch crash output
|
||||
Remote-Exec "cd /var/www/web-page-performance-test && timeout 5s node server.js || echo 'Crash Detected'"
|
||||
|
||||
echo "--- 5. Service Status ---"
|
||||
Remote-Exec "systemctl status web-page-performance-test --no-pager"
|
||||
@@ -1,59 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "--- 🛠️ STARTING REPAIR CHECK ---"
|
||||
|
||||
# 1. Ensure SSH persistence (Append only if not present)
|
||||
if ! grep -q "MaxStartups 100:30:200" /etc/ssh/sshd_config; then
|
||||
echo "Fixing SSH limits..."
|
||||
echo 'MaxStartups 100:30:200' >> /etc/ssh/sshd_config
|
||||
echo 'MaxSessions 100' >> /etc/ssh/sshd_config
|
||||
systemctl restart ssh
|
||||
fi
|
||||
|
||||
cd /var/www/web-page-performance-test || { echo "❌ App directory missing"; exit 1; }
|
||||
|
||||
# 2. Check & Install Dependencies
|
||||
echo "📦 Checking Dependencies..."
|
||||
if [ ! -d "node_modules/puppeteer" ]; then
|
||||
echo "⚠️ Puppeteer missing. Installing..."
|
||||
npm install puppeteer lighthouse chrome-launcher express cors uuid socket.io --save --unsafe-perm --verbose
|
||||
else
|
||||
echo "✅ Puppeteer folder exists."
|
||||
# Run a quick verify
|
||||
npm install --production --unsafe-perm
|
||||
fi
|
||||
|
||||
# 3. Verify Chrome Dependencies (Debian Bookworm)
|
||||
echo "🐧 Checking System Libs..."
|
||||
MISSING_LIBS=$(dpkg -l | grep -E "libxrandr2|libgbm1|libasound2|libxss1" | wc -l)
|
||||
if [ "$MISSING_LIBS" -lt 4 ]; then
|
||||
echo "⚠️ Installing missing linux deps..."
|
||||
apt-get update && apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 libxss1
|
||||
fi
|
||||
|
||||
# 4. Restart Service
|
||||
echo "🔄 Restarting Service..."
|
||||
systemctl restart web-page-performance-test
|
||||
sleep 5
|
||||
|
||||
STATUS=$(systemctl is-active web-page-performance-test)
|
||||
echo "Service Status: $STATUS"
|
||||
|
||||
if [ "$STATUS" != "active" ]; then
|
||||
echo "❌ Service failed to start. Logs:"
|
||||
journalctl -u web-page-performance-test -n 20 --no-pager
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 5. Run Test
|
||||
echo "🚀 Triggering Test..."
|
||||
TEST_OUTPUT=$(curl -s -X POST -H "Content-Type: application/json" -d '{"url":"https://example.com/","isMobile":true}' http://localhost:3000/api/run-test)
|
||||
|
||||
echo "Response: $TEST_OUTPUT"
|
||||
|
||||
if echo "$TEST_OUTPUT" | grep -q "id"; then
|
||||
echo "✅ SUCCESS: Test triggered successfully!"
|
||||
else
|
||||
echo "❌ FAILURE: Test API returned error."
|
||||
fi
|
||||
|
||||
echo "--- DONE ---"
|
||||
@@ -1 +0,0 @@
|
||||
ALTER USER postgres PASSWORD 'WebPerfTest2025';
|
||||
45
setup.sh
Normal file
45
setup.sh
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# Quick Setup Script for Web Performance Test
|
||||
# This script sets up the complete environment in minutes
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "🚀 Web Performance Test - Quick Setup"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
|
||||
# 1. Install Dependencies
|
||||
echo "📦 Installing Node.js dependencies..."
|
||||
npm install
|
||||
|
||||
# 2. Setup Database Configuration
|
||||
echo "🗄️ Setting up database configuration..."
|
||||
if [ ! -f "lib/db-config.js" ]; then
|
||||
echo ""
|
||||
echo "⚠️ Database configuration not found!"
|
||||
echo "Please create lib/db-config.js from the template:"
|
||||
echo ""
|
||||
echo " cp lib/db-config.template.js lib/db-config.js"
|
||||
echo ""
|
||||
echo "Then edit lib/db-config.js with your database credentials:"
|
||||
echo " - host: Your PostgreSQL server IP"
|
||||
echo " - user: Database username (default: postgres)"
|
||||
echo " - password: Database password"
|
||||
echo " - database: Database name (default: webperformance)"
|
||||
echo ""
|
||||
read -p "Press Enter after you've created and configured lib/db-config.js..."
|
||||
fi
|
||||
|
||||
# 3. Initialize Database
|
||||
echo "🔧 Initializing database..."
|
||||
node lib/db.js
|
||||
|
||||
echo ""
|
||||
echo "✅ Setup Complete!"
|
||||
echo ""
|
||||
echo "To start the application:"
|
||||
echo " npm start"
|
||||
echo ""
|
||||
echo "Or with PM2 (recommended for production):"
|
||||
echo " pm2 start ecosystem.config.js"
|
||||
echo ""
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo "Starting PostgreSQL Setup..."
|
||||
|
||||
# Ensure service is running
|
||||
service postgresql start
|
||||
|
||||
# Set postgres user password
|
||||
# Use single quotes for the inner SQL string to handle special characters if possible,
|
||||
# but password has single quote? No: X@gon2005!#$
|
||||
# We need to escape carefully.
|
||||
echo "Setting postgres user password..."
|
||||
su - postgres -c "psql -c \"ALTER USER postgres PASSWORD 'X@gon2005!#$';\""
|
||||
|
||||
# Create Database
|
||||
echo "Creating database WebPerformance..."
|
||||
su - postgres -c "createdb WebPerformance" || echo "Database WebPerformance might already exist or creation failed."
|
||||
|
||||
# Initialize Schema using application code
|
||||
echo "Initializing Database Schema..."
|
||||
cd /var/www/web-page-performance-test || exit
|
||||
# Ensure dependencies are installed
|
||||
npm install
|
||||
# Run the schema initialization function exported in lib/db.js
|
||||
node -e "const db = require('./lib/db'); db.initSchema().then(() => { console.log('Schema init called'); process.exit(0); }).catch(e => { console.error(e); process.exit(1); });"
|
||||
|
||||
echo "PostgreSQL Setup Complete."
|
||||
@@ -1,48 +0,0 @@
|
||||
const { Pool } = require('pg');
|
||||
const config = require('./lib/db-config');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const pool = new Pool(config);
|
||||
|
||||
async function testInsert() {
|
||||
console.log('🧪 Testing Manual Insert...');
|
||||
const client = await pool.connect();
|
||||
|
||||
try {
|
||||
const testId = crypto.randomUUID();
|
||||
const query = `
|
||||
INSERT INTO test_results (
|
||||
id, url, user_uuid, is_mobile,
|
||||
scores, metrics, filmstrip, timestamp
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW())
|
||||
RETURNING id
|
||||
`;
|
||||
|
||||
const values = [
|
||||
testId,
|
||||
'https://example.com',
|
||||
'test-user-uuid',
|
||||
false,
|
||||
JSON.stringify({ performance: 100 }),
|
||||
JSON.stringify({ lcp: 500 }),
|
||||
JSON.stringify([])
|
||||
];
|
||||
|
||||
console.log('📝 Executing Query:', query);
|
||||
console.log('📄 Values:', values);
|
||||
|
||||
const res = await client.query(query, values);
|
||||
console.log('✅ Insert Successful! ID:', res.rows[0].id);
|
||||
|
||||
const countRes = await client.query('SELECT COUNT(*) FROM test_results');
|
||||
console.log('📊 New Row Count:', countRes.rows[0].count);
|
||||
|
||||
} catch (err) {
|
||||
console.error('❌ Insert Failed:', err);
|
||||
} finally {
|
||||
client.release();
|
||||
pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
testInsert();
|
||||
@@ -1,46 +0,0 @@
|
||||
const { Pool } = require('pg');
|
||||
const config = require('./lib/db-config');
|
||||
|
||||
// Force verify config is using localhost
|
||||
if (config.host !== 'localhost' && config.host !== '127.0.0.1') {
|
||||
console.error(`❌ Config is NOT pointing to localhost! It is pointing to: ${config.host}`);
|
||||
console.log('Overriding to localhost for this test...');
|
||||
config.host = 'localhost';
|
||||
}
|
||||
|
||||
const pool = new Pool(config);
|
||||
|
||||
async function testConnection() {
|
||||
console.log(`🔌 Testing connection to ${config.database} on ${config.host} as ${config.user}...`);
|
||||
try {
|
||||
const client = await pool.connect();
|
||||
console.log('✅ Connection Successful!');
|
||||
|
||||
const res = await client.query('SELECT NOW() as now, current_database() as db, current_user as user');
|
||||
console.log(`📊 Connected Info:`);
|
||||
console.log(` - Time: ${res.rows[0].now}`);
|
||||
console.log(` - DB: ${res.rows[0].db}`);
|
||||
console.log(` - User: ${res.rows[0].user}`);
|
||||
|
||||
// Check if table exists
|
||||
const tableCheck = await client.query("SELECT to_regclass('public.test_results') as table_exists");
|
||||
if (tableCheck.rows[0].table_exists) {
|
||||
console.log('✅ Base table "test_results" found.');
|
||||
} else {
|
||||
console.warn('⚠️ Base table "test_results" NOT FOUND. Schema might need initialization.');
|
||||
}
|
||||
|
||||
client.release();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('❌ Connection Failed:', err.message);
|
||||
if (err.code === '28P01') {
|
||||
console.error(' Hint: Authentication failed. Check password.');
|
||||
} else if (err.code === '3D000') {
|
||||
console.error(` Hint: Database "${config.database}" does not exist.`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
testConnection();
|
||||
@@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Auto-sync Web Page Performance Test from GitHub
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/var/www/web-page-performance-test/auto-sync.sh
|
||||
User=root
|
||||
StandardOutput=append:/var/log/web-page-performance-test-autosync.log
|
||||
StandardError=append:/var/log/web-page-performance-test-autosync.log
|
||||
@@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=Run auto-sync every 30 seconds
|
||||
|
||||
[Timer]
|
||||
OnBootSec=1min
|
||||
OnUnitActiveSec=60s
|
||||
Unit=web-page-performance-test-sync.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Reference in New Issue
Block a user