Hermes Agent commited on
Commit
e5f689e
·
1 Parent(s): ea12ce5

Fix: Remove stale SQLite locks before OpenCode start + add retry logic + fix nginx duplicate MIME type

Browse files
Files changed (2) hide show
  1. entrypoint.sh +36 -2
  2. nginx.conf +1 -1
entrypoint.sh CHANGED
@@ -123,9 +123,17 @@ else
123
  echo "[DB] No database found"
124
  fi
125
 
 
 
 
 
 
 
 
126
  # Start the SQLite self-healing daemon in the background
127
  echo "[INIT] Starting self-healing daemon..."
128
  python3 /cleaner.py &
 
129
 
130
  # Always ensure /projects/default exists
131
  mkdir -p /projects/default
@@ -163,6 +171,32 @@ fi
163
  echo "============================================"
164
  echo "=== Launching OpenCode server & Nginx Proxy ==="
165
  echo "============================================"
166
- opencode serve --port 4097 --hostname 127.0.0.1 &
167
- sleep 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  exec nginx -g "daemon off;" -c /nginx.conf
 
123
  echo "[DB] No database found"
124
  fi
125
 
126
+ # Remove stale SQLite WAL/lock files to prevent "database is locked" on startup
127
+ DB_PATH="/data/share/opencode/opencode.db"
128
+ if [ -f "${DB_PATH}-wal" ] || [ -f "${DB_PATH}-shm" ] || [ -f "${DB_PATH}.lock" ]; then
129
+ echo "[DB] Removing stale SQLite lock/WAL files to prevent startup crash..."
130
+ rm -f "${DB_PATH}-wal" "${DB_PATH}-shm" "${DB_PATH}.lock" 2>/dev/null || true
131
+ fi
132
+
133
  # Start the SQLite self-healing daemon in the background
134
  echo "[INIT] Starting self-healing daemon..."
135
  python3 /cleaner.py &
136
+ sleep 1
137
 
138
  # Always ensure /projects/default exists
139
  mkdir -p /projects/default
 
171
  echo "============================================"
172
  echo "=== Launching OpenCode server & Nginx Proxy ==="
173
  echo "============================================"
174
+
175
+ # Remove any stale DB lock files one final time before starting opencode
176
+ rm -f /data/share/opencode/opencode.db-wal \
177
+ /data/share/opencode/opencode.db-shm \
178
+ /data/share/opencode/opencode.db.lock 2>/dev/null || true
179
+
180
+ # Start OpenCode server with retry logic
181
+ _oc_start() {
182
+ for attempt in 1 2 3; do
183
+ echo "[OPENCODE] Start attempt $attempt..."
184
+ opencode serve --port 4097 --hostname 127.0.0.1 &
185
+ OC_PID=$!
186
+ sleep 3
187
+ if kill -0 $OC_PID 2>/dev/null; then
188
+ echo "[OPENCODE] Server running (PID $OC_PID)"
189
+ return 0
190
+ fi
191
+ echo "[OPENCODE] Attempt $attempt failed, waiting 2s before retry..."
192
+ # Clean lock files between retries
193
+ rm -f /data/share/opencode/opencode.db-wal \
194
+ /data/share/opencode/opencode.db-shm \
195
+ /data/share/opencode/opencode.db.lock 2>/dev/null || true
196
+ sleep 2
197
+ done
198
+ echo "[OPENCODE] All start attempts failed - Nginx will still serve other services"
199
+ }
200
+ _oc_start
201
+
202
  exec nginx -g "daemon off;" -c /nginx.conf
nginx.conf CHANGED
@@ -68,7 +68,7 @@ http {
68
  proxy_redirect /login /omniroute/login;
69
  proxy_redirect /dashboard /omniroute/dashboard;
70
  proxy_set_header Accept-Encoding "";
71
- sub_filter_types text/html text/javascript application/javascript application/json;
72
  sub_filter 'href="/' 'href="/omniroute/';
73
  sub_filter 'src="/' 'src="/omniroute/';
74
  sub_filter 'action="/' 'action="/omniroute/';
 
68
  proxy_redirect /login /omniroute/login;
69
  proxy_redirect /dashboard /omniroute/dashboard;
70
  proxy_set_header Accept-Encoding "";
71
+ sub_filter_types text/javascript application/javascript application/json;
72
  sub_filter 'href="/' 'href="/omniroute/';
73
  sub_filter 'src="/' 'src="/omniroute/';
74
  sub_filter 'action="/' 'action="/omniroute/';