-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·50 lines (42 loc) · 1.76 KB
/
start.sh
File metadata and controls
executable file
·50 lines (42 loc) · 1.76 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
#!/bin/bash
# 1. Create directories if they don't exist (Crucial for volume mounts)
mkdir -p /data/input /data/scripts /data/archive
# 2. Handle PUID/PGID
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
echo "Configuring permissions for PUID:$PUID PGID:$PGID"
# Create group if not exists
if ! getent group scribble_group > /dev/null; then
groupadd -g "$PGID" scribble_group
fi
# Create user if not exists
if ! id -u scribble_user > /dev/null 2>&1; then
useradd -u "$PUID" -g "$PGID" -d /app -s /bin/bash scribble_user
fi
# Recursive chown to ensure user can write
chown -R "$PUID":"$PGID" /data
chown -R "$PUID":"$PGID" /app
# [NEW] Check & Run Database Migration
echo "Checking for database migrations..."
until su scribble_user -c "python3 -c 'from database import db; from app import app; app.app_context().push(); db.engine.connect()'" > /dev/null 2>&1; do
echo "Waiting for database..."
sleep 3
done
export SCRIBBLE_MIGRATE_ONLY=1
su scribble_user -c "python3 migrate.py"
unset SCRIBBLE_MIGRATE_ONLY
echo "Starting Scribble as scribble_user..."
# Switch user and run gunicorn
exec su scribble_user -c "gunicorn --workers 1 --threads 4 --bind 0.0.0.0:13131 app:app"
else
# [NEW] Check & Run Database Migration
echo "Checking for database migrations..."
until python3 -c "from database import db; from app import app; app.app_context().push(); db.engine.connect()" > /dev/null 2>&1; do
echo "Waiting for database..."
sleep 3
done
export SCRIBBLE_MIGRATE_ONLY=1
python3 migrate.py
unset SCRIBBLE_MIGRATE_ONLY
echo "Starting Scribble as root (Not Recommended)..."
exec gunicorn --workers 1 --threads 4 --bind 0.0.0.0:13131 app:app
fi