Commit c357d256 authored by xiezhi's avatar xiezhi

fix makefile

parent c91c6afb
......@@ -53,11 +53,7 @@ run: install
# 停止命令
.PHONY: stop
stop: kill
# 强制杀死所有相关Go进程
.PHONY: kill
kill:
stop:
@echo "正在查找并杀死所有相关的Go进程..."
@PIDS=$$(ps aux | grep -E "hello_world|$(APP_NAME)" | grep -v grep | awk '{print $$2}'); \
if [ -n "$$PIDS" ]; then \
......@@ -72,65 +68,4 @@ kill:
echo "未找到相关的Go进程"; \
fi
@rm -f $(PID_FILE)
@echo "✅ 强制停止操作完成"
# 重启命令
.PHONY: restart
restart: stop run
# 查看状态
.PHONY: status
status:
@if [ -f "$(PID_FILE)" ]; then \
PID=$$(cat $(PID_FILE)); \
if ps -p $$PID > /dev/null 2>&1; then \
echo "✅ 服务器正在运行,PID: $$PID"; \
echo "端口: $(APP_PORT)"; \
echo "日志: $(LOG_FILE)"; \
else \
echo "❌ 服务器未运行(PID文件存在但进程不存在)"; \
rm -f $(PID_FILE); \
fi; \
else \
echo "❌ 服务器未运行"; \
fi
# 开发模式运行
.PHONY: dev
dev:
@echo "开发模式运行Go程序..."
@APP_PORT_1=$(APP_PORT) $(GO_RUN) main.go
# 清理编译文件
.PHONY: clean
clean:
@echo "清理编译文件..."
rm -rf $(BUILD_DIR)
@echo "清理完成!"
# 显示帮助信息
.PHONY: help
help:
@echo "Go 1.23.4 HTTP 服务器项目"
@echo ""
@echo "可用命令:"
@echo " make install - 安装依赖并编译项目"
@echo " make run - 启动HTTP服务器(后台运行)"
@echo " make stop - 停止HTTP服务器(优雅停止)"
@echo " make kill - 强制杀死所有相关Go进程"
@echo " make restart - 重启HTTP服务器"
@echo " make status - 查看服务器状态"
@echo " make dev - 开发模式运行"
@echo " make clean - 清理编译文件"
@echo " make help - 显示此帮助信息"
@echo ""
@echo "示例:"
@echo " make run # 启动服务器"
@echo " make status # 查看状态"
@echo " make stop # 优雅停止服务器"
@echo " make kill # 强制停止所有相关进程"
@echo " make restart # 重启服务器"
@echo " make dev # 开发模式运行"
@echo ""
@echo "环境变量:"
@echo " APP_PORT_1 - 服务器端口(默认: 8000)"
@echo "✅ 停止操作完成"
......@@ -51,23 +51,8 @@ make install
# 启动服务器(后台运行)
make run
# 开发模式运行
make dev
# 查看服务器状态
make status
# 停止服务器
make stop
# 重启服务器
make restart
# 清理编译文件
make clean
# 查看帮助
make help
```
### 3. 直接使用 Go 命令
......@@ -165,11 +150,8 @@ if port == "" {
### 查看日志
```bash
# 使用 Makefile 查看日志
# 查看日志
tail -f .logs/app.log
# 查看服务器状态
make status
```
### 健康检查
......@@ -217,8 +199,8 @@ make stop
2. **编译错误**
```bash
# 清理并重新编译
make clean
# 重新编译
rm -rf build
make install
```
......@@ -231,9 +213,6 @@ docker build --no-cache -t test .
### 调试模式
```bash
# 开发模式运行(显示详细日志)
make dev
# 直接运行 Go 程序
go run main.go
```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment