在Mac系统中使用brew services启动nginx服务时,出现了Bootstrap failed: 5: Input/output error报错,具体报错信息如下:
brew services start nginx
Bootstrap failed: 5: Input/output error
1. 查看nginx的plist文件获取程序路径
通过编辑nginx的plist配置文件,能获取到nginx的应用程序具体路径,执行以下命令打开配置文件:
vi ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
plist文件内的配置内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.nginx</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/nginx/bin/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>
从配置中可得到nginx的应用程序路径为:/usr/local/opt/nginx/bin/nginx
2. 直接启动nginx定位具体问题
执行获取到的nginx程序路径,直接启动nginx服务,执行命令:
/usr/local/opt/nginx/bin/nginx
启动后出现新的报错,能明确问题根源为nginx所需的8080端口被占用,具体报错信息:
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] still could not bind()
3. 查看8080端口的占用情况
执行以下命令,查询当前占用8080端口的进程信息:
lsof -i:8080
查询结果显示有多个进程占用了8080端口。
4. 释放端口并重新启动nginx服务
先停止当前的nginx服务,再重新启动,执行以下命令:
# 先停止
brew services stop nginx
# 再重启
brew services start nginx
执行完成后,nginx服务成功启动,brew services启动报错问题解决。
