Skip to content

Commit 84c953f

Browse files
committed
feat: 完善应用启动、停止和状态检查脚本
重构启动、停止和状态检查脚本,增加错误处理、日志记录和配置管理 添加Makefile支持常用命令 更新.env.example文件包含更详细的配置说明
1 parent eb425fe commit 84c953f

6 files changed

Lines changed: 1025 additions & 56 deletions

File tree

.env.example

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,77 @@
11
# EveryDocs Environment Variables
22
# Copy this file to .env and fill in the actual values
3+
# Note: .env is already listed in .gitignore, so your secrets will never be committed.
34

4-
# Rails secret key base - use `openssl rand -hex 64` to generate
5-
SECRET_KEY_BASE=your_secret_key_base_here
5+
# ==============================================================================
6+
# Database Configuration (for Docker Compose and Manual Installation)
7+
# ==============================================================================
68

7-
# MySQL root password - use a strong password
9+
# MySQL root password - use a strong password (Docker Compose only)
10+
# Generate: openssl rand -hex 32
811
MYSQL_ROOT_PASSWORD=your_strong_mysql_root_password
912

10-
# MySQL user password for 'everydocs' user - use a strong password
13+
# MySQL password for the 'everydocs' user - use a strong password
14+
# Generate: openssl rand -hex 32
1115
MYSQL_PASSWORD=your_strong_mysql_password
1216

13-
# Security Notes:
14-
# 1. NEVER use the default or weak passwords in production
17+
# Rails secret key base - required for all installations
18+
# Generate: openssl rand -hex 64
19+
SECRET_KEY_BASE=your_secret_key_base_here
20+
21+
# ==============================================================================
22+
# Database Connection (for Manual Installation only)
23+
# ==============================================================================
24+
25+
# Database adapter (default: mysql2)
26+
EVERYDOCS_DB_ADAPTER=mysql2
27+
28+
# Database name (default: everydocs)
29+
EVERYDOCS_DB_NAME=everydocs
30+
31+
# Database user (default: everydocs)
32+
EVERYDOCS_DB_USER=everydocs
33+
34+
# Database host (default: localhost)
35+
EVERYDOCS_DB_HOST=localhost
36+
37+
# Database port (default: 3306)
38+
EVERYDOCS_DB_PORT=3306
39+
40+
# ==============================================================================
41+
# Application Configuration (for Manual Installation only)
42+
# ==============================================================================
43+
44+
# Rails environment (development, test, production)
45+
# Default: production
46+
RAILS_ENV=production
47+
48+
# Application port
49+
# Default: 5678
50+
PORT=5678
51+
52+
# Log directory (relative to project root or absolute path)
53+
# Default: log
54+
LOG_DIR=log
55+
56+
# PID file directory (relative to project root or absolute path)
57+
# Default: tmp/pids
58+
PID_DIR=tmp/pids
59+
60+
# ==============================================================================
61+
# Docker Compose Configuration
62+
# ==============================================================================
63+
64+
# Docker Compose ports (these are the ports exposed on the host)
65+
# API Port (EveryDocs Core) - Default: 5678
66+
# Web UI HTTP Port - Default: 8080
67+
# Web UI HTTPS Port - Default: 8443
68+
69+
# ==============================================================================
70+
# Security Notes
71+
# ==============================================================================
72+
# 1. NEVER use weak passwords or the example values in production
1573
# 2. Use `openssl rand -hex 32` or similar to generate strong passwords
16-
# 3. Keep this file (and your .env) out of version control
17-
# 4. .env is already listed in .gitignore
74+
# 3. Use `openssl rand -hex 64` to generate SECRET_KEY_BASE
75+
# 4. Keep this file (and your .env) out of version control
76+
# 5. For Docker Compose, only MYSQL_ROOT_PASSWORD, MYSQL_PASSWORD, and SECRET_KEY_BASE are required
77+
# 6. For Manual Installation, all database and application variables are required

Makefile

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
.PHONY: start stop restart status smoke clean help
2+
3+
.DEFAULT_GOAL := help
4+
5+
PROJECT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
6+
PID_DIR := tmp/pids
7+
PID_FILE := $(PID_DIR)/everydocs.pid
8+
LOG_DIR := log
9+
10+
help:
11+
@echo "EveryDocs Core - Make Commands"
12+
@echo "=============================================="
13+
@echo ""
14+
@echo "Commands:"
15+
@echo " start - Start the EveryDocs server"
16+
@echo " stop - Stop the EveryDocs server"
17+
@echo " restart - Restart the EveryDocs server"
18+
@echo " status - Check server status"
19+
@echo " smoke - Run non-interactive smoke test (for CI)"
20+
@echo " test - Run Rails tests"
21+
@echo " logs - Tail the server logs"
22+
@echo " clean-logs - Clean log files"
23+
@echo " help - Show this help message"
24+
@echo ""
25+
@echo "Environment Variables (can be set in .env file):"
26+
@echo " RAILS_ENV - Rails environment (default: production)"
27+
@echo " PORT - Server port (default: 5678)"
28+
@echo " SECRET_KEY_BASE - Rails secret key (required)"
29+
@echo " MYSQL_PASSWORD - Database password (required)"
30+
@echo ""
31+
@echo "Examples:"
32+
@echo " make start"
33+
@echo " make stop"
34+
@echo " make restart"
35+
@echo " make smoke"
36+
@echo ""
37+
38+
start:
39+
@echo "Starting EveryDocs Core..."
40+
@cd $(PROJECT_DIR) && ./start-app.sh
41+
42+
stop:
43+
@echo "Stopping EveryDocs Core..."
44+
@cd $(PROJECT_DIR) && ./stop-app.sh
45+
46+
restart: stop start
47+
48+
status:
49+
@cd $(PROJECT_DIR) && ./status.sh
50+
51+
logs:
52+
@echo "Tailing logs (Ctrl+C to exit)..."
53+
@tail -f $(LOG_DIR)/everydocs.log $(LOG_DIR)/everydocs.error.log 2>/dev/null || echo "Log files not found yet"
54+
55+
logs-error:
56+
@echo "Tailing error logs (Ctrl+C to exit)..."
57+
@tail -f $(LOG_DIR)/everydocs.error.log 2>/dev/null || echo "Error log file not found yet"
58+
59+
clean-logs:
60+
@echo "Cleaning log files..."
61+
@rm -f $(LOG_DIR)/everydocs.log $(LOG_DIR)/everydocs.error.log
62+
@echo "Log files cleaned"
63+
64+
test:
65+
@echo "Running Rails tests..."
66+
@cd $(PROJECT_DIR) && rails test RAILS_ENV=test
67+
68+
test-controllers:
69+
@echo "Running controller tests..."
70+
@cd $(PROJECT_DIR) && rails test test/controllers/ RAILS_ENV=test
71+
72+
db-migrate:
73+
@echo "Running database migrations..."
74+
@cd $(PROJECT_DIR) && rails db:migrate
75+
76+
db-migrate-test:
77+
@echo "Running database migrations (test env)..."
78+
@cd $(PROJECT_DIR) && rails db:migrate RAILS_ENV=test
79+
80+
smoke:
81+
@echo "=============================================="
82+
@echo "EveryDocs Core - Non-Interactive Smoke Test"
83+
@echo "=============================================="
84+
@echo ""
85+
@echo "Phase 1: Checking prerequisites..."
86+
@cd $(PROJECT_DIR) && if [ ! -f .env ]; then \
87+
echo " ERROR: .env file not found"; \
88+
echo " Create one from .env.example: cp .env.example .env"; \
89+
exit 1; \
90+
else \
91+
echo " ✓ .env file exists"; \
92+
fi
93+
@cd $(PROJECT_DIR) && if grep -q "your_secret_key_base_here" .env 2>/dev/null; then \
94+
echo " ERROR: SECRET_KEY_BASE not set in .env"; \
95+
echo " Generate one with: openssl rand -hex 64"; \
96+
exit 1; \
97+
else \
98+
echo " ✓ SECRET_KEY_BASE appears to be set"; \
99+
fi
100+
@echo ""
101+
102+
@echo "Phase 2: Checking required commands..."
103+
@which ruby >/dev/null 2>&1 && echo " ✓ ruby" || (echo " ✗ ruby (required)" && exit 1)
104+
@which bundle >/dev/null 2>&1 && echo " ✓ bundle" || (echo " ✗ bundle (required)" && exit 1)
105+
@which rails >/dev/null 2>&1 && echo " ✓ rails" || (echo " ✗ rails (required)" && exit 1)
106+
@echo ""
107+
108+
@echo "Phase 3: Checking bundle dependencies..."
109+
@cd $(PROJECT_DIR) && bundle check 2>/dev/null && echo " ✓ Dependencies satisfied" || (echo " ✗ Dependencies missing. Run: bundle install" && exit 1)
110+
@echo ""
111+
112+
@echo "Phase 4: Checking test setup..."
113+
@cd $(PROJECT_DIR) && rails db:migrate RAILS_ENV=test 2>&1 | tail -1
114+
@echo ""
115+
116+
@echo "Phase 5: Running basic tests..."
117+
@cd $(PROJECT_DIR) && rails test RAILS_ENV=test 2>&1
118+
@echo ""
119+
120+
@echo "=============================================="
121+
@echo "Smoke Test Completed"
122+
@echo "=============================================="

0 commit comments

Comments
 (0)