Spaces:
Running
Running
Simplify Docker logging and fix preview app working directory
Browse files
app.py
CHANGED
@@ -84,10 +84,14 @@ def start_preview_app():
|
|
84 |
|
85 |
print(f"π Starting preview app from `{app_file}` on port {PREVIEW_PORT}...")
|
86 |
try:
|
|
|
|
|
|
|
|
|
87 |
preview_process = subprocess.Popen(
|
88 |
[
|
89 |
"python",
|
90 |
-
|
91 |
"--server-port",
|
92 |
str(PREVIEW_PORT),
|
93 |
"--server-name",
|
@@ -96,6 +100,7 @@ def start_preview_app():
|
|
96 |
stdout=subprocess.PIPE,
|
97 |
stderr=subprocess.PIPE,
|
98 |
text=True,
|
|
|
99 |
)
|
100 |
# Give it a moment to start up
|
101 |
time.sleep(3)
|
@@ -103,9 +108,10 @@ def start_preview_app():
|
|
103 |
print(f"β
Preview app started successfully (PID: {preview_process.pid}).")
|
104 |
return True, f"Preview running at {PREVIEW_URL}"
|
105 |
else:
|
106 |
-
stderr = preview_process.
|
107 |
-
|
108 |
-
|
|
|
109 |
except Exception as e:
|
110 |
print(f"β Exception while starting preview app: {e}")
|
111 |
return False, f"Error starting preview app: {e}"
|
|
|
84 |
|
85 |
print(f"π Starting preview app from `{app_file}` on port {PREVIEW_PORT}...")
|
86 |
try:
|
87 |
+
# Change to the directory containing the app file
|
88 |
+
app_dir = str(Path(app_file).parent)
|
89 |
+
app_filename = Path(app_file).name
|
90 |
+
|
91 |
preview_process = subprocess.Popen(
|
92 |
[
|
93 |
"python",
|
94 |
+
app_filename,
|
95 |
"--server-port",
|
96 |
str(PREVIEW_PORT),
|
97 |
"--server-name",
|
|
|
100 |
stdout=subprocess.PIPE,
|
101 |
stderr=subprocess.PIPE,
|
102 |
text=True,
|
103 |
+
cwd=app_dir, # Set working directory to the app directory
|
104 |
)
|
105 |
# Give it a moment to start up
|
106 |
time.sleep(3)
|
|
|
108 |
print(f"β
Preview app started successfully (PID: {preview_process.pid}).")
|
109 |
return True, f"Preview running at {PREVIEW_URL}"
|
110 |
else:
|
111 |
+
stdout, stderr = preview_process.communicate()
|
112 |
+
error_msg = f"STDOUT:\n{stdout}\nSTDERR:\n{stderr}"
|
113 |
+
print(f"β Failed to start preview app. Error:\n{error_msg}")
|
114 |
+
return False, f"Failed to start preview app:\n{error_msg}"
|
115 |
except Exception as e:
|
116 |
print(f"β Exception while starting preview app: {e}")
|
117 |
return False, f"Error starting preview app: {e}"
|
start.sh
CHANGED
@@ -1,29 +1,24 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start nginx in background as non-root user
|
|
|
4 |
nginx -g 'daemon off;' &
|
5 |
NGINX_PID=$!
|
6 |
|
7 |
-
# Wait a moment for nginx to start
|
8 |
-
sleep 2
|
9 |
-
|
10 |
-
# Start the main Gradio app on port 7862 (internal)
|
11 |
-
python app.py --server-port 7862 --server-name 0.0.0.0 &
|
12 |
-
APP_PID=$!
|
13 |
-
|
14 |
# Function to handle shutdown
|
15 |
cleanup() {
|
16 |
echo "Shutting down..."
|
17 |
-
kill $NGINX_PID
|
18 |
-
wait $NGINX_PID
|
19 |
exit 0
|
20 |
}
|
21 |
|
22 |
# Set up signal handlers
|
23 |
trap cleanup SIGTERM SIGINT
|
24 |
|
25 |
-
# Wait for
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
# Start nginx in background as non-root user
|
4 |
+
echo "Starting nginx..."
|
5 |
nginx -g 'daemon off;' &
|
6 |
NGINX_PID=$!
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Function to handle shutdown
|
9 |
cleanup() {
|
10 |
echo "Shutting down..."
|
11 |
+
kill $NGINX_PID 2>/dev/null
|
12 |
+
wait $NGINX_PID 2>/dev/null
|
13 |
exit 0
|
14 |
}
|
15 |
|
16 |
# Set up signal handlers
|
17 |
trap cleanup SIGTERM SIGINT
|
18 |
|
19 |
+
# Wait a moment for nginx to start
|
20 |
+
sleep 2
|
21 |
|
22 |
+
echo "Starting Gradio app on port 7862..."
|
23 |
+
# Run the main app in foreground so Docker captures its logs
|
24 |
+
python app.py --server-port 7862 --server-name 0.0.0.0
|