新贵 node.js 工作目录 [英] Upstart node.js working directory
本文介绍了新贵 node.js 工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Upstart 启动 Node.js,当尝试访问 Node.js 中的文件时,它无法在不使用完整路径的情况下访问它们.我需要它来使用工作目录.
Starting Node.js with Upstart, when trying to access files within Node.js it cannot access them without using the full path. I need it to use the working directory.
start on startup
stop on shutdown
script
echo $$ > /var/run/mynodeapp.pid
exec sudo -u mynodeapp node server.js >> /var/log/mynodeapp.sys.log 2>&1
end script
pre-start script
echo "Starting" >> /var/log/mynodeapp.sys.log
end script
pre-stop script
rm /var/run/mynodeapp.pid
echo "Stopping" >> /var/log/mynodeapp.sys.log
end script
推荐答案
解决方案是更改脚本内的目录.就我而言,用户是 mynodeapp,节点文件位于用户目录 (/home/mynodeapp/) 中.
The solution is to change directory within the script. In my case, the user is mynodeapp and the node files are in the users directory (/home/mynodeapp/).
script
chdir /home/mynodeapp/
echo $$ > /var/run/mynodeapp.pid
exec sudo -u mynodeapp node server.js >> /var/log/mynodeapp.sys.log 2>&1
end script
我还没有弄清楚 $$ 在 echo 行或 2>&1 上的含义.如果他们知道的话,也许有人会同意这个!
I have yet to find out what $$ means on the echo line or 2>&1. Maybe somebody could chime in with this if they know!
这篇关于新贵 node.js 工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文