尝试为运行在端口3000上的nodejs应用创建启动脚本。
问题:node-app.server脚本不起作用,我认为这是因为
ExecStart
路径错误。 当我在Chrome中转到服务器IP时,没有任何显示。
该节点应用是使用npm generator创建的,我通常使用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
我的应用程序在/home/ubuntu/twitter-server
的Ubuntu 18上运行。如果是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#
答案 0 :(得分:0)
您的服务配置有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'
答案 1 :(得分:0)
我建议将此软件包(service-systemd)用于简单程序
有时,您只需要一个“旧式”守护程序来进行简单服务。 有时,您必须在小型设备(例如RaspberryPi)中进行部署,而不能使用Docker和所有频段。