|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# 이 스크립트는 hello 프로그램을 데몬 형태로 실행하여 |
4 | | -# 프로그램이 종료될 때마다 재시작합니다. |
5 | | -# |
6 | | -# 이 스크립트를 사용하기 전에, setup_core_dump_systemwide.sh 스크립트를 통해 |
7 | | -# 시스템 전역 코어 덤프 설정을 해야 합니다. |
8 | | -# 설정하지 않으면 coredump 파일이 생성되지 않습니다. |
| 3 | +# This script runs the hello program as a daemon, |
| 4 | +# restarting it every time it exits. |
| 5 | +# |
| 6 | +# Before using this script, you must configure system-wide core dump settings |
| 7 | +# using the setup_core_dump_systemwide.sh script. |
| 8 | +# If not configured, coredump files will not be created. |
9 | 9 |
|
10 | 10 | set -euo pipefail |
11 | 11 |
|
12 | | -# 작업 디렉터리 및 실행 파일 경로, 로그 파일 경로 설정 |
| 12 | +# Set working directory, executable path, and log file path |
13 | 13 | WORKDIR="/home/jaytwo/workspace/coredump-workspace" |
14 | 14 | EXEC="${WORKDIR}/hello" |
15 | 15 | LOG="${WORKDIR}/hello_daemon.log" |
16 | 16 |
|
17 | 17 | cd "${WORKDIR}" |
18 | 18 |
|
19 | | -# 코어 덤프 허용 (이 스크립트가 실행하는 hello에 적용) |
| 19 | +# Allow core dumps (applies to hello run by this script) |
20 | 20 | ulimit -c unlimited |
21 | 21 |
|
22 | | -# ASAN/UBSAN 설정 (필요시) |
| 22 | +# ASAN/UBSAN settings (if needed) |
23 | 23 | export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" |
24 | 24 | export UBSAN_OPTIONS="halt_on_error=1:abort_on_error=1" |
25 | 25 |
|
26 | | -# 데몬 시작 로그 기록 |
| 26 | +# Log daemon start |
27 | 27 | echo "[$(date '+%F %T')] daemon start" >> "${LOG}" |
28 | 28 |
|
29 | | -# 로그 파일 크기 제한: 10MB 초과 시 최근 10000줄만 남김 |
| 29 | +# Limit log file size: if over 10MB, keep only the last 10,000 lines |
30 | 30 | MAX_LOG_SIZE=10485760 # 10MB |
31 | 31 | MAX_LOG_LINES=10000 |
32 | 32 | if [ -f "${LOG}" ] && [ $(stat -c%s "${LOG}") -ge $MAX_LOG_SIZE ]; then |
|
36 | 36 |
|
37 | 37 | while true; do |
38 | 38 |
|
39 | | - # 실행 시작 로그 기록 |
| 39 | + # Log start of execution |
40 | 40 | echo "[$(date '+%F %T')] starting hello" >> "${LOG}" |
41 | 41 |
|
42 | | - # 실행 |
| 42 | + # Run |
43 | 43 | "${EXEC}" |
44 | 44 | rc=$? |
45 | 45 |
|
46 | | - # 종료 로그 기록 |
| 46 | + # Log exit |
47 | 47 | echo "[$(date '+%F %T')] hello exited rc=${rc}" >> "${LOG}" |
48 | 48 |
|
49 | | - # 너무 빠른 재시작 방지 |
| 49 | + # Prevent too rapid restarts |
50 | 50 | sleep 600 # seconds |
51 | 51 |
|
52 | 52 | # NOTE: crash에 의한 소프트웨어 정지가 원인일 확률이 높으며, |
|
0 commit comments