How port is reused by multiple node application process - node.js

When I run the same application which uses os port multiple times in java application(example ) I get below exception.
Exception in thread "main" java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
node_cluster.js
const cluster = require('cluster'),
cpus = require('os').cpus().length;
cluster.setupMaster({
exec: '3_worker.js'
});
if(cluster.isMaster) {
for(let i = 0; i< cpus; i++) {
cluster.fork();
}
cluster.on('fork', worker => console.log(worker.id + " is forked"));
cluster.on('listening', (worker, address) => console.log(worker.id + "is listening on " + JSON.stringify(address)));
cluster.on('online', worker => console.log(`${worker.id} is online`));
cluster.on('disconnect', worker => console.log(`${worker.id} is disconnected`));
cluster.on('exit', (worker, code, signal) => console.log(`${worker.id} is dead due to ${code} and ${signal}`));
}
3_worker.js
const http = require('http');
http.createServer((req, res) => {
console.log(req.url);
res.writeHead(200);
res.end('hello');
}).listen(8080);
The above programs return result -
3is listening on {"addressType":4,"address":null,"port":8080}
5is listening on {"addressType":4,"address":null,"port":8080}
4is listening on {"addressType":4,"address":null,"port":8080}
7is listening on {"addressType":4,"address":null,"port":8080}
8is listening on {"addressType":4,"address":null,"port":8080}
2is listening on {"addressType":4,"address":null,"port":8080}
1is listening on {"addressType":4,"address":null,"port":8080}
6is listening on {"addressType":4,"address":null,"port":8080}
The output of ps is -
$ ps
PID TTY TIME CMD
4477 ttys001 0:00.16 /bin/bash -l
5219 ttys001 0:00.12 node 3_clustering.js
5220 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5221 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5222 ttys001 0:00.13 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5223 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5224 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5225 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5226 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5227 ttys001 0:00.14 /Users/rajkumar.natarajan/.nvm/versions/node/v8.15.0/b
5794 ttys002 0:00.05 /bin/bash --rcfile /Applications/IntelliJ IDEA.app/Con
6063 ttys003 0:00.03 /Applications/Utilities/iTerm.app/Contents/MacOS/iTerm
6065 ttys003 0:00.04 -bash
How multiple node.js process are able to listen on same port.

Only the master has the port opened. It handles all incoming and outgoing traffic on the port and offloads the traffic to the worker threads for processing.

Related

Not able to access files in hadoop cluster

