Connection refused - connect(2) for "localhost" port 25 chef devops - ruby-on-rails

I am working on chef(devops) where I have a helper library with the following code in it
require 'net/smtp'
module HandlerSendEmail
class Helper
def send_email_on_run_failure(node_name)
message = "From: Chef <chef#chef.io>\n"
message << "To: Grant <xyz#test.com>\n"
message << "Subject: Chef run failed\n"
message << "Date: #{Time.now.rfc2822}\n\n"
message << "Chef run failed on #{node_name}\n"
Net::SMTP.start('localhost', 25) do |smtp|
smtp.send_message message, 'chef#chef.io', 'xyz#test.com'
end
end
end
end
But whhen I run the recipe I get
Chef Client failed. 0 resources updated in 02 seconds
[2017-10-30T05:19:38+00:00] ERROR: Connection refused - connect(2) for "localhost" port 25
[2017-10-30T05:19:38+00:00] ERROR: Connection refused - connect(2) for "localhost" port 25
I tried changing port to 90 and some other options I keep getting same error.There are some solution available on few posts on stackoverflow already but all of them are talking about some other .rb files which is not present on my dev environment.
Connection refused - connect(2) Ruby on Rails Mail Setup
Errno::ECONNREFUSED: Connection refused - connect(2) for action mailer

You would need to have an actual SMTP server listening on localhost and I'm guessing you don't have one. Without more information it's hard to say though. If you don't want run your own relay server, you can find instructions all over the internet for setting up outbound SMTP via GMail, Amazon SES, Sparkpost, Sendgrid, and may more.

Related

Connection to localhost:5488 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

I am trying to run this github repo on docker as specified by the instructions
Aidbox with Timescale DB
However when running the conatiners one of them throws this error message
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
WARNING: read already refers to: #'clojure.core/read in namespace: aidbox.sdk.crud, being replaced by: #'aidbox.sdk.crud/read
WARNING: update already refers to: #'clojure.core/update in namespace: aidbox.sdk.crud, being replaced by: #'aidbox.sdk.crud/update
Exception in thread "main" com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Connection to localhost:5488 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:597)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:576)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
at app.db$create_pool.invokeStatic(db.clj:45)
at app.db$create_pool.invoke(db.clj:42)
at app.db$datasource.invokeStatic(db.clj:70)
at app.db$datasource.invoke(db.clj:61)
at app.core$mk_connection.invokeStatic(core.clj:234)
at app.core$mk_connection.invoke(core.clj:231)
at app.core$_main.invokeStatic(core.clj:241)
at app.core$_main.invoke(core.clj:240)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.AFn.applyTo(AFn.java:144)
at app.core.main(Unknown Source)
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5488 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.Driver$ConnectThread.getResult(Driver.java:409)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:98)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:83)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
... 13 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:607)
at org.postgresql.core.PGStream.<init>(PGStream.java:75)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.access$100(Driver.java:57)
at org.postgresql.Driver$ConnectThread.run(Driver.java:368)
at java.lang.Thread.run(Thread.java:748)
I have tried changing the port the database (Which I think it’s what it’s trying to connect to) from port 5432 to 5488 but I get the same error. I have read other stack-overflow posts on this error message but they haven’t worked either.
I have also tried to speak with the company that made this project but as is understandable since this is an open source project of theirs from which they make no money it is not in their priorities to fix this issue.
So hopefully one of the brilliant minds roaming this site can help me out.
If you want more info on what the repo is for
Bringing data from wearables and medical IoT devices to FHIR solutions
I see container_name: timescaledb in docker-compose file. Hence host will be timescaledb and default port 5432 if you are trying to connect from another container in same network

Failed connect to localhost:2633 ; Connection refused

I have installed open-nebula and it's installed successfully.
But when i point to my IP. I can't access.
and when i checked log then it show this.
Mon Feb 5 02:03:32 2018 [Z0][SCHED][E]: Cannot contact oned, will
retry... Error: HTTP POST to URL 'http://localhost:2633/RPC2' failed.
libcurl failed even to execute the HTTP transaction, explaining:
Failed connect to localhost:2633; Connection refused
Help in this ??

How to do functional test for a Grails 3 app with redirection after CAS login?

Problem
I have an app that uses CAS (Central Authentication Service) login. In the configuration (application.yml), CAS is configured as follows:
grails:
plugin:
springsecurity:
# ...other configurations omitted ...
cas:
serverUrlPrefix: "https://<some endpoint for the actual CAS>"
serviceUrl: https://localhost:8443/myapp/login/cas
# ...other configurations omitted ...
When running functional tests, a Tomcat server is initiated with random port number, e.g. http://localhost:45359 and it is always changing with each run.
It seems like the app gets redirected to the CAS serviceUrl after login, and normally my app runs on port 8443, so it's never a problem. But since the functional test brings up the Tomcat server at random port number, the redirection fails.
Also, I'm running my app using run-app -https (i.e. https://localhost:8443), but the test runs on http (e.g. http://localhost:12345). I don't know if this is an important detail or not.
The Test
My functional test goes as follows:
Navigate to the app's main URL, which gets redirected to the login page
Check the title for the login page
Enters the login credentials
Click the Submit button
Errors with "Connection Refused" when it tries to connect to localhost:8443.
Source (based on: https://github.com/grails-guides/grails-test-security/blob/master/complete/src/integration-test/groovy/grails/test/security/AnnouncementControllerSpec.groovy):
#Integration
class MyAppControllerFunctionalSpec extends GebSpec {
def setup(){
}
def cleanup() {
}
void "test something"() {
when:"The home page is visited"
go '/myapp' // 1
then:"The title is correct"
title == "Login Page" // 2
at LoginPage // a helper class - subclass of geb.Page.
// Contains implementation of login method
when: "Sign in"
login('username', 'password') // 3 & 4 --> 5
then: "Title"
title == "Welcome MyApp"
}
Stacktrace:
java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8443 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at com.gargoylesoftware.htmlunit.WebClient.download(WebClient.java:2067)
at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:138)
at com.gargoylesoftware.htmlunit.html.HtmlButton.doClickStateUpdate(HtmlButton.java:97)
at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:786)
at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:733)
at org.openqa.selenium.htmlunit.HtmlUnitMouse.click(HtmlUnitMouse.java:74)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.click(HtmlUnitWebElement.java:151)
at geb.navigator.NonEmptyNavigator.click(NonEmptyNavigator.groovy:437)
at geb.content.TemplateDerivedPageContent.click(TemplateDerivedPageContent.groovy:115)
at myapp.LoginPage.login(LoginPage.groovy:22)
at geb.Browser.methodMissing(Browser.groovy:207)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
at myapp.MyAppControllerFunctionalSpec.test something(MyAppControllerFunctionalSpec.groovy:39)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8443 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:179)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1321)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1379)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1238)
at com.gargoylesoftware.htmlunit.WebClient.download(WebClient.java:2063)
... 12 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:337)
at com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory.connectSocket(HtmlUnitSSLConnectionSocketFactory.java:189)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141)
... 25 more
Question
What is the correct way to make it so my functional tests can get past the CAS login?
Other Info
Grails: 3.2.7
Groovy: 2.4.12
IntelliJ: 2017.1.5
UPDATE
I have tried setting port numbers using an environment variable, to no avail. See: this Grails isssue
My current solution to get the functional test to run with CAS login from Intellij IDEA:
Make sure the test class is under the src/integration-test/groovy/<package>/ directory
Run/launch the app using the Run commands or control buttons. Don't run the app from the IDE's Terminal.
Run the test from the IDE's Terminal:
grails test-app package.test_class --integration
For example, with package: foo and test class MyAppControllerFunctionalSpec:
grails test-app foo.MyAppControllerFunctionalSpec --integration

Failed to open TCP connection

While attempting to open a TCP connection to graph.facebook.com, I receive the following error:
Failed to open TCP connection to graph.facebook.com:443 (getaddrinfo:
Name or service not known)
TCPSocket.open(conn_address, conn_port, #local_host, #local_port)
rescue => e
raise e, "Failed to open TCP connection to " +
"#{conn_address}:#{conn_port} (#{e.message})"
end
}
Help me with this error
I'm using omniauth with Rails 5.0.0.beta3
Start by checking your network configuration.
Run this command on your terminal:
dig +short graph.facebook.com
If you do not get any IP address, your system don't know how to resolve this and the problem is not related to Ruby.
In addition to that as mentioned by Dawood Awan in his comment, opening a TCP connection to the port 443 is usually not a good idea, I am pretty sure facebook is excepting an HTTPS Connection.

Ruby: Connection refused - connect(2) for nil port 80

I am trying to check if the content type of the resource on my server at s3 has a valid image/jpeg content type. I used the code fromhere but I keep getting the:
Errno::ECONNREFUSED:
Connection refused - connect(2) for nil port 80
The link to my s3 image is as:
https://s3-us-west-2.amazonaws.com/cu-prototype-content/course-content/user-profile-images/BillSKenney-128.jpg
Is there something I need to change in my code?

Resources