简体   繁体   English

在Raspbian上通过rc.local运行Node JS

[英]Run Node JS via rc.local on Raspbian

I want to have a node js file start on bootup. 我想在启动时启动一个节点js文件。

I'm using /etc/rc.local. 我正在使用/etc/rc.local。 Here is the contents: 这里是内容:

su pi -c '/opt/node/bin/node /home/pi/repos/spacebrew/node_server_forever.js < /dev/null &'

Here is the error on startup: 这是启动时的错误:

Error: Target script does not exist: node_server.js
at /home/pi/node_modules/forever-monitor/lib/forever-monitor/monitor.js:144:26
at process._tickCallback (node.js:415:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3

Originally my command was just 'node' rather than the path to node but this gave me 'node command not found' 最初,我的命令只是“节点”,而不是到节点的路径,但这给了我“找不到节点命令”

I don't understand why 我不明白为什么

node /home/pi/repos/spacebrew/node_server_forever.js

works from terminal but not in rc.local. 从终端工作,但不在rc.local中。 I'd like to know the easiest way to get this server automatically up and running on reboot. 我想知道最简单的方法来使该服务器自动启动并在重新启动时运行。 Thanks. 谢谢。

node node_server_forever.js 

... works when called from ssh terminal. ...从ssh终端调用时有效。 However, I don't understand why because when called from rc.local there is an issue finding the forever-monitor. 但是,我不明白为什么,因为从rc.local调用时,找到永久监控器存在问题。

There is another file included in the spacebrew folder called simply node_server.js. spacebrew文件夹中包含另一个文件,简称为node_server.js。 Calling this file instead of it's 'forever' counterpart works as intended. 调用此文件而不是它的“永久”对应文件将按预期工作。

su pi -c '/opt/node/bin/node /home/pi/repos/spacebrew/node_server.js < /dev/null &'

This solves my issue of getting the server running but I am still confused why there are so many path issues running files from cron and rc.local. 这解决了我让服务器运行的问题,但是我仍然感到困惑,为什么从cron和rc.local运行文件的路径问题如此之多。 If someone could explain that to me I would really appreciate it. 如果有人可以向我解释这一点,我将非常感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM