You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rails 7.0.4部署时puma:restart报错服务未找到,疑与--user参数有关

解决Capistrano部署Puma服务重启时的"Unit not found"问题

问题背景

  • 环境:Rails 7.0.4、Puma 6.0
  • 执行bundle exec cap production deploy部署生产环境时,卡在puma:restart步骤
  • 服务器上R7-reporting-2022_puma_production.service服务正常运行,但Capistrano用systemctl --user restart ...执行时报错:Unit R7-reporting-2022_puma_production.service not found
  • 直接在服务器执行systemctl restart R7-reporting-2022_puma_production.service(不带--user参数)能成功完成重启

修复方案

修改Capistrano的Puma配置,让它使用系统级的systemctl命令,而非用户级的。

操作步骤

  1. 打开项目中的config/deploy.rb或者config/deploy/production.rb配置文件

  2. 添加或更新以下配置项:

    set :puma_systemctl_user, :system
    

    这个配置会告诉Capistrano的Puma插件,调用系统级的systemctl命令,不再附加--user参数。

  3. 重新执行部署命令bundle exec cap production deploy,puma:restart步骤就能正常完成。

原因说明

  • systemctl --user用于管理当前用户专属的systemd服务,这类服务的配置文件通常存放在用户目录下(比如~/.config/systemd/user/)
  • 你的R7-reporting-2022_puma_production.service是系统级服务(配置文件在/etc/systemd/system/目录),所以用--user参数找不到对应的服务单元
  • 把puma_systemctl_user设为:system后,Capistrano会执行不带--user的systemctl restart命令,匹配你的服务类型,自然就能找到并重启服务了

内容的提问来源于stack exchange,提问作者prodigerati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 16:56:03