mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-27 11:14:59 +00:00
fix(dev): ignore invalid backend pid files
This commit is contained in:
parent
3f7145a843
commit
798038fcc1
2 changed files with 45 additions and 0 deletions
|
|
@ -35,6 +35,10 @@ is_running() {
|
|||
local pid
|
||||
pid="$(cat "$pid_file" 2>/dev/null || true)"
|
||||
[[ "$pid" =~ ^[0-9]+$ ]] || return 1
|
||||
(( pid > 1 )) || {
|
||||
rm -f "$pid_file"
|
||||
return 1
|
||||
}
|
||||
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
return 0
|
||||
|
|
|
|||
41
scripts/tests/dev-process-test.sh
Executable file
41
scripts/tests/dev-process-test.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
DEV_PROCESS="$REPO_ROOT/scripts/dev-process.sh"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
PID_FILE="$TMP_DIR/process.pid"
|
||||
LOG_FILE="$TMP_DIR/process.log"
|
||||
|
||||
cleanup() {
|
||||
bash "$DEV_PROCESS" stop --pid-file "$PID_FILE" >/dev/null 2>&1 || true
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "0" >"$PID_FILE"
|
||||
if bash "$DEV_PROCESS" status --pid-file "$PID_FILE" >/dev/null 2>&1; then
|
||||
echo "expected PID 0 to be treated as not running" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f "$PID_FILE" ]]; then
|
||||
echo "expected invalid PID file to be removed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bash "$DEV_PROCESS" start \
|
||||
--pid-file "$PID_FILE" \
|
||||
--log-file "$LOG_FILE" \
|
||||
--cwd "$REPO_ROOT" \
|
||||
-- /bin/sh -lc 'sleep 30'
|
||||
|
||||
bash "$DEV_PROCESS" status --pid-file "$PID_FILE" >/dev/null
|
||||
|
||||
bash "$DEV_PROCESS" stop --pid-file "$PID_FILE"
|
||||
|
||||
if [[ -f "$PID_FILE" ]]; then
|
||||
echo "expected PID file to be removed after stop" >&2
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Reference in a new issue