28 lines
525 B
Bash
28 lines
525 B
Bash
#!/bin/bash
|
||
|
||
# 参数检查
|
||
if [ $# -ne 1 ]; then
|
||
echo "用法: $0 <项目目录>"
|
||
exit 1
|
||
fi
|
||
|
||
project_dir="$1"
|
||
pid_file="${project_dir}/service.pid"
|
||
|
||
# 检查PID文件是否存在
|
||
if [ ! -f "$pid_file" ]; then
|
||
echo "错误: PID文件不存在,服务可能未运行"
|
||
exit 1
|
||
fi
|
||
|
||
# 停止进程
|
||
pid=$(cat "$pid_file")
|
||
if kill -0 "$pid" >/dev/null 2>&1; then
|
||
kill "$pid"
|
||
rm "$pid_file"
|
||
echo "服务已停止 (PID: $pid)"
|
||
else
|
||
echo "错误: 进程 $pid 未运行"
|
||
rm "$pid_file"
|
||
exit 1
|
||
fi |