使用Forever运行nodejs脚本时出现问题

时间:2013-03-05 01:11:18

标签: node.js shell crontab iptables forever

我正在尝试在生产中设置node.js脚本(Balloons.IO)。我已经永远安装,但是任何时候服务器重启forever list命令都返回info: No forever processes running第二个问题我已经设置了这个脚本在端口9090下运行,这是iptables不允许的。为了解决这个问题,我要运行一个IPTABLES命令接受到端口9090的传入连接,IPTABLES保持这个配置直到服务器重启...简而言之,很多问题只是为了启动node.js脚本并保持运行

要修复所有这些,我将此命令添加到crontab:

* * * * * /home/steph/scripts/script-check.sh >> /home/steph/scripts/startup.log

启动了cron作业,但任何想法为什么startup.log包含下面的输出?

Mon Mar  4 20:04:01 EST 2013
REDIS: [OFFLINE] Starting Redis Server...[FAILED]
BALLOONS.IO: [OFFLINE] Starting Balloons.IO (with Forever)...[FAILED]
FIREWALL (port 9090): [DENIED] Enabling port 9090...
[FAILED]

当我手动运行script-check.sh时,linux产生:

Mon Mar  4 20:06:38 EST 2013
REDIS: [ONLINE]
BALLOONS.IO: [OFFLINE] Starting Balloons.IO (with Forever)...[SUCCESS]
FIREWALL (port 9090): [ACCEPT]

以下是script-check.sh内容:

echo -ne "$(date)\n";
echo -ne  "REDIS: ";
if [ "`redis-cli ping | grep -i pong`" ]
then
        echo -ne "[ONLINE]\n";
else
        echo -ne "[OFFLINE] Starting Redis Server...";
        echo -ne `/etc/init.d/redis_6379 start > /home/steph/stat_redis.log`;
        if [ "`redis-cli ping | grep -i pong`" ]
        then
                echo -ne "[SUCCESS]\n";
        else
                echo -ne "[FAILED]\n";
        fi
fi

echo -ne "BALLOONS.IO: ";
if [ "`forever list | grep -i balloons`" ]
then
        echo -ne "[ONLINE]\n";
else
        echo -ne "[OFFLINE] Starting Balloons.IO (with Forever)...";
        echo -ne `forever start /home/steph/Balloons.IO/balloons.js > /home/steph/stat_balloons.log`;
        if [ "`forever list | grep -i balloons`" ]
        then
                echo -ne "[SUCCESS]\n";
        else
                echo -ne "[FAILED]\n";
        fi
fi

echo -ne "FIREWALL (port 9090): ";
if [ "`iptables-save | grep -- "-A INPUT -p tcp -m tcp --dport 9090 -j ACCEPT"`" ]
then
        echo -ne "[ACCEPT]\n";
else
        echo -ne "[DENIED] Enabling port 9090...";
        echo `iptables -A INPUT -p tcp -m tcp --dport 9090 -j ACCEPT > /home/steph/stat_iptables.log`
        if [ "`iptables-save | grep -- "-A INPUT -p tcp -m tcp --dport 9090 -j ACCEPT"`" ]
        then
                echo -ne  "[SUCCESS]\n";
        else
                echo -ne "[FAILED]\n";
        fi
fi

0 个答案:

没有答案