无法使用 systemd 运行节点应用程序 [英] Unable to run node app using systemd
问题描述
这将是我的第一个节点部署.我有这个应用程序,它使用以下命令在我的 Debian 9 服务器上运行良好:
This going to be my first node deployment. I have this app which runs fine on my Debian 9 server using this command:
cd /srv/myapp && NODE_ENV=production yarn start
并打印出这条消息:
yarn run v1.6.0
$ babel-node index.js
为了使用 systemd 妖魔化应用程序,我创建了 `/lib/systemd/system/myapp.service:
In order to demonize the app using systemd, I created `/lib/systemd/system/myapp.service:
[Unit]
Description=Myapp
[Service]
ExecStart=/home/john/start.sh
Type=simple
User=john
Restart=on-failure
[Install]
WantedBy=multi-user.target
在 start.sh
中我有:
cd /srv/myapp && NODE_ENV=production yarn start
然而,当我运行 systemctl start myapp
时,节点应用程序并没有像预期的那样开始侦听端口 3000 (netstat -tulpn | grep :3000
没有返回结果)
Hoewever, when I run systemctl start myapp
the node app does not start to listen on port 3000, as expected (netstat -tulpn | grep :3000
returns no results)
# systemctl status myapp
● myapp.service - Myapp
Loaded: loaded (/lib/systemd/system/myapp.service; disabled; vendor preset: enabled
Active: failed (Result: exit-code) since Sun 2018-05-13 06:14:04 EDT; 5s ago
Process: 8852 ExecStart=/home/bob/start.sh (code=exited, status=203/EXEC)
Main PID: 8852 (code=exited, status=203/EXEC)
May 13 06:14:04 9606 systemd[1]: myapp.service: Unit entered failed state.
May 13 06:14:04 9606 systemd[1]: myapp.service: Failed with result 'exit-code'.
May 13 06:14:04 9606 systemd[1]: myapp.service: Service hold-off time over, scheduling
May 13 06:14:04 9606 systemd[1]: Stopped myapp.
May 13 06:14:04 9606 systemd[1]: myapp.service: Start request repeated too quickly.
May 13 06:14:04 9606 systemd[1]: Failed to start myapp.
May 13 06:14:04 9606 systemd[1]: myapp.service: Unit entered failed state.
May 13 06:14:04 9606 systemd[1]: myapp.service: Failed with result 'exit-code'.
我对 myapp.service 有其他变体,但无法运行节点.
I have other variations on myapp.service but could not manage to run node.
这里有什么问题?我该如何解决?
What could be wrong here? How can I fix it?
推荐答案
Process: 8852 ExecStart=/home/bob/start.sh (code=exited, status=203/EXEC)
根据 systemd.exec
(5),这意味着systemd
无法执行指定的文件:
According to systemd.exec
(5), this means systemd
could not execute the specified file:
203 EXIT_EXEC 实际进程执行失败(特别是 execve(2) 系统调用).这很可能是由丢失或不可访问的可执行文件引起的.
203 EXIT_EXEC The actual process execution failed (specifically, the execve(2) system call). Most likely this is caused by a missing or non-accessible executable file.
您应该检查 /home/bob/start.sh
是否可执行并指定了正确的shebang(也就是说,您的脚本的第一行必须是 #!/bin/bash
).
You should check if /home/bob/start.sh
is executable and has correct shebang specified (that is, the first line of your script must be #!/bin/bash
).
这篇关于无法使用 systemd 运行节点应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!