|
5 | 5 | CONFIG_PATH=$(bashio::config 'ha_config_path' || echo "/config") |
6 | 6 | LOG_LEVEL=$(bashio::config 'log_level' || echo "info") |
7 | 7 |
|
| 8 | +# Export log level for scripts |
| 9 | +export LOG_LEVEL |
| 10 | + |
8 | 11 | # Validate log level |
9 | 12 | case "${LOG_LEVEL}" in |
10 | 13 | debug|info|warning|error) ;; |
|
64 | 67 |
|
65 | 68 | # Load security utilities if available |
66 | 69 | if [[ -f "/opt/scripts/security-utils.sh" ]]; then |
67 | | - source "/opt/scripts/security-utils.sh" |
68 | | - bashio::log.info "Security utilities loaded" |
69 | | - |
70 | | - # Validate configuration path |
71 | | - if ! validate_config_path "${CONFIG_PATH}"; then |
72 | | - bashio::log.error "Invalid configuration path: ${CONFIG_PATH}" |
73 | | - exit 1 |
| 70 | + if source "/opt/scripts/security-utils.sh" 2>/dev/null; then |
| 71 | + bashio::log.info "Security utilities loaded" |
| 72 | + |
| 73 | + # Validate configuration path if function exists |
| 74 | + if command -v validate_config_path >/dev/null 2>&1; then |
| 75 | + if ! validate_config_path "${CONFIG_PATH}" 2>/dev/null; then |
| 76 | + bashio::log.warning "Configuration path validation failed: ${CONFIG_PATH}" |
| 77 | + # Don't exit - continue anyway |
| 78 | + fi |
| 79 | + fi |
| 80 | + else |
| 81 | + bashio::log.warning "Failed to load security utilities - continuing without them" |
74 | 82 | fi |
75 | 83 | fi |
76 | 84 |
|
77 | 85 | # Initialize caching if available |
78 | 86 | if [[ -f "/opt/scripts/cache-manager.sh" ]]; then |
79 | | - source "/opt/scripts/cache-manager.sh" |
80 | | - cache_init |
81 | | - bashio::log.info "Cache system initialized" |
| 87 | + if source "/opt/scripts/cache-manager.sh" 2>/dev/null; then |
| 88 | + if command -v cache_init >/dev/null 2>&1; then |
| 89 | + if cache_init 2>/dev/null; then |
| 90 | + bashio::log.info "Cache system initialized" |
| 91 | + else |
| 92 | + bashio::log.warning "Cache initialization failed - continuing without cache" |
| 93 | + fi |
| 94 | + fi |
| 95 | + else |
| 96 | + bashio::log.warning "Failed to load cache utilities - continuing without them" |
| 97 | + fi |
82 | 98 | fi |
83 | 99 |
|
84 | 100 | # Initialize circuit breakers if available |
85 | 101 | if [[ -f "/opt/scripts/circuit-breaker.sh" ]]; then |
86 | | - source "/opt/scripts/circuit-breaker.sh" |
87 | | - cb_init "mcp_server" |
88 | | - bashio::log.info "Circuit breaker system initialized" |
| 102 | + if source "/opt/scripts/circuit-breaker.sh" 2>/dev/null; then |
| 103 | + if command -v cb_init >/dev/null 2>&1; then |
| 104 | + if cb_init "mcp_server" 2>/dev/null; then |
| 105 | + bashio::log.info "Circuit breaker system initialized" |
| 106 | + else |
| 107 | + bashio::log.warning "Circuit breaker initialization failed - continuing without it" |
| 108 | + fi |
| 109 | + fi |
| 110 | + else |
| 111 | + bashio::log.warning "Failed to load circuit breaker utilities - continuing without them" |
| 112 | + fi |
89 | 113 | fi |
90 | 114 |
|
91 | 115 | # Function to handle signals for graceful shutdown |
|
116 | 140 | # Start Dashboard API on port 3001 if files exist |
117 | 141 | if [[ -f "/dashboard/api/server.js" ]]; then |
118 | 142 | bashio::log.info "Starting Dashboard API on port 3001..." |
119 | | - cd /dashboard/api |
| 143 | + cd /dashboard/api || { |
| 144 | + bashio::log.error "Failed to change to dashboard directory" |
| 145 | + exit 1 |
| 146 | + } |
| 147 | + |
| 148 | + # Test node and dependencies first |
| 149 | + if ! node --version >/dev/null 2>&1; then |
| 150 | + bashio::log.error "Node.js not available" |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | + |
| 154 | + if ! ls node_modules >/dev/null 2>&1; then |
| 155 | + bashio::log.warning "No node_modules found, dashboard may not work" |
| 156 | + fi |
| 157 | + |
120 | 158 | nohup node server.js >/tmp/dashboard.log 2>&1 & |
121 | 159 | DASHBOARD_PID=$! |
122 | 160 | bashio::log.info "Dashboard API started with PID: $DASHBOARD_PID" |
123 | | - cd / |
| 161 | + |
| 162 | + # Give dashboard time to start |
| 163 | + sleep 2 |
| 164 | + |
| 165 | + # Check if still running |
| 166 | + if ! kill -0 $DASHBOARD_PID 2>/dev/null; then |
| 167 | + bashio::log.error "Dashboard API failed to start" |
| 168 | + bashio::log.error "Dashboard logs:" |
| 169 | + cat /tmp/dashboard.log 2>/dev/null || bashio::log.error "No dashboard logs" |
| 170 | + fi |
| 171 | + |
| 172 | + cd / || true |
124 | 173 | fi |
125 | 174 |
|
126 | 175 | # Run initial health check |
|
0 commit comments