@@ -25,9 +25,42 @@ start_core() {
2525# Start API service
2626start_api () {
2727 log " Starting router-api..."
28+
29+ # First start the API service
2830 nohup /usr/local/bin/router-api > " $LOG_DIR /api.log" 2> " $LOG_DIR /api.error" &
29- echo $! > " $PID_DIR /api.pid"
30- log " router-api started (PID: $! )"
31+ local api_pid=$!
32+ echo $api_pid > " $PID_DIR /api.pid"
33+ log " router-api started (PID: $api_pid )"
34+
35+ # Wait a moment to check if API started successfully
36+ sleep 2
37+
38+ # Check if API is still running
39+ if kill -0 $api_pid 2> /dev/null; then
40+ # Check for config files in order of priority
41+ local config_file=" "
42+ if [ -f " /data/config.yaml" ]; then
43+ config_file=" /data/config.yaml"
44+ elif [ -f " $HOME /config.yaml" ]; then
45+ config_file=" $HOME /config.yaml"
46+ elif [ -f " /app/config.yaml" ]; then
47+ config_file=" /app/config.yaml"
48+ elif [ ! -z " $CONFIG_FILE " ]; then
49+ config_file=" $CONFIG_FILE "
50+ fi
51+
52+ if [ ! -z " $config_file " ]; then
53+ log " API running successfully, starting gwrs with config: $config_file "
54+ nohup gwrs --osenv --config " $config_file " > " $LOG_DIR /gwrs.log" 2> " $LOG_DIR /gwrs.error" &
55+ echo $! > " $PID_DIR /gwrs.pid"
56+ log " gwrs started (PID: $! )"
57+ else
58+ log " API running successfully but no config file found, skipping gwrs"
59+ fi
60+ else
61+ log " API failed to start, not running gwrs"
62+ rm -f " $PID_DIR /api.pid"
63+ fi
3164}
3265
3366# Stop a service
0 commit comments