Ghost 博客升级出错无法启动修复

Ghost 博客升级出错无法启动修复

October 04, 2019
分享 ,

由于 Ghost 没有自动更新系统,并保持在最新版本的功能,所以每次升级都需要用 ssh 登陆主机执行 ghost update 指令(以前后台的 about 里是不是有一个按钮点了就能升级?我刚刚去看好像没了)。不过好在用 ghost-cli 套件升级起来到是还简单方便。

今天像往常一样执行完命令,第一次执行时提示 ghost-cli 版本过低,不过命令还是能正常执行,但是在最后 build 完库之后在 restart 的步骤忽然卡出了,起初没在意,便放在这里忙其他的去了,忙完回来后却发现升级失败,出问题的步骤就是最后的 restart 的时候,报错如下:

Debug Information:
OS: Ubuntu, v16.04
Node Version: v8.15.0
Ghost-CLI Version: 1.11.0
Environment: production
Command: 'ghost update'
Message: Could not communicate with Ghost
Suggestion: journalctl -u ghost_www-4zen-top -n 50
Stack: Error: Could not communicate with Ghost
at Server.server.close (/usr/local/lib/node_modules/ghost-cli/lib/utils/port-polling.js:56:20)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at Server.emit (events.js:208:7)
at emitCloseNT (net.js:1664:8)
at _combinedTickCallback (internal/process/next_tick.js:136:11)
at process._tickCallback (internal/process/next_tick.js:181:9)

ubuntu@VM-98-64-ubuntu:/var/www/ghost$ journalctl -u ghost_www-4zen-top -n 50
-- Logs begin at Fri 2019-10-04 11:30:25 CST, end at Fri 2019-10-04 11:40:38 CST. --
Oct 04 11:34:26 VM-98-64-ubuntu systemd[1]: Stopped Ghost systemd service for blog: www-4zen-top.
Oct 04 11:34:26 VM-98-64-ubuntu systemd[1]: Started Ghost systemd service for blog: www-4zen-top.
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: /var/www/ghost/versions/2.31.1/node_modules/knex/lib/client.js:258
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: return this.acquireRawConnection().then(async (connection) => {
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: ^
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: SyntaxError: Unexpected token (
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at createScript (vm.js:56:10)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Object.runInThisContext (vm.js:97:10)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module._compile (module.js:549:28)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Object.Module._extensions..js (module.js:586:10)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module.load (module.js:494:32)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at tryModuleLoad (module.js:453:12)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Function.Module._load (module.js:445:3)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module.require (module.js:504:17)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at require (internal/module.js:20:19)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Object. (/var/www/ghost/versions/2.31.1/node_modules/knex/lib/knex.js:2:16)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module._compile (module.js:577:32)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Object.Module._extensions..js (module.js:586:10)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module.load (module.js:494:32)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at tryModuleLoad (module.js:453:12)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Function.Module._load (module.js:445:3)
Oct 04 11:34:27 VM-98-64-ubuntu node[3469]: at Module.require (module.js:504:17)
报错信息 

之后我用 run 命令单独执行 ghost 后程序正常运行,看来程序已经正常升级,只是 systemd 保持进程时出了问题。

自己研究了一阵后无果,便想着去 github 上 发条 issue,看有没有人能帮到我 —— 很可惜,等了半小时都没有答复。

Restart after the upgrade is complete · Issue #11199 · TryGhost/Ghost
Debug Information: OS: Ubuntu, v16.04 Node Version: v8.15.0 Ghost-CLI Version: 1.11.0 Environment: production Command: 'ghost update' Message: Could not communicate with Ghost Suggestion: j...

无奈之下自己尝试了一下

  1. 在 ghost 目录下有个 system 文件夹,里面存放有 systemd 的配置文件,
  2. 把这个出错的配置文件更名
  3. 执行 ghost steup systemd 重新建立 systemd 配置文件
  4. 执行 ghost restart 指令运行程序
  5. 修复成功

虽然大概知道是配置文件的问题,但是不清楚具体因为什么原因而出错,升级过程中除了 ghost-cli 的版本过低警告外就是 npm 的版本更新提示,没出现过其他错误。

觉得很莫名其妙...。

加入评论