5
5
6
6
set -e
7
7
8
- WORK_DIR=" /home/pi /laravel-jeopardy"
8
+ WORK_DIR=" /home/geocodio /laravel-jeopardy"
9
9
SERVICE_NAME=" laravel-buzzer"
10
10
SERVICE_FILE=" /etc/systemd/system/${SERVICE_NAME} .service"
11
11
LOG_DIR=" /var/log/laravel-buzzer"
53
53
if [ ! -d " $LOG_DIR " ]; then
54
54
log " Creating log directory at $LOG_DIR ..."
55
55
mkdir -p " $LOG_DIR "
56
- chown pi:pi " $LOG_DIR "
56
+ chown geocodio:geocodio " $LOG_DIR "
57
57
fi
58
58
59
59
# Create wrapper script for the buzzer server
@@ -63,15 +63,15 @@ log "Creating wrapper script at $WRAPPER_SCRIPT..."
63
63
cat > " $WRAPPER_SCRIPT " << 'EOF '
64
64
#!/bin/bash
65
65
66
- WORK_DIR="/home/pi /laravel-jeopardy"
66
+ WORK_DIR="/home/geocodio /laravel-jeopardy"
67
67
LOG_DIR="/var/log/laravel-buzzer"
68
68
LOG_FILE="$LOG_DIR/buzzer-server.log"
69
69
ERROR_LOG="$LOG_DIR/buzzer-server-error.log"
70
70
RESTART_LOG="$LOG_DIR/restart.log"
71
71
72
72
# Ensure log files exist and are writable
73
73
touch "$LOG_FILE" "$ERROR_LOG" "$RESTART_LOG"
74
- chown pi:pi "$LOG_FILE" "$ERROR_LOG" "$RESTART_LOG"
74
+ chown geocodio:geocodio "$LOG_FILE" "$ERROR_LOG" "$RESTART_LOG"
75
75
76
76
log_message() {
77
77
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
@@ -92,13 +92,13 @@ MAX_RESTART_DELAY=60
92
92
93
93
while true; do
94
94
log_message "Starting buzzer server (attempt #$((RESTART_COUNT + 1)))..."
95
-
95
+
96
96
# Run the buzzer server and capture its exit code
97
97
php artisan buzzer-server >> "$LOG_FILE" 2>> "$ERROR_LOG"
98
98
EXIT_CODE=$?
99
-
99
+
100
100
RESTART_COUNT=$((RESTART_COUNT + 1))
101
-
101
+
102
102
if [ $EXIT_CODE -eq 0 ]; then
103
103
log_message "Buzzer server exited normally with code 0"
104
104
log_restart "Normal exit after $RESTART_COUNT restart(s)"
@@ -107,18 +107,18 @@ while true; do
107
107
log_restart "CRASH: Exit code $EXIT_CODE after running. Restart #$RESTART_COUNT"
108
108
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Process crashed with exit code $EXIT_CODE" >> "$ERROR_LOG"
109
109
fi
110
-
110
+
111
111
# Calculate restart delay (exponential backoff with max limit)
112
112
if [ $RESTART_COUNT -lt 5 ]; then
113
113
DELAY=$((RESTART_COUNT * 2))
114
114
else
115
115
DELAY=$MAX_RESTART_DELAY
116
116
fi
117
-
117
+
118
118
log_message "Waiting $DELAY seconds before restart..."
119
119
log_restart "Waiting $DELAY seconds before restart #$((RESTART_COUNT + 1))"
120
120
sleep $DELAY
121
-
121
+
122
122
log_message "Restarting buzzer server..."
123
123
done
124
124
EOF
@@ -137,16 +137,16 @@ StartLimitIntervalSec=0
137
137
138
138
[Service]
139
139
Type=simple
140
- User=pi
141
- Group=pi
140
+ User=geocodio
141
+ Group=geocodio
142
142
WorkingDirectory=$WORK_DIR
143
143
ExecStart=$WRAPPER_SCRIPT
144
144
Restart=always
145
145
RestartSec=5
146
146
147
147
# Environment variables
148
148
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
149
- Environment="HOME=/home/pi "
149
+ Environment="HOME=/home/geocodio "
150
150
151
151
# Logging
152
152
StandardOutput=journal
@@ -175,7 +175,7 @@ if systemctl is-active --quiet "$SERVICE_NAME"; then
175
175
else
176
176
log " Enabling service to start on boot..."
177
177
systemctl enable " $SERVICE_NAME "
178
-
178
+
179
179
log " Starting service..."
180
180
systemctl start " $SERVICE_NAME "
181
181
fi
@@ -254,4 +254,4 @@ echo "Log Files:"
254
254
echo " $LOG_DIR /buzzer-server.log - Main application log"
255
255
echo " $LOG_DIR /buzzer-server-error.log - Error log"
256
256
echo " $LOG_DIR /restart.log - Restart history"
257
- echo " "
257
+ echo " "
0 commit comments