Skip to content

Commit 56cf735

Browse files
committed
Final fix for real
1 parent dbb943e commit 56cf735

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[Unit]
2+
Description=NASA Sky Explorer Web Application
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=nasaapp
8+
Group=nasaapp
9+
WorkingDirectory=/opt/nasa-sky-explorer
10+
Environment="PATH=/opt/nasa-sky-explorer/.venv/bin:/usr/local/bin:/usr/bin:/bin"
11+
ExecStart=/opt/nasa-sky-explorer/.venv/bin/uvicorn src.server:app --host 0.0.0.0 --port 80
12+
Restart=always
13+
RestartSec=10
14+
15+
# Security hardening (NoNewPrivileges removed to allow capabilities)
16+
PrivateTmp=true
17+
ProtectHome=true
18+
19+
# Logging
20+
StandardOutput=journal
21+
StandardError=journal
22+
SyslogIdentifier=nasaspaceapps
23+
24+
[Install]
25+
WantedBy=multi-user.target

deploy/remote_deploy.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,36 @@ pip install -r requirements.txt
3131
deactivate || true
3232
EOSCRIPT
3333

34-
# Note: Port 80 binding is handled by systemd AmbientCapabilities
35-
# No need to set capabilities on the Python binary
34+
# Apply capability for port binding if needed (for systemd < 229)
35+
# Modern systemd (>= 229) uses AmbientCapabilities in the service file
36+
if [ "${UVICORN_PORT}" -lt 1024 ]; then
37+
REAL_PYTHON=$(readlink -f "${APP_DIR}/.venv/bin/python")
38+
if [ -f "${REAL_PYTHON}" ]; then
39+
echo "Applying cap_net_bind_service to ${REAL_PYTHON}..."
40+
setcap 'cap_net_bind_service=+ep' "${REAL_PYTHON}" || echo "Warning: Failed to set capability (may not be needed with modern systemd)"
41+
fi
42+
fi
3643

3744
LOG_DIR="${APP_DIR}/logs"
3845
mkdir -p "${LOG_DIR}"
3946
chown "${APP_USER}:${APP_USER}" "${LOG_DIR}"
4047
chmod 755 "${LOG_DIR}"
4148

49+
# Always kill any existing uvicorn processes to avoid port conflicts
50+
echo "Stopping any existing uvicorn processes..."
51+
pkill -f "uvicorn src.server:app" || true
52+
sleep 2
53+
4254
if command -v systemctl >/dev/null 2>&1; then
4355
systemctl daemon-reload || true
4456
if systemctl list-unit-files | grep -q "^${SERVICE_NAME}\.service"; then
57+
echo "Restarting systemd service ${SERVICE_NAME}.service..."
4558
systemctl restart "${SERVICE_NAME}.service"
4659
exit 0
4760
fi
4861
fi
4962

5063
echo "systemd unit ${SERVICE_NAME}.service not found or unavailable. Relaunching Uvicorn with nohup."
5164

52-
pkill -f "uvicorn src.server:app" || true
5365
sudo -u "${APP_USER}" nohup "${APP_DIR}/.venv/bin/uvicorn" src.server:app --host 0.0.0.0 --port "${UVICORN_PORT}" \
5466
>"${LOG_DIR}/uvicorn.log" 2>&1 &

0 commit comments

Comments
 (0)