I was trying to read the file present in hadoop cluster through the following code. The default port used is 9000. (since at 50700, it is not getting connected)
//webhdfs-read-tests.js
// Include webhdfs module
var WebHDFS = require('webhdfs');
var fs = require('fs');
// Create a new
var hdfs = WebHDFS.createClient({
user: 'ubuntu', // Hadoop user
host: 'localhost', // Namenode host
port: 9000 // Namenode port
});
// Initialize readable stream from HDFS source
var remoteFileStream = hdfs.createReadStream('/sample.txt');
// Variable for storing data
var data = new Buffer.alloc(10);
remoteFileStream.on('error', function onError(err) {
// Do something with the error
console.log(err);
//console.log('')
});
remoteFileStream.on('data', function onChunk(chunk) {
// Concat received data chunk
data = Buffer.concat([data, chunk]);
console.log('data', data);
});
remoteFileStream.on('finish', function onFinish() {
// Upload is done
// Print received data
console.log(data.toString());
});
The cluster looks like:
hadoop fs -ls -R /
2022-12-21 10:52:30,393 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
drwxr-xr-x - ubuntu supergroup 0 2022-12-21 08:28 /files
-rw-r--r-- 1 ubuntu supergroup 169 2022-12-21 08:28 /files/sample.txt
-rw-r--r-- 1 ubuntu supergroup 169 2022-12-21 10:24 /sample.txt
drwxr-xr-x - ubuntu supergroup 0 2022-12-21 08:30 /uploadedFiles
Also, the jps command gives:
jps
47232 ResourceManager
52208 Jps
46768 DataNode
46598 NameNode
47031 SecondaryNameNode
47405 NodeManager
After running the code, I got the following error message:
Error: Invalid request path or webhdfs is not enabled: /webhdfs/v1/sample.txt
at WebHDFS._parseError (/home/ubuntu/node_modules/webhdfs/lib/webhdfs.js:89:16)
at Request.onData (/home/ubuntu/node_modules/webhdfs/lib/webhdfs.js:656:32)
at Request.emit (events.js:198:13)
at IncomingMessage.<anonymous> (/home/ubuntu/node_modules/request/request.js:1073:12)
at IncomingMessage.emit (events.js:198:13)
at IncomingMessage.Readable.read (_stream_readable.js:505:10)
at flow (_stream_readable.js:974:34)
at resume_ (_stream_readable.js:955:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
Can someone help me with this?
The solution is to use the correct port number.
9000 is the port of the namenode.
9870 is the port of webhdfs-> correct port.

firefox.NotConnectedException Unable to connect on port 7055 after 45000

When I tried to run selenium test using Xvfb i am getting this below error
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host localhost.localdomain on port 7055 after 45000 ms. Firefox console output:
Error: cannot open display: 1
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
at com.gtech.automation.uk.webdriver.WebDriverFactory.getWebDriver(WebDriverFactory.java:41)
at com.gtech.automation.uk.dashboard.DashboardImpl.getWebDriver(DashboardImpl.java:53)
at com.gtech.automation.uk.dashboard.DashboardImpl.goHome(DashboardImpl.java:91)
at com.gtech.automation.uk.dashboard.steps.footer.ConnectionInfoSteps.isConnectionClosed(ConnectionInfoSteps.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at cucumber.runtime.Utils$1.call(Utils.java:34)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:30)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:298)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
These are the configuration i have used
Selenium version :2.53.0
Firefox version 46
I have checked the port 7055 its not active
netstat -ntlp | grep 7055
however Xvfb is running on the linux server
netstat -ntlp | grep Xvfb
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 31384/Xvfb
I tried running the Xvfb server with port number its not working
Xvfb :1 -screen 0 1024x768x16 -nolisten inet6 -port 7055 -from localhost.localdomain
Please help on this
Code
public static WebDriver getWebDriver(WebDriverImplementation implementation) {
switch (implementation) {
case FIREFOX:
return new FirefoxDriver(getFirefoxCapabilities());
case FIREBUG: {
FirefoxProfile firefoxProfile = new FirefoxProfile();
String seleniumPath = System.getProperty("selenuim.webdriver.path");
try {
firefoxProfile.addExtension(new File(seleniumPath + "/" + FIREBUG_FILENAME));
}catch (NullPointerException e)
{
logger.log(Level.SEVERE, null, e);
} catch(Exception e) {
System.out.println("Unexcepted Exception");
logger.log(Level.SEVERE, null, e);
}
firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION);
firefoxProfile.setPreference(seleniumPath, seleniumPath);
DesiredCapabilities capabilities = getFirefoxCapabilities();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
return new FirefoxDriver(capabilities);
}
case SHARED_FIREFOX:
return new SharedFireFoxDriver();
case MARIONETTE:
return new MarionetteDriver(getFirefoxCapabilities());
case INTERNET_EXPLORER:
return new InternetExplorerDriver();
default:
String message = "Unable to find a web driver implemention for : " + implementation.name();
logger.log(Level.SEVERE, message);
throw new UnsupportedOperationException(message);
}
}

Wikimedia with Parsoid 0.4.0 doesn't start or doesn't connect properly with nodejs

