【问题标题】:Why can't my css/js files be found when systemd restarts my node.js app?为什么 systemd 重新启动我的 node.js 应用程序时找不到我的 css/js 文件?
【发布时间】:2014-11-26 23:46:21
【问题描述】:

我有 node.js 应用程序,我正尝试使用 systemd 在生产模式下部署它以在服务器崩溃/重新启动时重新启动它。当我使用“node app.js”启动它时,该应用程序运行良好(即找到了我所有的公共文件)。但是,当我终止进程并 systemd 重新启动它时,Express 无法再找到我的 css/js 文件。我正在使用 connect-assets 连接我的 css/js 文件。

我认为问题出在我的节点路径上,但我并不完全确定。 这是我在 systemd 重新启动应用程序时在浏览器中看到的错误:

500 Error ...
> 11| != css('styles')
12| != js('application')
No file found for route css/styles.css

当我检查使用“node app.js”命令手动启动的进程时,我看到:

ghost   30222  6.8 17.8 140348 90848 pts/0    Sl+  18:01   0:08 node app.js

当 systemd 重新启动应用程序时,我看到以下内容:

ghost   30332  5.5  9.1  94036 46516 ?        Ssl  18:05   0:01 /usr/local/bin/node /home/ghost/myapp/app.js

这是我的服务文件:

[Service]
ExecStart=/usr/local/bin/node /home/ghost/myapp/app.js 
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=node-sample
User=ghost
Group=ghost
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

【问题讨论】:

  • 您可能希望将您的WorkingDirectory 设置为/home/ghost/myapp/
  • 是的,这似乎成功了。谢谢@Wrikken!

标签: node.js systemd connect-assets


【解决方案1】:

您需要将WorkingDirectory= 设置为您的Node 应用程序的顶级目录,无论它在哪里。

例如:

WorkingDirectory=/home/ghost/myapp

或对于全球安装的应用,

WorkingDirectory=/usr/lib/node_modules/myapp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    相关资源
    最近更新 更多