Compare commits
2 Commits
90e4726a61
...
9bb805cb99
| Author | SHA1 | Date | |
|---|---|---|---|
| 9bb805cb99 | |||
| d65523e429 |
@ -91,21 +91,145 @@ cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/gunicorn --bind 0.0.0.0:6868 --workers 2 --timeout 120 app.main:create_app()
|
||||
Environment=PYTHONPATH=/opt/${APPLICATION}/backend
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python -m gunicorn --bind 0.0.0.0:6868 --workers 2 --timeout 120 --pythonpath /opt/${APPLICATION}/backend app.main:create_app
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
$STD systemctl daemon-reload
|
||||
systemctl enable -q --now ${APPLICATION}
|
||||
|
||||
# Test the application manually first
|
||||
msg_info "Testing Application"
|
||||
cd /opt/${APPLICATION}/backend
|
||||
|
||||
# Check if the main module exists and is importable
|
||||
if ! /opt/${APPLICATION}/venv/bin/python -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/${APPLICATION}/backend')
|
||||
try:
|
||||
import app.main
|
||||
print('✓ app.main imported successfully')
|
||||
except ImportError as e:
|
||||
print(f'✗ Import error: {e}')
|
||||
# List directory structure for debugging
|
||||
import os
|
||||
print('Backend directory contents:')
|
||||
for root, dirs, files in os.walk('/opt/${APPLICATION}/backend'):
|
||||
level = root.replace('/opt/${APPLICATION}/backend', '').count(os.sep)
|
||||
indent = ' ' * 2 * level
|
||||
print(f'{indent}{os.path.basename(root)}/')
|
||||
subindent = ' ' * 2 * (level + 1)
|
||||
for file in files:
|
||||
if file.endswith('.py'):
|
||||
print(f'{subindent}{file}')
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f'✗ Other error: {e}')
|
||||
sys.exit(1)
|
||||
"; then
|
||||
msg_error "Application import test failed"
|
||||
|
||||
# Try alternative approaches
|
||||
msg_info "Trying alternative startup methods"
|
||||
|
||||
# Check if there's a direct run.py or main.py
|
||||
if [[ -f "/opt/${APPLICATION}/backend/run.py" ]]; then
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python run.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
elif [[ -f "/opt/${APPLICATION}/backend/main.py" ]]; then
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python main.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
else
|
||||
# Fallback to Flask development server
|
||||
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
|
||||
[Unit]
|
||||
Description=Profilarr Profile Manager
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/${APPLICATION}/backend
|
||||
Environment=PATH=/opt/${APPLICATION}/venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=CONFIG_PATH=/opt/${APPLICATION}_config
|
||||
Environment=FLASK_APP=app.main:create_app
|
||||
Environment=FLASK_RUN_HOST=0.0.0.0
|
||||
Environment=FLASK_RUN_PORT=6868
|
||||
ExecStart=/opt/${APPLICATION}/venv/bin/python -m flask run
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
fi
|
||||
|
||||
$STD systemctl daemon-reload
|
||||
fi
|
||||
|
||||
systemctl enable ${APPLICATION}
|
||||
systemctl start ${APPLICATION}
|
||||
|
||||
# Wait and check status
|
||||
sleep 5
|
||||
if systemctl is-active --quiet ${APPLICATION}; then
|
||||
msg_ok "Service started successfully"
|
||||
else
|
||||
msg_error "Service failed to start. Checking logs..."
|
||||
journalctl -u ${APPLICATION} --no-pager -n 20
|
||||
exit 1
|
||||
fi
|
||||
msg_ok "Created Service"
|
||||
|
||||
motd_ssh
|
||||
|
||||
Reference in New Issue
Block a user