运行OpenShift节点服务器:获取错误应用程序“appname”无法启动(端口8080不可用)

时间:2016-07-02 19:38:22

标签: javascript node.js git openshift

我正在尝试为我正在开发的游戏运行服务器。我运行Application 'appname' failed to start (port 8080 not available)时收到错误$git push。 (之前我运行了git add和git commit)。这是我的服务器代码:`

//Lets require/import the HTTP module
var http = require('http');
//var fs = require("fs");
//var index = fs.readFileSync('test.txt');

//Lets define a port we want to listen to
const PORT=8081; 

//We need a function which handles requests and send response
function handleRequest(request, response){
    response.end("hi");
}

//Create a server
var server = http.createServer(handleRequest);

//Lets start our server
server.listen(PORT, "127.0.0.1",function(){
    //Callback triggered when server is successfully listening.
    console.log("Server listening on: http://localhost:%s", PORT);
});

根据我所做的研究,如果您的代码出现错误,您将收到端口不可用错误,但我已经测试过在我的计算机上本地运行应用程序,并且运行正常(我能够连接我看到消息“嗨”)。我之所以注释掉文件系统(fs)的原因是因为我想测试问题是因为OpenShift应用程序没有安装fs(事实并非如此)。我也试过运行一个完全空的服务器,但我仍然得到相同的错误。因此,我认为问题不在于任何缺失的包裹。我已经检查过端口8080上是否有东西在运行,但是我没有看到任何东西。

的package.json:

{
  "name": "OpenShift-Sample-App",
  "version": "1.0.0",
  "description": "OpenShift Sample Application",
  "keywords": [
    "OpenShift",
    "Node.js",
    "application",
    "openshift"
  ],
  "author": {
    "name": "OpenShift",
    "email": "ramr@example.org",
    "url": "http://www.openshift.com/"
  },
  "homepage": "http://www.openshift.com/",
  "repository": {
    "type": "git",
    "url": "https://github.com/openshift/origin-server"
  },

  "engines": {
    "node": ">= 0.6.0",
    "npm": ">= 1.0.0"
  },

  "dependencies": {
    "express": "~3.4.4"
  },
    "scripts": {
     "start": "node htmlServer.js"
  },
  "devDependencies": {},
  "bundleDependencies": [],
  "private": true,
  "main": "htmlServer.js"
}

错误日志:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Stopping NodeJS cartridge
remote: Sat Jul 02 2016 14:17:48 GMT-0400 (EDT): Stopping application 'griffinsmod' ...
remote: Sat Jul 02 2016 14:17:49 GMT-0400 (EDT): Stopped Node application 'griffinsmod'
remote: Saving away previously installed Node modules
remote: Building git ref 'master', commit 07b3114
remote: Building NodeJS cartridge
remote: npm info it worked if it ends with ok
remote: npm info using npm@1.4.28
remote: npm info using node@v0.10.35
remote: npm info preinstall OpenShift-Sample-App@1.0.0
remote: npm info build /var/lib/openshift/5777be422d5271bc8b00018f/app-root/runtime/repo
remote: npm info linkStuff OpenShift-Sample-App@1.0.0
remote: npm info install OpenShift-Sample-App@1.0.0
remote: npm info postinstall OpenShift-Sample-App@1.0.0
remote: npm info prepublish OpenShift-Sample-App@1.0.0
remote: npm info ok 
remote: Preparing build for deployment
remote: Deployment id is 6f6c7880
remote: Activating deployment
remote: Starting NodeJS cartridge
remote: Sat Jul 02 2016 14:18:15 GMT-0400 (EDT): Starting application 'griffinsmod' ...
remote: Waiting for application port (8080) become available ...
remote: Application 'griffinsmod' failed to start (port 8080 not available)
remote: -------------------------
remote: Git Post-Receive Result: failure
remote: Activation status: failure
remote: Activation failed for the following gears:
remote: 5777be422d5271bc8b00018f (Error activating gear: CLIENT_ERROR: Failed to execute: 'control start' for /var/lib/openshift/5777be422d5271bc8b00018f/nodejs
remote: #<IO:0x000000011ac290>
remote: #<IO:0x000000011ac218>
remote: )
remote: Deployment completed with status: failure
remote: postreceive failed
To ssh://5777be422d5271bc8b00018f@griffinsmod-snowballdynamics.rhcloud.com/~/git/griffinsmod.git/
   a2fb4f6..07b3114  master -> master

我没有真正关心审查任何信息,我希望没有人因为错误日志而破解任何东西,对不起,如果这个问题很长...也很抱歉,如果这听起来很无聊,我开始使用OpenShift和GitHub昨天。如果您有任何疑问或想要其他信息只需评论!我非常感谢能得到的任何帮助! :)

1 个答案:

答案 0 :(得分:0)

标准的Openshift Node.js磁带为您提供了应该使用环境变量监听的端口和IP。

我会使用类似的东西,因为PORTIP是更常见的方法,如果没有提供任何内容(开发环境),它会立即收听:

const PORT = process.env.OPENSHIFT_NODEJS_PORT ||process.env.PORT || 8080;
const IP = process.env.OPENSHIFT_NODEJS_IP || process.env.IP || '0.0.0.0';