我正在使用Arch Linux上运行的旧版Raspberry Pi 1上的NodeJS(iojs)工作。 一切工作正常,但不重新启动。
我试过的:没有用户的Crontab:
crontab -e @reboot /usr/local/iojs/bin/forever start /x/y/server.js
和用户:
crontab -ux -e @reboot /usr/bin/sudo -ux -H /usr/local/iojs/bin/forever start /x/y/server.js
两个版本都是手动执行的。 我也试着用systemctrl来做到这一点:
/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
这应该执行start_service.sh:
#!/bin/sh forever start /usr/local/rest_api/server.js exit
启动它会引发错误
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
我是其中一些主题的初学者,所以我正在努力寻找错误。 其实我觉得这应该很简单。
谢谢你,马提亚斯
如果有些人仍然感兴趣,这完美的作品:
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中了解它的工作方式。
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