This commit is contained in:
2026-10-16 23:54:22 +03:30
parent 56cd3edd87
commit dd39844c02
34 changed files with 591 additions and 31249 deletions

31
app.sh
View File

@@ -12,13 +12,15 @@ MAVEN_SETTINGS_FILE="${CTI_MAVEN_SETTINGS:-/etc/cti/maven-settings.xml}"
log() { printf '[app] %s\n' "$*"; }
archive_log() {
local log_file="$1" archive_file
[[ -s "$log_file" ]] || return 0
archive_file="${log_file}.$(date '+%Y%m%d-%H%M%S')-$$"
mv -- "$log_file" "$archive_file"
log "archived previous log: $archive_file"
}
if ! command -v npm >/dev/null 2>&1 && [[ -n "${HOME:-}" ]]; then
for node_bin in "$HOME"/.nvm/versions/node/*/bin; do
if [[ -x "$node_bin/npm" ]]; then
PATH="$node_bin:$PATH"
export PATH
break
fi
done
fi
service_running() {
local pid_file="$1" expected_dir pid pgid actual_dir
@@ -66,22 +68,15 @@ start_service() {
return 0
fi
rm -f -- "$pid_file"
archive_log "$service_log"
if [[ "$1" == mvn ]]; then
archive_log "$(dirname -- "$service_log")/pline.log"
fi
: > "$service_log"
log "starting $name: $*"
cd "$service_dir"
nohup setsid bash -c '
pid_file="$1"
service_log_dir="$2"
shift 2
shift
printf "%s\n" "$$" > "$pid_file"
if [[ "$1" == mvn ]]; then
export LOGGING_FILE_NAME="$service_log_dir/pline.log"
fi
exec "$@"
' app-service "$pid_file" "$(dirname -- "$service_log")" "$@" >> "$service_log" 2>&1 </dev/null &
' app-service "$pid_file" "$@" >> "$service_log" 2>&1 </dev/null &
for _ in {1..10}; do
service_running "$pid_file" "$service_dir" && break
@@ -108,7 +103,7 @@ start_all() {
stop_service frontend "$RUN_DIR/frontend.pid" "$FRONTEND_DIR"
start_service backend "$BACKEND_DIR" "$BACKEND_LOG" "$RUN_DIR/backend.pid" "${maven_command[@]}" spring-boot:run
if ! start_service frontend "$FRONTEND_DIR" "$FRONTEND_LOG" "$RUN_DIR/frontend.pid" npm start; then
stop_service backend "$RUN_DIR/backend.pid" "$BACKEND_DIR"
log 'frontend failed to start; backend remains running'
return 1
fi
log 'both services are running; follow logs with: ./app.sh logs'