I have parsoid 0.4.0 from mediawiki, nodejs v0.10.25, when I /etc/init.d/parsoid start, I receive workers restarting having the next messages in the parsoid.log, this message is repeated indefinitely, making my parsoid.log growing indefinitely, another hand I don't recerive any response at http://localhost:8142, 8142 is the port where my parsoid says is serving when I start with "/etc/init.d/parsoid start with the output message:
root#vscj016mlinuxserver:/usr/lib# /etc/init.d/parsoid start
Started Parsoid server on port 8142
root#vscj016mlinuxserver:/usr/lib#
/var/log/parsoid.log output :
[info][master][13876] initializing 4 workers
[info][worker][13879] loading ...
[info][worker][13882] loading ...
[info][worker][13878] loading ...
[info][worker][13881] loading ...
[fatal][worker][13879] uncaught exception Object function createApplication() {
var app = function(req, res, next) {
app.handle(req, res, next);
};
mixin(app, EventEmitter.prototype, false);
mixin(app, proto, false);
app.request = { __proto__: req, app: app };
app.response = { __proto__: res, app: app };
app.init();
return app;
} has no method 'createServer'
TypeError: Object function createApplication() {
var app = function(req, res, next) {
app.handle(req, res, next);
};
mixin(app, EventEmitter.prototype, false);
mixin(app, proto, false);
app.request = { __proto__: req, app: app };
app.response = { __proto__: res, app: app };
app.init();
return app;
} has no method 'createServer'
at new ParsoidService (/usr/lib/parsoid/src/api/ParsoidService.js:23:20)
at Object.<anonymous> (/usr/lib/parsoid/src/api/server.js:202:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
On another hand I can see de processes started with "ps -ef | grep parsoid", de pids of the processes change everytime as you can see with the next output like:
parsoid 920 1 0 09:08 ? 00:00:00 /bin/sh -c /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js >> /var/log/parsoid/parsoid.log 2>&1
parsoid 949 920 0 09:08 ? 00:00:01 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2563 949 18 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2565 949 19 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2567 949 17 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2569 949 5 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
root 2572 2134 0 09:13 pts/0 00:00:00 grep --color=auto parsoid
root#vscj016mlinuxserver:/var/log/parsoid# ps -ef| grep parsoid
parsoid 920 1 0 09:08 ? 00:00:00 /bin/sh -c /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js >> /var/log/parsoid/parsoid.log 2>&1
parsoid 949 920 0 09:08 ? 00:00:01 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2579 949 23 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2581 949 23 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2583 949 0 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2585 949 0 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
root 2588 2134 0 09:13 pts/0 00:00:00 grep --color=auto parsoid
root#vscj016mlinuxserver:/var/log/parsoid# ps -ef| grep parsoid
parsoid 920 1 0 09:08 ? 00:00:00 /bin/sh -c /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js >> /var/log/parsoid/parsoid.log 2>&1
parsoid 949 920 0 09:08 ? 00:00:01 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2581 949 22 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2583 949 30 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2585 949 28 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
parsoid 2589 949 15 09:13 ? 00:00:00 /usr/bin/nodejs /usr/lib/parsoid/src/api/server.js -c /etc/mediawiki/parsoid/settings.js
I show the /etc/mediawiki/parsoid/settings.js aswell:
exports.setup = function(parsoidConfig) {
// Set your own user-agent string
// Otherwise, defaults to "Parsoid/<current-version-defined-in- package.json>"
//parsoidConfig.userAgent = "My-User-Agent-String";
// The URL of your MediaWiki API endpoint.
parsoidConfig.setMwApi('localhost', {uri: 'http://localhost/mediawiki/api.php'} );
// To specify a proxy (or proxy headers) specific to this prefix (which
// overrides defaultAPIProxyURI) use:
/*
parsoidConfig.setMwApi('localhost', {
uri: 'http://localhost/w/api.php',
// set `proxy` to `null` to override and force no proxying.
proxy: {
uri: 'http://my.proxy:1234/',
headers: { 'X-Forwarded-Proto': 'https' } // headers are optional
}
});
*/
......
......
......
Here I show the packets installed and the version of my ubuntu server:
root#vscj016mlinuxserver:/usr/lib# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
root#vscj016mlinuxserver:/usr/lib#
root#vscj016mlinuxserver:/usr/lib#
root#vscj016mlinuxserver:/usr/lib# dpkg -l parsoid
Deseado=Desconocido/Instalar/Eliminar/Purgar/Retener
| Estado=No/Instalado/Config-files/Desempaquetado/Medio-conf/Medio- inst/espera-disparo/pendiente-disparo
|/ Err?=(ninguno)/Requiere-reinst (Estado,Err: mayúsc.=malo)
||/ Nombre Versión Arquitectura Descripción
+++-=================================-=====================- =====================- =======================================================================
ii parsoid 0.4.0 amd64 Web service converting HTML+RDFa to MediaWiki wikitext and back
root#vscj016mlinuxserver:/usr/lib# dpkg -l nodejs
Deseado=Desconocido/Instalar/Eliminar/Purgar/Retener
| Estado=No/Instalado/Config-files/Desempaquetado/Medio-conf/Medio- inst/espera-disparo/pendiente-disparo
|/ Err?=(ninguno)/Requiere-reinst (Estado,Err: mayúsc.=malo)
||/ Nombre Versión Arquitectura Descripción
+++-=================================-=====================- =====================- =======================================================================
ii nodejs 0.10.25~dfsg2-2ubuntu amd64 evented I/O for V8 javascript
root#vscj016mlinuxserver:/usr/lib# dpkg -l nodejs-legacy
Deseado=Desconocido/Instalar/Eliminar/Purgar/Retener
| Estado=No/Instalado/Config-files/Desempaquetado/Medio-conf/Medio- inst/espera-disparo/pendiente-disparo
|/ Err?=(ninguno)/Requiere-reinst (Estado,Err: mayúsc.=malo)
||/ Nombre Versión Arquitectura Descripción
+++-=================================-=====================- =====================- =======================================================================
ii nodejs-legacy 0.10.25~dfsg2-2ubuntu all evented I/O for V8 javascript (legacy symlink)
root#vscj016mlinuxserver:/usr/lib#
You're going to have a much better time with a newer version of Node, for example >=4.3. You can use NVM to run manage different versions of Node: https://github.com/creationix/nvm
this my /etc/mediawiki/parsoid configuration:
exports.setup = function(parsoidConfig) {
// Set your own user-agent string
// Otherwise, defaults to "Parsoid/<current-version-defined-in- package.json>"
//parsoidConfig.userAgent = "My-User-Agent-String";
// The URL of your MediaWiki API endpoint.
parsoidConfig.setMwApi('localhost', { uri: 'http://localhost/mediawiki/api.php' });
// To specify a proxy (or proxy headers) specific to this prefix (which
// overrides defaultAPIProxyURI) use:
/*
parsoidConfig.setMwApi('localhost', {
uri: 'http://localhost/w/api.php',
// set `proxy` to `null` to override and force no proxying.
proxy: {
uri: 'http://my.proxy:1234/',
headers: { 'X-Forwarded-Proto': 'https' } // headers are optional
}
});
*/
This is my parsoid configuration , I don't Know if this is the problema:
exports.setup = function(parsoidConfig) {
// Set your own user-agent string
// Otherwise, defaults to "Parsoid/<current-version-defined-in- package.json>"
//parsoidConfig.userAgent = "My-User-Agent-String";
// The URL of your MediaWiki API endpoint.
parsoidConfig.setMwApi('localhost', { uri: 'http://localhost/mediawiki/api.php' });
// To specify a proxy (or proxy headers) specific to this prefix (which
// overrides defaultAPIProxyURI) use:
/*
parsoidConfig.setMwApi('localhost', {
uri: 'http://localhost/w/api.php',
// set `proxy` to `null` to override and force no proxying.
proxy: {
uri: 'http://my.proxy:1234/',
headers: { 'X-Forwarded-Proto': 'https' } // headers are optional
}
});
*/

Can't connect to MongoDB from NodeJS on Ubuntu. Same code on OSX works fine

I have mongodb installed locally on my osx laptop and on a remote ubuntu server. Both have mongodb running and I can verify this using the http diagnostics on port 28017. I'm running the same code on both computers. On osx everything works fine, but on Ubuntu I can't make a connection to the database through NodeJS. I keep getting this error:
Error: failed to connect to [localhost:27017]]
message: listen EADDRNOTAVAIL
stack: Error: listen EADDRNOTAVAIL
at errnoException (net.js:769:11)
at Server._listen2 (net.js:892:19)
at listen (net.js:936:10)
at Server.listen (net.js:993:9)
at asyncCallback (dns.js:67:16)
at Object.onanswer [as oncomplete] (dns.js:120:9)
What I don't understand is that I can connect on Ubuntu locally via the mongo commandline interface. I can also connect to the database on Ubuntu via the mongo command on my OSX computer. So nothing seems to be wrong with the installation of MongoDB itself.
Can anyone think of a reason why I can't connect via NodeJS? I have tried using the mongodb and mongoose packages. Both give me the same error.
Here are the 2 ways I tried:
var mongo = require("mongodb");
var host = "localhost";
var port = mongo.Connection.DEFAULT_PORT;
var db = new mongo.Db('node-mongo-examples', new mongo.Server(host, port, {}), {});
db.open(function(err, db){
if(err){
log.error('MongoDB connection error:', err);
}else{
log.info("OPEN MONGO CONNECTION");
}
});
And the with mongoose:
var mongoose = require('mongoose');
var db = mongoose.createConnection('localhost', 'node-mongo-examples');
db.on('error', function(err){
log.error('MongoDB connection error:', err);
});
db.once('open', function () {
log.debug("OPEN MONGO CONNECTION");
});
In the logs I see nothing special, and nothing happens either
***** SERVER RESTARTED *****
Wed Sep 26 18:00:18 [initandlisten] MongoDB starting : pid=13377 port=27017 dbpath=/var/lib/mongodb 64-bit host=octo-dev
Wed Sep 26 18:00:18 [initandlisten] db version v2.2.0, pdfile version 4.5
Wed Sep 26 18:00:18 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Wed Sep 26 18:00:18 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed Sep 26 18:00:18 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Wed Sep 26 18:00:18 [initandlisten] journal dir=/var/lib/mongodb/journal
Wed Sep 26 18:00:18 [initandlisten] recover : no journal files present, no recovery needed
Wed Sep 26 18:00:18 [websvr] admin web console waiting for connections on port 28017
Wed Sep 26 18:00:18 [initandlisten] waiting for connections on port 27017
..... except when I connect through the mongo commandline interface:
Wed Sep 26 18:30:40 [initandlisten] connection accepted from 127.0.0.1:38229 #3 (1 connection now open)
I ran out of things to try. Any suggestions for troubleshooting this?
Some extra info
sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 13377/mongod
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 885/mysqld
tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN 1102/java
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 1102/java
tcp 0 0 192.87.219.76:10000 0.0.0.0:* LISTEN 31171/webserver
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1387/java
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1076/apache2
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN 13377/mongod
tcp 0 0 0.0.0.0:48466 0.0.0.0:* LISTEN 12418/java
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3507/sshd
tcp 0 0 127.0.0.1:9016 0.0.0.0:* LISTEN 12418/java
tcp 0 0 0.0.0.0:5080 0.0.0.0:* LISTEN 1102/java
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 1216/master
tcp 0 0 0.0.0.0:41018 0.0.0.0:* LISTEN 12418/java
tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN 1102/java
tcp 0 0 0.0.0.0:9090 0.0.0.0:* LISTEN 12418/java
tcp 0 0 0.0.0.0:29090 0.0.0.0:* LISTEN 12418/java
tcp 0 0 127.0.0.1:8100 0.0.0.0:* LISTEN 8535/soffice.bin
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 1387/java
tcp 0 0 0.0.0.0:389 0.0.0.0:* LISTEN 887/slapd
tcp 0 0 0.0.0.0:33736 0.0.0.0:* LISTEN 1102/java
tcp6 0 0 :::22 :::* LISTEN 3507/sshd
tcp6 0 0 :::389 :::* LISTEN 887/slapd
udp 0 0 192.87.219.76:123 0.0.0.0:* 721/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 721/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 721/ntpd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 797/avahi-daemon: r
udp 0 0 0.0.0.0:55248 0.0.0.0:* 797/avahi-daemon: r
udp6 0 0 :::123 :::* 721/ntpd
udp6 0 0 :::35920 :::* 797/avahi-daemon: r
udp6 0 0 :::5353 :::* 797/avahi-daemon: r
Make sure port 27017 is opened to the web server in Ubuntu.
I found the problem!! The system had a messed up /etc/hosts file. Something with localhost configuration that was unusual. Correcting this file solved everything :D
Try firing the mongo command from your terminal.It will show an error if theres some problem with mongodb.

Dovecot not working pop3 with postfix

telnet localhost pop3
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
netstat -l
tcp 0 0 *:www : LISTEN
tcp 0 0 localhost.localdoma:ipp : LISTEN
tcp 0 0 *:smtp : LISTEN
tcp 0 0 localhost.localdo:mysql : LISTEN
when i run this service dovecot start i got
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.553" (uid=1000 pid=26250 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
on Dovecot.conf
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
log_timestamp = "%Y-%m-%d %H:%M:%S "
mail_location = maildir:/var/spool/mail/%d/%n
mail_access_groups = mail
first_valid_uid = 106
first_valid_gid = 106
protocol imap {
}
protocol pop3 {
listen=*:110
pop3_uidl_format = %08Xu%08Xv
}
protocol lda {
postmaster_address = samer#aiu.com
mail_plugins = quota
log_path = /var/log/dovecot-deliver.log
info_log_path = /var/log/dovecot-deliver.log
}
auth default {
mechanisms = digest-md5 plain
passdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot/dovecot-mysql.conf
}
user = root
}
If you get this message on the command line:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.553" (uid=1000 pid=26250 comm="start) interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
It indicates that you're not doing service dovecot restart as root. So make sure you do:
sudo service dovecot restart
The directive protocols = imap imaps pop3 pop3s should be sufficient to activate pop3 with dovecot. You can add
listen = *
to be sure dovecot will listen on all available interfaces. You can verify this by netstat -apn | grep 110. Are there any failures while starting dovecot? Can you post the dovecot related logs?
By default, dovecot logs to syslog, you can explicitly specify the log files:
# Log file to use for error messages, instead of sending them to syslog.
# /dev/stderr can be used to log into stderr.
log_path = /var/log/dovecot.log
# Log file to use for informational and debug messages.
# Default is the same as log_path.
info_log_path = /var/log/dovecot.info.log

Resources