Node.js flightplan脚本尝试运行时失败";npm安装“;在远程机器上
我的flightplan脚本类似于:Node.js flightplan脚本尝试运行时失败";npm安装“;在远程机器上,node.js,Node.js,我的flightplan脚本类似于: // run commands on remote hosts (destinations) plan.remote(function(remote) { remote.log('Copy to remote host in folder: ' + tmpDir); remote.sudo('cp -R /tmp/' + tmpDir + ' ~', {user: username}); remote.log('Delete temporary
// run commands on remote hosts (destinations)
plan.remote(function(remote) {
remote.log('Copy to remote host in folder: ' + tmpDir);
remote.sudo('cp -R /tmp/' + tmpDir + ' ~', {user: username});
remote.log('Delete temporary local directory');
remote.rm('-rf /tmp/' + tmpDir);
remote.log('Install dependencies');
remote.exec('cd ' + tmpDir);
remote.sudo('npm --production install', {user: username});
remote.log('Reload application');
remote.sudo('ln -snf ~/' + tmpDir + ' ~/' + appName, {user: username});
});
脚本运行良好,直到遇到“npm--production install”行
以下是日志:
Copy to remote host in folder: node-app-1452386549897
104.131.12.146 $ sudo -u deploy -i bash -c 'cp -R /tmp/node-app-1452386549897 ~'
104.131.12.146 ● ok
104.131.12.146 Delete temporary local directory
104.131.12.146 $ rm -rf /tmp/node-app-1452386549897
104.131.12.146 ● ok
104.131.12.146 Install dependencies
104.131.12.146 $ cd node-app-1452386549897
104.131.12.146 ● ok
104.131.12.146 $ npm --production install
104.131.12.146 > bash: npm: command not found
failed(127)
虽然它说找不到npm命令。。该命令在远程机器上非常常见
知道是什么导致了这个问题吗
以下是部署用户(具有sudo功能)在远程计算机上的路径
以下是根用户在远程计算机上的路径:
/root/.nvm/v4.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
以下是npm的路径:
/home/deploy/.nvm/v4.2.2/bin/npm
/root/.nvm/v4.2.2/bin/npm
我分别为root和deploy安装了它刚刚在问题中找到了一个解决方案: 默认情况下,在非交互状态下执行shell时,不会加载nvm 要解决此问题,请执行以下操作: 打开
/root/.bashrc
文件,将与nvm
相关的行移到[-z“$PS1”]&&return
表达式之前
最后你会得到这样的结果:
export NVM_DIR=“/root/.NVM”
[-s“$NVM_DIR/NVM.sh”]&&。“$NVM_DIR/NVM.sh”
[-z“$PS1”]&返回
我也有同样的问题。我找到的解决方案如下所述:
我打开了我的deploy
用户的/home/deploy/.bashrc
文件,并在安装nvm后移动了位于文件末尾的行:
export NVM_DIR="/home/deploy/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
线以上:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
尝试调用
remote.exec('which npm')
和remote.sudo('which npm')代码>。可能根用户的路径中没有npm
,这是PATH为普通用户或根用户提供的任何目录中远程机器/home/deploy/.nvm/v4.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/games:/usr/local/gamesisnpm
binary上的路径?我认为npm
对于普通用户来说是可行的,但对于root用户来说不是。尝试将npm
可执行文件简单链接到/usr/bin
根用户路径:/root/.nvm/v4.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/usr/games:/usr/local/games我也有同样的问题。我可以在root用户下访问npm
,但是当flightplan
运行它时,它找不到二进制文件。看起来flightplan
正在使用不同的环境或其他东西。修好了没有?
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac