资讯动态

cygwin + supervisor(进程管理器)

发布时间:2026/9/2 22:58:54 来源:尧图企业网站定制
1.打开 Cygwin 终端执行pip3 install supervisor安装完成后验证是否可用supervisord --version # 若输出版本号说明安装成功2.生成配置文件并配置生成默认配置文件echo_supervisord_conf /etc/supervisord.conf # 若 /etc 目录不存在先创建mkdir -p /etc3.创建前置脚本 /etc/supervisor/supervisor_prepare.sh#!/bin/bash set -e # taskkill 自动探测Cygwin PATH 可能不含 System32 TASKKILL command -v taskkill /dev/null 21 TASKKILLtaskkill [ -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.sh4.编辑配置文件确认服务路径(如果不在/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] nodaemonfalse logfile/var/log/supervisord.log pidfile/tmp/supervisord.pid childlogdir/var/log logfile_maxbytes40MB logfile_backups5 [unix_http_server] file/tmp/supervisor.sock [rpcinterface:supervisor] supervisor.rpcinterface_factory supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurlunix:///tmp/supervisor.sock ; 环境初始化脚本 [program:prepare_env] command/etc/supervisor/supervisor_prepare.sh autostarttrue autorestartfalse priority1 stdout_logfile/var/log/prepare_env_std.log stderr_logfile/var/log/prepare_env_err.log stdout_logfile_maxbytes20MB stdout_logfile_backups2 stopwaitsecs10 ; MySQL [program:mysql] command/usr/bin/mysqld.exe autostarttrue autorestarttrue startsecs8 startretries5 exitcodes0 priority5 stopwaitsecs12 stdout_logfile/var/log/mysql/mysql_std.log stderr_logfile/var/log/mysql/mysql_err.log stdout_logfile_maxbytes50MB stdout_logfile_backups3 stderr_logfile_maxbytes50MB stderr_logfile_backups3 ; Redis 【配置文件路径改为 /etc/redis.conf】 [program:redis] command/usr/bin/redis-server.exe /etc/redis.conf autostarttrue autorestarttrue startsecs8 startretries8 exitcodes0 priority6 stopwaitsecs15 stdout_logfile/var/log/redis/redis_std.log stderr_logfile/var/log/redis/redis_err.log stdout_logfile_maxbytes50MB stdout_logfile_backups3 stderr_logfile_maxbytes50MB stderr_logfile_backups3 ; PHP‑FPM [program:phpfpm] command/usr/bin/php-fpm.exe -F autostarttrue autorestarttrue startsecs8 startretries5 exitcodes0 priority7 stopwaitsecs10 stdout_logfile/var/log/phpfpm/phpfpm_std.log stderr_logfile/var/log/phpfpm/phpfpm_err.log stdout_logfile_maxbytes50MB stdout_logfile_backups3 stderr_logfile_maxbytes50MB stderr_logfile_backups3 ; Nginx [program:nginx] command/usr/bin/nginx.exe -g daemon off; autostarttrue autorestarttrue startsecs8 startretries5 exitcodes0 priority8 stopwaitsecs10 stdout_logfile/var/log/nginx/nginx_std.log stderr_logfile/var/log/nginx/nginx_err.log stdout_logfile_maxbytes50MB stdout_logfile_backups3 stderr_logfile_maxbytes50MB stderr_logfile_backups3php-fpm.conf默认日志路径修改error_log /var/log/phpfpm/php-fpm.log5.管理 PHP 脚本进程supervisord -c /etc/supervisord.conf # 启动进程监控 supervisorctl status # 查看状态 supervisorctl restart all # 重启全部 supervisorctl stop all # 停止全部 supervisorctl start all # 启动全部 supervisorctl status # 查状态

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价