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

通过systemd启动Wiki.js服务失败问题求助

问题排查:Wiki.js通过systemd启动失败

现象概述

  • 在Putty中直接执行node server,服务器可正常启动
  • 通过systemd启动时服务报错,状态信息如下:
* wiki.service - Wiki.js

   Loaded: loaded (/etc/systemd/system/wiki.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2022-10-03 13:35:00 MSK; 5s ago
  Process: 6447 ExecStart=/usr/bin/node server (code=exited, status=0/SUCCESS)
 Main PID: 6447 (code=exited, status=0/SUCCESS)

Oct 03 13:35:00  node[6447]:     at require (internal/module.js:11:18)
Oct 03 13:35:00  node[6447]:     at Object.<anonymous> (/var/www/wiki/node_modules/fs-extra/lib/mkdirs/index.js:3:44)
Oct 03 13:35:00  node[6447]:     at Module._compile (module.js:653:30)
Oct 03 13:35:00  node[6447]:     at Object.Module._extensions..js (module.js:664:10)
Oct 03 13:35:00  node[6447]:     at Module.load (module.js:566:32)
Oct 03 13:35:00  node[6447]:     at tryModuleLoad (module.js:506:12)
Oct 03 13:35:00  node[6447]:     at Function.Module._load (module.js:498:3)
Oct 03 13:35:00  node[6447]:     at Module.require (module.js:597:17)
Oct 03 13:35:00  node[6447]: (node:6447) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise whic
Oct 03 13:35:00  node[6447]: (node:6447) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit
  • 切换到wiki用户终端执行node server,出现语法错误:
Loading configuration from /var/www/wiki/config.yml... OK
2022-10-03T10:19:40.835Z [MASTER] info: =======================================
2022-10-03T10:19:40.837Z [MASTER] info: = Wiki.js 2.5.289 =====================
2022-10-03T10:19:40.837Z [MASTER] info: =======================================
2022-10-03T10:19:40.837Z [MASTER] info: Initializing...
(node:6326) UnhandledPromiseRejectionWarning: /var/www/wiki/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
      } catch {
              ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/var/www/wiki/node_modules/fs-extra/lib/mkdirs/index.js:3:44)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
(node:6326) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6326) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

运行环境

  • Ubuntu 18.04
  • Node.js v16.17.1

排查与解决步骤

1. 核心问题定位

错误中的SyntaxError: Unexpected token {指向无参数catch语法——该语法从Node.js v10.13.0才开始支持。你全局Node.js是v16.17.1,但wiki用户或systemd服务实际调用的Node.js版本过低,才会触发这个语法错误。

2. 验证Node.js版本一致性

  • 执行which node查看当前终端的Node.js路径
  • 切换到wiki用户,执行su - wiki -c "which node"和su - wiki -c "node -v",确认版本是否为v16.17.1
  • 检查systemd服务文件/etc/systemd/system/wiki.service里的ExecStart路径,是否使用了正确的Node.js路径(比如/usr/local/bin/node而非/usr/bin/node)

3. 修复版本不一致问题

如果wiki用户或systemd使用的Node.js版本不对:

  • 编辑wiki.service文件:
    nano /etc/systemd/system/wiki.service
    
    修改ExecStart为正确的Node.js路径,并添加项目工作目录配置:
    ExecStart=/usr/local/bin/node /var/www/wiki/server
    WorkingDirectory=/var/www/wiki
    
    保存后重新加载systemd并重启服务:
    systemctl daemon-reload
    systemctl restart wiki.service
    

4. 权限检查

  • 确保wiki用户对项目目录有读写权限:
    chown -R wiki:wiki /var/www/wiki
    
  • 确认systemd服务文件已配置正确运行用户:
    在wiki.service中添加或验证:
    User=wiki
    Group=wiki
    

5. 重新安装依赖(可选)

若上述步骤无效,删除现有依赖并重新安装:

cd /var/www/wiki
rm -rf node_modules package-lock.json
su - wiki -c "npm install"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 01:20:19