node.js - NODE APP:Systemd 启动脚本不起作用?
问题描述
尝试为在端口 3000 上运行的 nodejs 应用程序创建启动脚本。
问题:node-app.server 脚本不起作用,我认为这是因为
ExecStart
路径错误。当我在 Chrome 中访问服务器 IP 时,什么都没有显示。
节点应用程序是使用 npm 生成器创建的,我通常使用它npm start
来启动应用程序。我在这里添加了 bin/wwww 的路径:
[Unit]
Description=tweetMonster twtiter server - making your environment variables rad
Documentation=https://example.com
After=network.target
[Service]
Environment=NODE_PORT=3000
Type=simple
User=ubuntu
ExecStart=/home/ubuntu/twitter-server/bin/www.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
我的应用程序在 Ubuntu 18 上运行/home/ubuntu/twitter-server
。如果这样做ls
:
/twitter-server$ ls
app.js node_modules package.json routes
bin package-lock.json public views
请帮忙!
错误终端:
Nov 01 05:40:25 ip-172-31-22-207 systemd[1]: node-app.service: Main process exited, code=exited, status=203/EXEC
Nov 01 05:40:25 ip-172-31-22-207 systemd[1]: node-app.service: Failed with result 'exit-code'.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: node-app.service: Service hold-off time over, scheduling restart.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: node-app.service: Scheduled restart job, restart counter is at 5.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: Stopped hello_env.js - making your environment variables rad.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: node-app.service: Start request repeated too quickly.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: node-app.service: Failed with result 'exit-code'.
Nov 01 05:40:26 ip-172-31-22-207 systemd[1]: Failed to start hello_env.js - making your environment variables rad.
Nov 01 06:20:11 ip-172-31-22-207 systemd[1]: /etc/systemd/system/node-app.service:10: Executable path is not absolute: "node /home/ubuntu/twitter-server/bin/www.js"
Nov 01 06:24:35 ip-172-31-22-207 systemd[1]: /etc/systemd/system/node-app.service:10: Executable path is not absolute: "node /home/ubuntu/twitter-server/bin/www.js"
root@ip-172-31-22-207:/etc/systemd/system#
解决方案
您的服务配置有 2 个问题。
首先,Environment
用双引号将 的值括起来:
Environment="NODE_PORT=3000"
第二,
您需要使用 node
来运行ExecStart
脚本。/home/ubuntu/twitter-server/bin/www.js
本身不是命令。
做,
ExecStart=/bin/bash -c '$$(which node) /home/ubuntu/twitter-server/bin/www.js'
推荐阅读
- pine-script - 一旦收盘价高于之前的高点就尝试买入
- google-sheets - 根据第一个单元格提取多行
- core-location - 地理围栏和 startMonitoringSignificantLocationChanges 在请勿打扰模式下没有响应
- c++ - Matlab C++集成,什么是libting?
- sql-server - 如何在动态数据透视中使用 NULL 值进行 GROUP BY
- bash - devspace enter 命令只是返回 [fatal] 未知标志:--omit
- php - 在构建或管理网页面板上找不到 Orocommerce 捆绑主题
- amazon-web-services - ECS 没有足够的空闲数据块用于 docker 镜像。如何提供足够的卷/存储?
- javascript - WebAssembly:worker.js onmessage() 捕获了一个未捕获的异常:NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope'
- asp.net - 使用 3 个表 LINQ .NET 中的 Include