我通過永遠啓動我的nodejs應用程序使用這個upstart腳本,它工作正常。問題是,當應用程序以編程方式創建文件夾時,它會在根目錄上創建;如何爲永久啓動的nodejs應用程序設置正確的路徑
/公/ newfolder,而不是在/ var/WWW/nodeapp /公/ newfolder。
這裏是我的upstar文件myapp.conf:
#!upstart
#
description "Example upstart script for a Node.js process"
start on startup
stop on shutdown
expect fork
env NODE_BIN_DIR="/usr/bin"
env NODE_PATH="/usr/lib/node_modules"
env APPLICATION_PATH="/var/www/nodeapp/app.js"
env PIDFILE="/var/run/myapp.pid"
env LOG="/var/log/myapp.log"
env MIN_UPTIME="5000"
env SPIN_SLEEP_TIME="2000"
script
# Add the node executables to the path, which includes Forever if it is
# installed globally, which it should be.
PATH=$NODE_BIN_DIR:$PATH
exec forever \
--pidFile $PIDFILE \
-a \
-l $LOG \
--minUptime $MIN_UPTIME \
--spinSleepTime $SPIN_SLEEP_TIME \
start $APPLICATION_PATH
end script
pre-stop script
# Add the node executables to the path.
PATH=$NODE_BIN_DIR:$PATH
exec forever stop $APPLICATION_PATH
end script
和創建文件夾的api.js:
newFolder = "public/"+folder_ID; //relative path for new folder
var mkdirp = require('mkdirp');
mkdirp(newFolder, function(err) {
if (err){
console.log('error');
}else{
console.log('new folder');
}
});
我希望你能幫助我,謝謝。
非常感謝。 --workingDir選項解決了我的問題。 – 2015-02-12 16:05:36
不客氣!考慮接受這個答案,如果它解決了你的問題。 – 2015-02-12 17:28:19