forked from Cryptkeeper/Minetrack
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.sh
More file actions
52 lines (43 loc) · 1.24 KB
/
update.sh
File metadata and controls
52 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Configuration
PM2_APP_NAME="minetrack"
BRANCH="main"
LOG_FILE="update.log"
# Function to log messages
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR" || {
log "ERROR: Failed to change to directory $SCRIPT_DIR"
exit 1
}
# Pull latest changes and check if anything was actually updated
if git pull --ff-only origin "$BRANCH" | grep -q 'Already up to date.'; then
# log "Already up to date."
exit 0
fi
log "New changes detected. Updating..."
# Stop the PM2 process
log "Stopping PM2 app: $PM2_APP_NAME..."
pm2 stop "$PM2_APP_NAME"
# Install dependencies
log "Running npm install..."
npm install
# Restart the PM2 process
log "Restarting PM2 app: $PM2_APP_NAME..."
pm2 restart "$PM2_APP_NAME"
# Check if process is running
if pm2 list | grep -q "$PM2_APP_NAME.*online"; then
log "Update completed successfully. App is running."
else
log "WARNING: Could not verify if app started successfully."
fi
# Automatic runner:
# Add as job in crontab
# 1. crontab -e
# 2. Add this to config (checks every 10 min)
# */10 * * * * cd /home/user/x && ./update.sh
# 3. Save and exit.
# 4. Verify with: crontab -l