updateweb
This commit is contained in:
187
SERVER_MANAGEMENT.md
Normal file
187
SERVER_MANAGEMENT.md
Normal file
@@ -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**: <http://localhost:5000>
|
||||||
|
- **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**: <http://localhost:5000>
|
||||||
|
- **Shop Page**: <http://localhost:5000/shop.html>
|
||||||
|
- **Admin Login**: <http://localhost:5000/admin/login.html>
|
||||||
|
|
||||||
|
## 🔄 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)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
NODE_ENV=production
|
NODE_ENV=development
|
||||||
PORT=5000
|
PORT=5000
|
||||||
|
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
|
|||||||
30
check-service.sh
Executable file
30
check-service.sh
Executable file
@@ -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
|
||||||
30
ecosystem.config.js
Normal file
30
ecosystem.config.js
Normal file
@@ -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,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
63
manage-server.sh
Executable file
63
manage-server.sh
Executable file
@@ -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
|
||||||
4
pre-start.sh
Executable file
4
pre-start.sh
Executable file
@@ -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
|
||||||
42
quick-status.sh
Executable file
42
quick-status.sh
Executable file
@@ -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 "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
49
setup-service.sh
Executable file
49
setup-service.sh
Executable file
@@ -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"
|
||||||
30
skyartshop.service
Normal file
30
skyartshop.service
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user