Homebrew服务无法启动,出现"Bootstrap failed: 5: Input/output error"错误。

120

运行brew services start mongodb-community会产生以下结果:

Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/<myUserName>/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.

当我运行 launchctl load -w /Users/<myUserName>/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

时,出现以下提示:

Load failed: 5: Input/output error

我最近将macOS升级到BigSur 11.5.2。

我已卸载并重新安装了homebrew和xcode。


1
没有将这个作为答案添加,因为它不是我的。这对我起作用了。 - Harsh Kumar
1
我已经尝试过这个,但仍然遇到相同的错误。我想知道是否使用命令给出了正确的输入?Brew服务应该可以正常工作,因为这是MongoDB官方启动服务的方式。 - dasqueel
谢谢 @HarshKumar,这个链接救了我的一天! - undefined
18个回答

132

试试这个

brew services restart <mongodb-community@4.4>


3
令人惊讶的是,它起作用了。谢谢Mari! - andreybleme
10
仍然存在同样的问题。 - Bjørson Bjørson
1
在我从Mac Intel迁移到M1后,这对我起作用了。谢谢! - i-know-nothing
17
它能够工作,但为什么呢? - Adam Fowler
适用于我,所以我只需要具体说明版本号。 - jpcaparas
显示剩余6条评论

48

我遇到了MySQL的这个问题,解决方法是我的当前配置文件不是homebrew目录的所有者。

因为我有第二个配置文件用于另一个工作空间,但它们共享相同的homebrew路径,所以我必须更改它。

我建议任何看到这个错误的人尝试运行

