53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
echo "Starting DigiServer v2..."
|
|
|
|
# Create necessary directories
|
|
mkdir -p /app/instance
|
|
mkdir -p /app/app/static/uploads
|
|
|
|
# Initialize database if it doesn't exist
|
|
if [ ! -f /app/instance/dashboard.db ]; then
|
|
echo "Initializing database..."
|
|
python -c "
|
|
from app.app import create_app
|
|
from app.extensions import db, bcrypt
|
|
from app.models import User
|
|
|
|
app = create_app('production')
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
# Create or update admin user from environment variables
|
|
import os
|
|
admin_username = os.getenv('ADMIN_USERNAME', 'admin')
|
|
admin_password = os.getenv('ADMIN_PASSWORD', 'admin123')
|
|
|
|
admin = User.query.filter_by(username=admin_username).first()
|
|
if not admin:
|
|
hashed = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
|
admin = User(username=admin_username, password=hashed, role='admin')
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
print(f'✅ Admin user created ({admin_username})')
|
|
else:
|
|
# Update password if it exists
|
|
hashed = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
|
admin.password = hashed
|
|
db.session.commit()
|
|
print(f'✅ Admin user password updated ({admin_username})')
|
|
"
|
|
echo "Database initialized!"
|
|
fi
|
|
|
|
# Start the application
|
|
echo "Starting Gunicorn..."
|
|
exec gunicorn \
|
|
--bind 0.0.0.0:5000 \
|
|
--workers 4 \
|
|
--timeout 120 \
|
|
--access-logfile - \
|
|
--error-logfile - \
|
|
"app.app:create_app('production')"
|