我正在尝试在生产中设置 node.js 脚本(Balloons.IO)。我已经永远安装了,但是任何时候服务器重新启动forever list
命令都会返回info: No forever processes running
第二个问题,我已经将此脚本设置为在 iptables 不允许的端口 9090 下运行。为了解决这个其他问题,我必须运行一个 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