基本上,每次我想将更改推到我的服务器时,我都会遍历这个工作流。
node app.js
//if above not crashed
git push heroku <branchname>
git push origin <branchname>我想写一个脚本,为我完成所有这一切。如果运行节点app.js崩溃,我需要在脚本中显示。我该怎么做?
编辑:
Sam下面的答案检测节点是否崩溃,但如果没有,则会继续运行。我想我想要的是:开始节点。等三十几岁。如果仍在运行,则继续执行脚本的其余部分
发布于 2015-03-20 15:23:29
取决于您所说的“崩溃”指的是什么,但是如果节点进程出现错误,您应该有一个非零的退出代码,您可以在脚本中测试:
#!/bin/bash
node app.js
if [ $? != 0 ] 
then
   echo "app.js failed; exiting"
   exit 1
fi
git push heroku branchname
# etc.如果还想检测node终止时没有错误,但脚本app.js有错误的情况,请确保使用非零代码进行process.exit(code)。
发布于 2015-03-20 16:04:26
我不认为节点会自动在后台启动,所以:
node app.js &
node_pid=$!
sleep 30
if kill -0 $node_pid 2>/dev/null; then
    # still running
    git push heroku $branchname
    git push origin $branchname
fi发送一个进程-- 0信号--是查看它是否还活着的一种方便的方法。
https://stackoverflow.com/questions/29169980
复制相似问题