全国大学生电子设计竞赛备赛路线图:控制类核心、元器件选型与四天三夜避坑指南
2026/9/30 0:47:48
pip3 install supervisor安装完成后,验证是否可用:
supervisord --version # 若输出版本号,说明安装成功生成默认配置文件:
echo_supervisord_conf > /etc/supervisord.conf # 若 /etc 目录不存在,先创建:mkdir -p /etc#!/bin/bash set -e # taskkill 自动探测(Cygwin PATH 可能不含 System32) TASKKILL="" command -v taskkill >/dev/null 2>&1 && TASKKILL="taskkill" [ -z "${TASKKILL}" ] && [ -f /cygdrive/c/Windows/System32/taskkill.exe ] && TASKKILL="/cygdrive/c/Windows/System32/taskkill.exe" kill_old_process() { local proc_exe="$1" # cygwin内部杀 local pids pids=$(ps -ef | grep "${proc_exe}" | grep -v grep | awk '{print $2}') if [ -n "${pids}" ];then echo "[PREPARE] kill cygwin pid ${pids} ${proc_exe}" kill ${pids} 2>/dev/null || true sleep 1 pids=$(ps -ef | grep "${proc_exe}" | grep -v grep | awk '{print $2}') if [ -n "${pids}" ];then kill -9 ${pids} 2>/dev/null || true fi fi # Windows原生强制结束,兜底 if [ -n "${TASKKILL}" ];then ${TASKKILL} /F /IM "${proc_exe}" 2>/dev/null || true fi sleep 0.3 } # 清理的是服务端 mysqld.exe(不是客户端 mysql.exe) kill_old_process "mysqld.exe" kill_old_process "redis-server.exe" kill_old_process "php-fpm.exe" kill_old_process "nginx.exe" echo "[PREPARE] env prepare done" exit 0赋可执行权限(cygwin bash 执行)
chmod +x /etc/supervisor/supervisor_prepare.sh确认服务路径(如果不在/usr/bin目录下则在/usr/sbin/目录下复制一份过去)
which mysqld.exe which redis-server.exe which php-fpm.exe which nginx.exe创建日志目录
mkdir -p /var/log/mysql /var/log/redis /var/log/phpfpm /var/log/nginx; ================= /etc/supervisord.conf Cygwin最终版 ================= [supervisord] nodaemon=false logfile=/var/log/supervisord.log pidfile=/tmp/supervisord.pid childlogdir=/var/log logfile_maxbytes=40MB logfile_backups=5 [unix_http_server] file=/tmp/supervisor.sock [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; ========== 环境初始化脚本 ========== [program:prepare_env] command=/etc/supervisor/supervisor_prepare.sh autostart=true autorestart=false priority=1 stdout_logfile=/var/log/prepare_env_std.log stderr_logfile=/var/log/prepare_env_err.log stdout_logfile_maxbytes=20MB stdout_logfile_backups=2 stopwaitsecs=10 ; ========== MySQL ========== [program:mysql] command=/usr/bin/mysqld.exe autostart=true autorestart=true startsecs=8 startretries=5 exitcodes=0 priority=5 stopwaitsecs=12 stdout_logfile=/var/log/mysql/mysql_std.log stderr_logfile=/var/log/mysql/mysql_err.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=3 stderr_logfile_maxbytes=50MB stderr_logfile_backups=3 ; ========== Redis 【配置文件路径改为 /etc/redis.conf】 ========== [program:redis] command=/usr/bin/redis-server.exe /etc/redis.conf autostart=true autorestart=true startsecs=8 startretries=8 exitcodes=0 priority=6 stopwaitsecs=15 stdout_logfile=/var/log/redis/redis_std.log stderr_logfile=/var/log/redis/redis_err.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=3 stderr_logfile_maxbytes=50MB stderr_logfile_backups=3 ; ========== PHP‑FPM ========== [program:phpfpm] command=/usr/bin/php-fpm.exe -F autostart=true autorestart=true startsecs=8 startretries=5 exitcodes=0 priority=7 stopwaitsecs=10 stdout_logfile=/var/log/phpfpm/phpfpm_std.log stderr_logfile=/var/log/phpfpm/phpfpm_err.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=3 stderr_logfile_maxbytes=50MB stderr_logfile_backups=3 ; ========== Nginx ========== [program:nginx] command=/usr/bin/nginx.exe -g "daemon off;" autostart=true autorestart=true startsecs=8 startretries=5 exitcodes=0 priority=8 stopwaitsecs=10 stdout_logfile=/var/log/nginx/nginx_std.log stderr_logfile=/var/log/nginx/nginx_err.log stdout_logfile_maxbytes=50MB stdout_logfile_backups=3 stderr_logfile_maxbytes=50MB stderr_logfile_backups=3php-fpm.conf(默认日志路径修改)
error_log = /var/log/phpfpm/php-fpm.logsupervisord -c /etc/supervisord.conf # 启动进程监控 supervisorctl status # 查看状态 supervisorctl restart all # 重启全部 supervisorctl stop all # 停止全部 supervisorctl start all # 启动全部 supervisorctl status # 查状态