gitea, notion webhook
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

88 lines
1.9 KiB

#!/usr/bin/env bash
#
# slack-notifier 실행 스크립트 — 스크립트가 위치한 디렉터리에서 백그라운드로 운영.
# (배포 경로 예: /data/app/notifier/start.sh)
#
# ./start.sh start [dev|prod] # 백그라운드 시작 (기본 prod)
# ./start.sh stop # 종료
# ./start.sh restart [dev|prod] # 재시작
# ./start.sh status # 상태
#
# 같은 디렉터리에 바이너리(slack-notifier)와 .env.{env} 가 있어야 한다.
set -euo pipefail
APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$APP_DIR"
BIN="./slack-notifier"
ENV="${2:-prod}"
PID_FILE="$APP_DIR/run/slack-notifier.pid"
CONSOLE_LOG="$APP_DIR/logs/console.log" # stdout/stderr (기동 전 출력·패닉 포함)
mkdir -p "$APP_DIR/run" "$APP_DIR/logs"
is_running() {
[[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null
}
start() {
if is_running; then
echo "이미 실행 중 (pid $(cat "$PID_FILE"))"
return 0
fi
if [[ ! -x "$BIN" ]]; then
echo "바이너리가 없거나 실행 권한 없음: $BIN"
exit 1
fi
nohup "$BIN" -env "$ENV" >>"$CONSOLE_LOG" 2>&1 &
echo $! >"$PID_FILE"
sleep 1
if is_running; then
echo "시작됨 (pid $(cat "$PID_FILE"), env=$ENV)"
else
echo "시작 실패 — 마지막 로그:"
tail -n 20 "$CONSOLE_LOG"
rm -f "$PID_FILE"
exit 1
fi
}
stop() {
if ! is_running; then
echo "실행 중이 아님"
rm -f "$PID_FILE"
return 0
fi
local pid
pid="$(cat "$PID_FILE")"
kill "$pid" 2>/dev/null || true
for _ in $(seq 1 10); do
is_running || break
sleep 0.5
done
if is_running; then
kill -9 "$pid" 2>/dev/null || true
fi
rm -f "$PID_FILE"
echo "종료됨"
}
case "${1:-}" in
start) start ;;
stop) stop ;;
restart)
stop
start
;;
status)
if is_running; then
echo "running (pid $(cat "$PID_FILE"))"
else
echo "stopped"
fi
;;
*)
echo "사용법: $0 {start|stop|restart|status} [dev|prod]"
exit 1
;;
esac