From 701f799cdec5041b5d36e88c358173174e47a8d5 Mon Sep 17 00:00:00 2001 From: Local Server Date: Sun, 14 Dec 2025 17:42:13 -0600 Subject: [PATCH] updateweb --- SERVER_MANAGEMENT.md | 187 +++++++++++++++++++++++++++++++++++++++++++ backend/.env | 2 +- check-service.sh | 30 +++++++ ecosystem.config.js | 30 +++++++ manage-server.sh | 63 +++++++++++++++ pre-start.sh | 4 + quick-status.sh | 42 ++++++++++ setup-service.sh | 49 ++++++++++++ skyartshop.service | 30 +++++++ 9 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 SERVER_MANAGEMENT.md create mode 100755 check-service.sh create mode 100644 ecosystem.config.js create mode 100755 manage-server.sh create mode 100755 pre-start.sh create mode 100755 quick-status.sh create mode 100755 setup-service.sh create mode 100644 skyartshop.service diff --git a/SERVER_MANAGEMENT.md b/SERVER_MANAGEMENT.md new file mode 100644 index 0000000..2455f57 --- /dev/null +++ b/SERVER_MANAGEMENT.md @@ -0,0 +1,187 @@ +# SkyArtShop Server Management + +Your SkyArtShop server is now configured to run persistently on **localhost:5000** using PM2 process manager. + +## ✅ What's Been Set Up + +1. **PM2 Process Manager** - Manages your Node.js server +2. **Auto-Restart** - Server automatically restarts if it crashes +3. **Boot Startup** - Server starts automatically when system boots +4. **Zero restarts** - Currently running with 0 crashes (stable!) + +## 🚀 Server Status + +Your server is currently **ONLINE** and running at: + +- **URL**: +- **Mode**: Development +- **Database**: PostgreSQL (skyartshop) +- **Process Manager**: PM2 + +## 📝 Quick Commands + +### Check Server Status + +```bash +cd /media/pts/Website/SkyArtShop +./manage-server.sh status +``` + +### View Live Logs + +```bash +./manage-server.sh logs +``` + +(Press Ctrl+C to exit) + +### Restart Server + +```bash +./manage-server.sh restart +``` + +### Stop Server + +```bash +./manage-server.sh stop +``` + +### Start Server + +```bash +./manage-server.sh start +``` + +## 🔍 Advanced PM2 Commands + +```bash +# Detailed status +pm2 show skyartshop + +# Monitor CPU/Memory in real-time +pm2 monit + +# View logs (last 100 lines) +pm2 logs skyartshop --lines 100 + +# Clear logs +pm2 flush + +# List all PM2 processes +pm2 list +``` + +## 🌐 Accessing Your Website + +- **Homepage**: +- **Shop Page**: +- **Admin Login**: + +## 🔄 Auto-Restart Features + +Your server will automatically: + +- ✅ Restart if it crashes +- ✅ Start when you boot your computer +- ✅ Stay running even when VS Code is closed +- ✅ Recover from unexpected errors + +## 📊 Log Files + +Logs are stored in two locations: + +**PM2 Logs:** + +- Output: `/var/log/skyartshop/pm2-output.log` +- Errors: `/var/log/skyartshop/pm2-error.log` + +**View logs:** + +```bash +tail -f /var/log/skyartshop/pm2-output.log +tail -f /var/log/skyartshop/pm2-error.log +``` + +## âš™ī¸ Configuration Files + +- **PM2 Config**: `ecosystem.config.js` +- **Environment**: `backend/.env` +- **Server Script**: `backend/server.js` + +## 🛑 Stopping Auto-Start + +If you want to disable auto-start on boot: + +```bash +pm2 unstartup systemd +``` + +To re-enable: + +```bash +sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u pts --hp /home/pts +pm2 save +``` + +## 🔧 Troubleshooting + +### Server not responding? + +```bash +./manage-server.sh status +# Check if status shows "online" +``` + +### Check for errors in logs + +```bash +./manage-server.sh logs +# or +pm2 logs skyartshop --err +``` + +### Force restart + +```bash +pm2 delete skyartshop +cd /media/pts/Website/SkyArtShop +pm2 start ecosystem.config.js +pm2 save +``` + +### Check what's using port 5000 + +```bash +sudo lsof -i :5000 +``` + +## 📁 Project Structure + +``` +/media/pts/Website/SkyArtShop/ +├── backend/ +│ ├── server.js # Main server file +│ ├── .env # Environment variables +│ └── ... +├── website/ +│ ├── public/ # Public HTML pages +│ ├── admin/ # Admin panel +│ └── assets/ # CSS, JS, images +├── ecosystem.config.js # PM2 configuration +└── manage-server.sh # Server management script +``` + +## đŸŽ¯ Key Benefits + +1. **No VS Code Required** - Server runs independently +2. **Automatic Recovery** - Restarts on crashes +3. **Boot Persistence** - Starts with your system +4. **Easy Management** - Simple commands via manage-server.sh +5. **Production Ready** - PM2 is industry standard for Node.js + +--- + +**Server Manager Script**: `./manage-server.sh {start|stop|restart|status|logs}` + +For help: `./manage-server.sh` (shows usage) diff --git a/backend/.env b/backend/.env index 5d7c0a0..79cc836 100644 --- a/backend/.env +++ b/backend/.env @@ -1,4 +1,4 @@ -NODE_ENV=production +NODE_ENV=development PORT=5000 DB_HOST=localhost diff --git a/check-service.sh b/check-service.sh new file mode 100755 index 0000000..0a5f7b9 --- /dev/null +++ b/check-service.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Quick service status check + +echo "🔍 SkyArtShop Service Status" +echo "==============================" +echo "" + +# Check if service is active +if sudo systemctl is-active --quiet skyartshop; then + echo "✅ Service is RUNNING" +else + echo "❌ Service is STOPPED" +fi + +echo "" +echo "📊 Detailed Status:" +sudo systemctl status skyartshop --no-pager -l + +echo "" +echo "🌐 Testing localhost:5000..." +if curl -s -o /dev/null -w "%{http_code}" http://localhost:5000 | grep -q "200\|301\|302"; then + echo "✅ Website is responding" +else + echo "âš ī¸ Website not responding" +fi + +echo "" +echo "📝 Recent logs (last 10 lines):" +sudo journalctl -u skyartshop -n 10 --no-pager diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..cbaa857 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,30 @@ +module.exports = { + apps: [ + { + name: "skyartshop", + script: "server.js", + cwd: "/media/pts/Website/SkyArtShop/backend", + instances: 1, + autorestart: true, + watch: false, + max_memory_restart: "500M", + env: { + NODE_ENV: "development", + PORT: 5000, + DB_HOST: "localhost", + DB_PORT: 5432, + DB_NAME: "skyartshop", + DB_USER: "skyartapp", + DB_PASSWORD: "SkyArt2025Pass", + SESSION_SECRET: "skyart-shop-secret-2025-change-this-in-production", + UPLOAD_DIR: "/var/www/SkyArtShop/wwwroot/uploads/images", + }, + error_file: "/var/log/skyartshop/pm2-error.log", + out_file: "/var/log/skyartshop/pm2-output.log", + log_date_format: "YYYY-MM-DD HH:mm:ss Z", + merge_logs: true, + kill_timeout: 5000, + listen_timeout: 10000, + }, + ], +}; diff --git a/manage-server.sh b/manage-server.sh new file mode 100755 index 0000000..7221a02 --- /dev/null +++ b/manage-server.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# SkyArtShop PM2 Management Script + +ACTION=${1:-status} + +case $ACTION in + start) + echo "🚀 Starting SkyArtShop with PM2..." + cd /media/pts/Website/SkyArtShop + pm2 start ecosystem.config.js + pm2 save + echo "✅ Server started and saved to PM2" + ;; + + stop) + echo "âšī¸ Stopping SkyArtShop..." + pm2 stop skyartshop + echo "✅ Server stopped" + ;; + + restart) + echo "🔄 Restarting SkyArtShop..." + pm2 restart skyartshop + echo "✅ Server restarted" + ;; + + status) + echo "📊 SkyArtShop Status:" + pm2 list skyartshop + echo "" + pm2 show skyartshop + ;; + + logs) + echo "📝 Showing SkyArtShop logs (Ctrl+C to exit)..." + pm2 logs skyartshop + ;; + + setup) + echo "🔧 Setting up PM2 to start on boot..." + pm2 startup systemd -u pts --hp /home/pts + echo "" + echo "âš ī¸ Run the command above if shown, then run:" + echo " ./manage-server.sh start" + echo " pm2 save" + ;; + + *) + echo "SkyArtShop Server Manager" + echo "=========================" + echo "" + echo "Usage: $0 {start|stop|restart|status|logs|setup}" + echo "" + echo "Commands:" + echo " start - Start the server" + echo " stop - Stop the server" + echo " restart - Restart the server" + echo " status - Show server status" + echo " logs - Show and follow logs" + echo " setup - Configure PM2 to start on boot" + ;; +esac diff --git a/pre-start.sh b/pre-start.sh new file mode 100755 index 0000000..3320d9a --- /dev/null +++ b/pre-start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Kill any existing SkyArtShop node processes before starting +pkill -f "node.*SkyArtShop/backend/server.js" 2>/dev/null || true +sleep 1 diff --git a/quick-status.sh b/quick-status.sh new file mode 100755 index 0000000..cc7c791 --- /dev/null +++ b/quick-status.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Quick Server Status Check + +echo "╔════════════════════════════════════════════════════════════╗" +echo "║ SkyArtShop Server Quick Status ║" +echo "╚════════════════════════════════════════════════════════════╝" +echo "" + +# Check if PM2 process is running +if pm2 list | grep -q "skyartshop.*online"; then + echo "✅ Server Status: ONLINE" + + # Get uptime + UPTIME=$(pm2 jlist | grep -A 20 "\"name\":\"skyartshop\"" | grep "pm_uptime" | cut -d':' -f2 | cut -d',' -f1) + if [ ! -z "$UPTIME" ]; then + SECONDS=$(($(date +%s) - $UPTIME / 1000)) + HOURS=$((SECONDS / 3600)) + MINUTES=$(((SECONDS % 3600) / 60)) + echo "âąī¸ Uptime: ${HOURS}h ${MINUTES}m" + fi + + # Check if responding + if curl -s -o /dev/null -w "%{http_code}" http://localhost:5000 | grep -q "200"; then + echo "🌐 Website: Responding on http://localhost:5000" + else + echo "âš ī¸ Website: Not responding (check logs)" + fi + +else + echo "❌ Server Status: OFFLINE" + echo "" + echo "Start the server with:" + echo " ./manage-server.sh start" +fi + +echo "" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" +echo "Quick Commands:" +echo " Status: ./manage-server.sh status" +echo " Logs: ./manage-server.sh logs" +echo " Restart: ./manage-server.sh restart" +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" diff --git a/setup-service.sh b/setup-service.sh new file mode 100755 index 0000000..1cd6575 --- /dev/null +++ b/setup-service.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Setup SkyArtShop as a systemd service +# This will make your server run automatically on boot and restart on crashes + +echo "🚀 Setting up SkyArtShop as a system service..." + +# Create log directory +echo "📁 Creating log directory..." +sudo mkdir -p /var/log/skyartshop +sudo chown pts:pts /var/log/skyartshop + +# Copy service file to systemd +echo "📋 Installing service file..." +sudo cp skyartshop.service /etc/systemd/system/ + +# Reload systemd to recognize new service +echo "🔄 Reloading systemd..." +sudo systemctl daemon-reload + +# Enable service to start on boot +echo "✅ Enabling service to start on boot..." +sudo systemctl enable skyartshop + +# Start the service +echo "â–ļī¸ Starting service..." +sudo systemctl start skyartshop + +# Wait a moment for service to start +sleep 2 + +# Check service status +echo "" +echo "📊 Service Status:" +sudo systemctl status skyartshop --no-pager + +echo "" +echo "✨ Setup complete!" +echo "" +echo "📝 Useful commands:" +echo " â€ĸ Check status: sudo systemctl status skyartshop" +echo " â€ĸ Start service: sudo systemctl start skyartshop" +echo " â€ĸ Stop service: sudo systemctl stop skyartshop" +echo " â€ĸ Restart: sudo systemctl restart skyartshop" +echo " â€ĸ View logs: sudo journalctl -u skyartshop -f" +echo " â€ĸ View errors: tail -f /var/log/skyartshop/error.log" +echo " â€ĸ View output: tail -f /var/log/skyartshop/output.log" +echo "" +echo "🌐 Your server should now be running on http://localhost:5000" diff --git a/skyartshop.service b/skyartshop.service new file mode 100644 index 0000000..2b76282 --- /dev/null +++ b/skyartshop.service @@ -0,0 +1,30 @@ +[Unit] +Description=SkyArtShop Node.js Backend Server +Documentation=https://github.com/yourusername/skyartshop +After=network.target postgresql.service + +[Service] +Type=simple +User=pts +WorkingDirectory=/media/pts/Website/SkyArtShop/backend +EnvironmentFile=/media/pts/Website/SkyArtShop/backend/.env +ExecStartPre=/media/pts/Website/SkyArtShop/pre-start.sh +ExecStart=/usr/bin/node /media/pts/Website/SkyArtShop/backend/server.js +Restart=always +RestartSec=10 +StartLimitInterval=200 +StartLimitBurst=5 +StandardOutput=append:/var/log/skyartshop/output.log +StandardError=append:/var/log/skyartshop/error.log + +# Restart service after 10 seconds if node service crashes +RestartSec=10 +# Output to systemd journal for easy debugging +SyslogIdentifier=skyartshop + +# Security settings +NoNewPrivileges=true +PrivateTmp=true + +[Install] +WantedBy=multi-user.target