Unable to run node app using systemd

半城伤御伤魂 提交于 2021-02-10 15:12:38

问题


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

And print out this message:

yarn run v1.6.0
$ babel-node index.js

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

and in start.sh I have:

cd /srv/myapp &&   NODE_ENV=production  yarn start

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'.

I have other variations on myapp.service but could not manage to run node.

What could be wrong here? How can I fix it?


回答1:


Process: 8852 ExecStart=/home/bob/start.sh (code=exited, status=203/EXEC)

According to systemd.exec(5), this means systemd could not execute the specified file:

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.

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).



来源:https://stackoverflow.com/questions/50315049/unable-to-run-node-app-using-systemd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!