NodeJS永远不会在启动时工作

时间:2015-09-16 20:36:06

标签: linux node.js archlinux reboot forever

我正在使用在Arch Linux上运行的旧Raspberry Pi 1上使用NodeJS(iojs)的Rest Service。一切正常,但不是重启。

我尝试了什么: 没有用户的Crontab:

crontab -u x -e
@reboot /usr/bin/sudo -u x -H /usr/local/iojs/bin/forever start /x/y/server.js

并与用户:

/etc/systemd/system/rest_api.service
[Unit]
Description=Rest Api

[Service]
ExecStart=/x/y/rest_api/start_service.sh
Restart=always

[Install]
WantedBy=multi-user.target

两个版本都可以手动执行。 我也试过用systemctrl做到这一点:

#!/bin/sh
forever start /usr/local/rest_api/server.js
exit

这应该执行start_service.sh:

systemctl start rest_api
Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)
Failed to start rest_api.service: Connection timed out

启动它会抛出错误

authorNames = authors |> Enum.map(fn a-> a.name end)

我是其中一些主题的初学者,因此我很难找到错误。其实我认为这应该很简单。

谢谢你, 的Matthias

2 个答案:

答案 0 :(得分:1)

如果有些人仍然感兴趣,这很有效:

1)npm install forever -g && npm install forever-service -g

2)将您的js脚本重命名为 app.js ,使用 cd 转到其位置并输入:

forever-service install myService

3)在 /etc/rc.local 中添加以下行:

sudo service myService start

我希望它会有所帮助!

答案 1 :(得分:0)

我遇到了同样的问题。在上面的场景#1中使用了它的方式。

sudo crontab -e
#added this to the bottom
@reboot /usr/bin/sudo -u pi -H /usr/local/bin/forever start /home/pi/server.js

我认为它起初并没有起作用,但在重新启动后我在运行前5分钟给它一个稳定的:

forever list

它出现了:

info:    Forever processes running
data:        uid  command             script                                       forever pid  id logfile                    uptime
data:    [0] L8AA /usr/local/bin/node /home/pi/server.js 3086    3108    /home/pi/.forever/L8AA.log 0:0:12:21.877
相关问题