sudo chown -R $(whoami) $(brew --prefix)/*

然后尝试看看是否能解决它。再次强调,我在使用MongoDB时没有遇到这个问题,但是当我的配置文件没有拥有brew文件夹时,我在使用MySQL时看到了这个确切的错误。


1
在探索了几个选项后,这似乎是我最有可能的解决方案。与此同时,我使用 sudo brew servies start postgresql 成功启动了postgresql。 - Alex Booker
1
有些服务器如apache需要以root身份运行,才能绑定到正确的端口。如果您在非系统受保护的端口上进行绑定,则可能会获得更好的运行结果。我的nginx服务器在我的非特权用户下正常运行。事实上,使用sudo可能是启动httpd的唯一方法。有趣的是,如果您使用和不使用sudo查看sudo brew services list,可能会出现似乎是错误的假阳性。这个完整的反馈是很有启发性的。 - Richard Tyler Miles
1
值得链接为什么和如何apache这样做,以了解安全考虑。 - Richard Tyler Miles
1
谢谢。我尝试了几种方法,但都不起作用。这个更新完美地工作了。谢谢。 - Long Tran
1
这似乎停止了终端输出的所有无意义内容,谢谢! - Purple_Kitten
显示剩余4条评论

40

我可以通过Homebrew来运行MongoDB,我相信这解决了我的问题:

接下来执行:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

然后执行:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist


1
这解决了我遇到的问题。 - Adam Reis
这样就解决了,而不必强制使用版本4.4——很好! - snooze92
当防火墙阻止Java服务器启动时,此方法有效。一旦您卸载并重新加载,您将看到一个操作系统提示,允许Java连接。一旦接受,服务器就可以正常启动了。 - mpprdev

18

如果您尝试过重新启动您的服务,但它仍然无法工作,请尝试以下方法:

  1. 停止您的服务
brew services stop mongodb-community
  1. 重新启动您的 macOS
  2. 再次启动您的服务
brew services start mongodb-community

15

要查看真正的错误,您需要在没有brew的情况下运行服务

我遇到了类似的问题,但与mongodb不同的是,我无法启动apache(httpd)。

$ brew services start httpd                                                                                                                                                        
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 
/Users/john/Library/LaunchAgents/homebrew.mxcl.httpd.plist` exited with 
5.
FAIL: 1

不幸的是,brew无法向用户展示导致此错误的原因。起初我尝试使用此线程中答案中的提示,但重新安装apache或使用卸载-w /加载-w都没有帮助。

我在brew日志中也没有发现任何信息。我决定调查apache本身。为此,我运行了未经brew处理的apache:

$ /opt/homebrew/Cellar/httpd/2.4.51/bin/apachectl start
httpd: Syntax error on line 66 of /opt/homebrew/etc/httpd/httpd.conf: Cannot load /opt/homebrew/Cellar/php@5.6/5.6.40_3/lib/httpd/modules/libphp5.so into server: dlopen(/opt/homebrew/Cellar/php@5.6/5.6.40_3/lib/httpd/modules/libphp5.so, 0x000A): tried: '/opt/homebrew/Cellar/php@5.6/5.6.40_3/lib/httpd/modules/libphp5.so' (no such file), '/usr/local/lib/libphp5.so' (no such file), '/usr/lib/libphp5.so' (no such file)
FAIL: 1

最后终于清楚了httpd服务无法启动的原因。原来在php升级后,php版本已经改变而我忘记在apache配置文件中写入新的php版本。 我很快解决了这个问题,apache启动了。


3
这是一个好的提示;它对我有用。 - mr.cook
1
很好的提示,但是提醒其他人:只在调试时使用。Brew会自动为您执行一些操作(例如设置ulimit值),因此您需要知道自己在做什么。 - Tim Rasim
获取实际错误的好方法 - Huupke

10

我遇到了与postgresql 11类似的问题,重新启动服务也没有帮助。这个问题出现在我的MacBook突然重新启动时。

在检查端口并尝试了所有可能的解决方案后,我决定查看日志。

tail -n 100 /usr/local/var/log/postgresql@11.log

这给了我日志的最后100行,我在其中找到了这个:
FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 479) running in data directory "/usr/local/var/postgresql@11"?

显然,问题出在 postmaster.pid 文件上,所以我将其删除:

rm /usr/local/var/postgresql@11/postmaster.pid

重新启动了Postgres服务:
brew services start postgresql@11

瞧!它奏效了。


7

看起来 mongodb-community 已经启动了。因此,请使用以下命令重新启动它,而不是启动:

brew services restart mongodb-community

6

我曾经遇到过类似的错误,与postgres有关。

$ brew services start postgresql
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/yrk/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5.

我尝试过重新启动它,看起来很有希望:

$ brew services restart postgres
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

但是在尝试连接时仍然存在问题:

 $ psql -d postgres -U apiuser
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?

根据 @mansoor.khan 提到的方法检查 postgres 日志对我有帮助,在我的情况下是:

tail /usr/local/var/log/postgres.log

问题变得清晰明了:

$ tail /usr/local/var/log/postgres.log
2022-05-19 14:18:46.029 CEST [32374] FATAL:  database files are incompatible with server
2022-05-19 14:18:46.029 CEST [32374] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:18:56.071 CEST [32676] FATAL:  database files are incompatible with server
2022-05-19 14:18:56.071 CEST [32676] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:06.111 CEST [32885] FATAL:  database files are incompatible with server
2022-05-19 14:19:06.111 CEST [32885] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:16.128 CEST [33102] FATAL:  database files are incompatible with server
2022-05-19 14:19:16.128 CEST [33102] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.
2022-05-19 14:19:26.166 CEST [33434] FATAL:  database files are incompatible with server
2022-05-19 14:19:26.166 CEST [33434] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.3.

现在的问题是:如何还原到以前的版本,或将旧数据升级到新的Postgres DB版本,但这是另一个话题。

1
brew postgresql-upgrade-database 是为此目的而设计的。 - Joe Atzberger

2
重新启动
我是说重新启动电脑。
我尝试了这里写的所有方法,包括卸载和重新安装Mongo本身。经过一番努力,不知怎么地,重新启动电脑解决了我的问题。

1

我在mysql上遇到了类似的问题。

Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/gerd/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.

在我的情况下,mysqld缺少osx网络连接权限。重新启动OSX后,出现了网络权限对话框。我授予了msqld权限,问题得到了解决!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接